From 73074daa0710b0a2dcac510718287fba170796bc Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 15 Mar 2010 20:46:14 -0700 Subject: [PATCH] removing arguments-to-array-conversion from coffee --- lib/nodes.js | 11 +---------- lib/optparse.js | 1 - src/nodes.coffee | 5 ----- test/test_arguments.coffee | 14 ++++++++------ 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index 970d00a6..03ca3824 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -228,14 +228,8 @@ // Compile the expressions body for the contents of a function, with // declarations of all inner variables pushed up to the top. Expressions.prototype.compile_with_declarations = function compile_with_declarations(o) { - var args, code; + var code; code = this.compile_node(o); - args = this.contains(function(node) { - return node instanceof ValueNode && node.is_arguments(); - }); - if (args) { - code = '' + (this.tab) + "arguments = Array.prototype.slice.call(arguments, 0);\n" + code; - } if (o.scope.has_assignments(this)) { code = '' + (this.tab) + "var " + (o.scope.compiled_assignments()) + ";\n" + code; } @@ -355,9 +349,6 @@ ValueNode.prototype.is_splice = function is_splice() { return this.has_properties() && this.properties[this.properties.length - 1] instanceof SliceNode; }; - ValueNode.prototype.is_arguments = function is_arguments() { - return this.base.value === 'arguments'; - }; // The value can be unwrapped as its inner node, if there are no attached // properties. ValueNode.prototype.unwrap = function unwrap() { diff --git a/lib/optparse.js b/lib/optparse.js index 4aa5107f..a88ad049 100755 --- a/lib/optparse.js +++ b/lib/optparse.js @@ -20,7 +20,6 @@ // flag. Instead, you're responsible for interpreting the options object. OptionParser.prototype.parse = function parse(args) { var _a, _b, _c, arg, is_option, matched_rule, options, rule; - arguments = Array.prototype.slice.call(arguments, 0); options = { arguments: [] }; diff --git a/src/nodes.coffee b/src/nodes.coffee index 32f91efc..5f411556 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -167,8 +167,6 @@ exports.Expressions: class Expressions extends BaseNode # declarations of all inner variables pushed up to the top. compile_with_declarations: (o) -> code: @compile_node(o) - args: @contains (node) -> node instanceof ValueNode and node.is_arguments() - code: "${@tab}arguments = Array.prototype.slice.call(arguments, 0);\n$code" if args code: "${@tab}var ${o.scope.compiled_assignments()};\n$code" if o.scope.has_assignments(this) code: "${@tab}var ${o.scope.compiled_declarations()};\n$code" if o.scope.has_declarations(this) code @@ -266,9 +264,6 @@ exports.ValueNode: class ValueNode extends BaseNode is_splice: -> @has_properties() and @properties[@properties.length - 1] instanceof SliceNode - is_arguments: -> - @base.value is 'arguments' - # The value can be unwrapped as its inner node, if there are no attached # properties. unwrap: -> diff --git a/test/test_arguments.coffee b/test/test_arguments.coffee index 7915a980..42d4d98f 100644 --- a/test/test_arguments.coffee +++ b/test/test_arguments.coffee @@ -17,12 +17,6 @@ ok(area( ) is 100, 'newline delimited arguments') -curried: -> - ok area.apply(this, arguments.concat(20, 20)) is 100, 'arguments converted into an array' - -curried 10, 10 - - func: -> arguments: 25 arguments @@ -32,3 +26,11 @@ ok func(100) is 25, 'arguments as a regular identifier' this.arguments: 10 ok @arguments is 10, 'arguments accessed as a property' + + +sum_of_args: -> + sum: 0 + sum += val for val in arguments + sum + +ok sum_of_args(1, 2, 3, 4, 5) is 15 \ No newline at end of file