diff --git a/lib/lexer.js b/lib/lexer.js index 2f7d664e..23ac8d40 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -222,8 +222,7 @@ }; Lexer.prototype.balancedToken = function() { var delimited; - var _d = arguments.length, _e = _d >= 1; - delimited = __slice.call(arguments, 0, _d - 0); + delimited = __slice.call(arguments, 0); return this.balancedString(this.chunk, delimited); }; Lexer.prototype.lineToken = function() { diff --git a/lib/nodes.js b/lib/nodes.js index bd0516af..203f7793 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1031,20 +1031,24 @@ return (typeof (_b = this.index) !== "undefined" && _b !== null) ? this.compileParam(o) : this.name.compile(o); }; SplatNode.prototype.compileParam = function(o) { - var _b, _c, idx, len, name, pos, trailing, variadic; + var _b, _c, end, idx, len, name, pos, trailing, variadic; name = this.name.compile(o); o.scope.find(name); - len = o.scope.freeVariable(); - o.scope.assign(len, "arguments.length"); - variadic = o.scope.freeVariable(); - o.scope.assign(variadic, ("" + len + " >= " + this.arglength)); - _b = this.trailings; - for (idx = 0, _c = _b.length; idx < _c; idx++) { - trailing = _b[idx]; - pos = this.trailings.length - idx; - o.scope.assign(trailing.compile(o), ("arguments[" + variadic + " ? " + len + " - " + pos + " : " + (this.index + idx) + "]")); + end = ''; + if (this.trailings.length) { + len = o.scope.freeVariable(); + o.scope.assign(len, "arguments.length"); + variadic = o.scope.freeVariable(); + o.scope.assign(variadic, ("" + len + " >= " + this.arglength)); + end = this.trailings.length ? (", " + len + " - " + (this.trailings.length)) : null; + _b = this.trailings; + for (idx = 0, _c = _b.length; idx < _c; idx++) { + trailing = _b[idx]; + pos = this.trailings.length - idx; + o.scope.assign(trailing.compile(o), ("arguments[" + variadic + " ? " + len + " - " + pos + " : " + (this.index + idx) + "]")); + } } - return "" + name + " = " + (utility('slice')) + ".call(arguments, " + this.index + ", " + len + " - " + (this.trailings.length) + ")"; + return "" + name + " = " + (utility('slice')) + ".call(arguments, " + this.index + end + ")"; }; SplatNode.prototype.compileValue = function(o, name, index, trailings) { var trail; diff --git a/src/nodes.coffee b/src/nodes.coffee index 74cc25a0..1fbc808c 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -922,14 +922,17 @@ exports.SplatNode: class SplatNode extends BaseNode compileParam: (o) -> name: @name.compile(o) o.scope.find name - len: o.scope.freeVariable() - o.scope.assign len, "arguments.length" - variadic: o.scope.freeVariable() - o.scope.assign variadic, "$len >= $@arglength" - for trailing, idx in @trailings - pos: @trailings.length - idx - o.scope.assign(trailing.compile(o), "arguments[$variadic ? $len - $pos : ${@index + idx}]") - "$name = ${utility('slice')}.call(arguments, $@index, $len - ${@trailings.length})" + end: '' + if @trailings.length + len: o.scope.freeVariable() + o.scope.assign len, "arguments.length" + variadic: o.scope.freeVariable() + o.scope.assign variadic, "$len >= $@arglength" + end: if @trailings.length then ", $len - ${@trailings.length}" + for trailing, idx in @trailings + pos: @trailings.length - idx + o.scope.assign(trailing.compile(o), "arguments[$variadic ? $len - $pos : ${@index + idx}]") + "$name = ${utility('slice')}.call(arguments, $@index$end)" # A compiling a splat as a destructuring assignment means slicing arguments # from the right-hand-side's corresponding array.