diff --git a/lib/lexer.js b/lib/lexer.js index 6f8f7a16..5a0e8bcd 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -240,7 +240,8 @@ // balanced (ie. strings, JS literals). Lexer.prototype.balanced_token = function balanced_token() { var delimited; - delimited = __slice.call(arguments, 0, arguments.length - 0); + var _d = arguments.length; + delimited = __slice.call(arguments, 0, _d - 0); return balanced_string(this.chunk, delimited); }; // Matches and conumes comments. We pass through comments into JavaScript, diff --git a/lib/nodes.js b/lib/nodes.js index 2f2d0807..d7542098 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1153,15 +1153,17 @@ // 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, name, pos, trailing; + var _b, _c, len, name, pos, trailing; name = this.name.compile(o); o.scope.find(name); + len = o.scope.free_variable(); + o.scope.assign(len, "arguments.length"); _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) + "]")); + o.scope.assign(trailing.compile(o), ("arguments[" + len + " - " + (this.trailings.length + pos) + "]")); } - return "" + name + " = " + (utility('slice')) + ".call(arguments, " + this.index + ", arguments.length - " + (this.trailings.length) + ")"; + return "" + name + " = " + (utility('slice')) + ".call(arguments, " + this.index + ", " + len + " - " + (this.trailings.length) + ")"; }; // A compiling a splat as a destructuring assignment means slicing arguments // from the right-hand-side's corresponding array. diff --git a/src/nodes.coffee b/src/nodes.coffee index 82b1c1a5..26552cd2 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -828,9 +828,11 @@ exports.SplatNode: class SplatNode extends BaseNode compile_param: (o) -> name: @name.compile(o) o.scope.find name + len: o.scope.free_variable() + o.scope.assign len, "arguments.length" 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})" + o.scope.assign(trailing.compile(o), "arguments[$len - ${@trailings.length + pos}]") + "$name = ${utility('slice')}.call(arguments, $@index, $len - ${@trailings.length})" # A compiling a splat as a destructuring assignment means slicing arguments # from the right-hand-side's corresponding array.