From 1ab3b183a8ffcf00c10f20a7b55d693f2d2551d4 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 13 Feb 2010 02:29:37 -0500 Subject: [PATCH] Using underscore for an any() function. --- lib/coffee_script/nodes.js | 20 +++----------------- src/nodes.coffee | 8 ++------ 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/lib/coffee_script/nodes.js b/lib/coffee_script/nodes.js index 86413f41..2dec5b4c 100644 --- a/lib/coffee_script/nodes.js +++ b/lib/coffee_script/nodes.js @@ -1,7 +1,8 @@ (function(){ - var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, Node, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ThrowNode, TryNode, ValueNode, WhileNode, any, compact, del, dup, flatten, inherit, merge, statement; + var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, Node, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ThrowNode, TryNode, ValueNode, WhileNode, _, compact, del, dup, flatten, inherit, merge, statement; var __hasProp = Object.prototype.hasOwnProperty; process.mixin(require('./scope')); + _ = require('./underscore')._; // Some helper functions // Tabs are two spaces for pretty printing. TAB = ' '; @@ -77,21 +78,6 @@ } return fresh; }; - // Do any of the elements in the list pass a truth test? - any = function any(list, test) { - var __a, __b, __c, item, result; - result = (function() { - __a = []; __b = list; - for (__c = 0; __c < __b.length; __c++) { - item = __b[__c]; - if (test(item)) { - __a.push(true); - } - } - return __a; - }).call(this); - return !!result.length; - }; // Delete a key from an object, returning the value. del = function del(obj, key) { var val; @@ -457,7 +443,7 @@ // Compile a vanilla function call. compile_node: function compile_node(o) { var __a, __b, __c, arg, args; - if (any(this.args, function(a) { + if (_.any(this.args, function(a) { return a instanceof SplatNode; })) { return this.compile_splat(o); diff --git a/src/nodes.coffee b/src/nodes.coffee index 9cf85c38..d4631f9b 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1,4 +1,5 @@ process.mixin require './scope' +_: require('./underscore')._ # Some helper functions @@ -38,11 +39,6 @@ merge: (src, dest) -> (fresh[key]: val) for key, val of dest fresh -# Do any of the elements in the list pass a truth test? -any: (list, test) -> - result: true for item in list when test(item) - !!result.length - # Delete a key from an object, returning the value. del: (obj, key) -> val: obj[key] @@ -337,7 +333,7 @@ CallNode: exports.CallNode: inherit Node, { # Compile a vanilla function call. compile_node: (o) -> - return @compile_splat(o) if any @args, (a) -> a instanceof SplatNode + return @compile_splat(o) if _.any @args, (a) -> a instanceof SplatNode args: (arg.compile(o) for arg in @args).join(', ') return @compile_super(args, o) if @variable is 'super' @prefix + @variable.compile(o) + '(' + args + ')'