Merge pull request #240 from thejameskyle/arguments-spread

Only slice arguments when necessary - fixes #239
This commit is contained in:
Sebastian McKenzie 2014-12-03 12:28:14 +11:00
commit 2eab56c38b
7 changed files with 50 additions and 4 deletions

View File

@ -64,7 +64,12 @@ exports.CallExpression = function (node, parent, file) {
node.arguments = [];
var nodes = build(args, file);
var nodes;
if (args.length === 1 && args[0].argument.name === 'arguments') {
nodes = [args[0].argument];
} else {
nodes = build(args, file);
}
var first = nodes.shift();
if (nodes.length) {

View File

@ -0,0 +1,9 @@
function foo() {
return bar([...arguments]);
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@ -0,0 +1,12 @@
"use strict";
var _slice = Array.prototype.slice;
function foo() {
return bar([].concat(_slice.call(arguments)));
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@ -0,0 +1,9 @@
function foo() {
return bar("test", ...arguments);
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@ -0,0 +1,12 @@
"use strict";
var _slice = Array.prototype.slice;
function foo() {
return bar.apply(null, ["test"].concat(_slice.call(arguments)));
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@ -1,5 +1,5 @@
function foo() {
return bar("test", ...arguments);
return bar(...arguments);
}
function bar(one, two, three) {

View File

@ -1,8 +1,7 @@
"use strict";
var _slice = Array.prototype.slice;
function foo() {
return bar.apply(null, ["test"].concat(_slice.call(arguments)));
return bar.apply(null, arguments);
}
function bar(one, two, three) {