From c452c3a101595a0a2d9c705005b1c0bbdc70b62c Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 8 May 2010 12:15:47 -0400 Subject: [PATCH] minor cleanup to varargs --- lib/nodes.js | 12 +++++------- src/nodes.coffee | 8 +++----- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index cff8792c..2f2d0807 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1153,15 +1153,13 @@ // Compiling a parameter splat means recovering the parameters that succeed // the splat in the parameter list, by slicing the arguments object. SplatNode.prototype.compile_param = function compile_param(o) { - var _b, _c, _d, i, name, trailing; + var _b, _c, name, pos, trailing; name = this.name.compile(o); o.scope.find(name); - i = 0; - _c = this.trailings; - for (_b = 0, _d = _c.length; _b < _d; _b++) { - trailing = _c[_b]; - o.scope.assign(trailing.compile(o), ("arguments[arguments.length - " + this.trailings.length + " + " + i + "]")); - i += 1; + _b = this.trailings; + for (pos = 0, _c = _b.length; pos < _c; pos++) { + trailing = _b[pos]; + o.scope.assign(trailing.compile(o), ("arguments[arguments.length - " + (this.trailings.length + pos) + "]")); } return "" + name + " = " + (utility('slice')) + ".call(arguments, " + this.index + ", arguments.length - " + (this.trailings.length) + ")"; }; diff --git a/src/nodes.coffee b/src/nodes.coffee index ec7089b8..82b1c1a5 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -298,7 +298,7 @@ exports.ValueNode: class ValueNode extends BaseNode # Values are considered to be statements if their base is a statement. is_statement: -> @base.is_statement and @base.is_statement() and not @has_properties() - + # Works out if the value is the start of a chain. is_start: (o) -> return true if this is o.chain_root and @properties[0] instanceof AccessorNode @@ -828,10 +828,8 @@ exports.SplatNode: class SplatNode extends BaseNode compile_param: (o) -> name: @name.compile(o) o.scope.find name - i: 0 - for trailing in @trailings - o.scope.assign(trailing.compile(o), "arguments[arguments.length - $@trailings.length + $i]") - i: + 1 + for trailing, pos in @trailings + o.scope.assign(trailing.compile(o), "arguments[arguments.length - ${@trailings.length + pos}]") "$name = ${utility('slice')}.call(arguments, $@index, arguments.length - ${@trailings.length})" # A compiling a splat as a destructuring assignment means slicing arguments