diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 92258afae3..6c4b1586e5 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -73,6 +73,8 @@ File.normaliseOptions = function (opts) { File.prototype.toArray = function (node) { if (t.isArrayExpression(node)) { return node; + } else if (t.isIdentifier(node) && node.name === "arguments") { + return t.callExpression(t.memberExpression(this.addDeclaration("slice"), t.identifier("call")), [node]); } else { return t.callExpression(this.addDeclaration("to-array"), [node]); } diff --git a/test/fixtures/transformation/classes/accessing-super-class/expected.js b/test/fixtures/transformation/classes/accessing-super-class/expected.js index 37a2a13d6f..d49fffb74e 100644 --- a/test/fixtures/transformation/classes/accessing-super-class/expected.js +++ b/test/fixtures/transformation/classes/accessing-super-class/expected.js @@ -1,9 +1,6 @@ "use strict"; -var _toArray = function (arr) { - return Array.isArray(arr) ? arr : Array.from(arr); -}; - +var _slice = Array.prototype.slice; var _classProps = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); @@ -28,11 +25,11 @@ var Test = (function (Foo) { Foo.prototype.test.call(this); foob(Foo); - Foo.call.apply(Foo, [this].concat(_toArray(arguments))); - Foo.call.apply(Foo, [this, "test"].concat(_toArray(arguments))); + Foo.call.apply(Foo, [this].concat(_slice.call(arguments))); + Foo.call.apply(Foo, [this, "test"].concat(_slice.call(arguments))); - Foo.prototype.test.call.apply(Foo.prototype, [this].concat(_toArray(arguments))); - Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_toArray(arguments))); + Foo.prototype.test.call.apply(Foo.prototype, [this].concat(_slice.call(arguments))); + Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_slice.call(arguments))); }; _extends(Test, Foo); @@ -42,8 +39,8 @@ var Test = (function (Foo) { writable: true, value: function () { Foo.foo.call(this); - Foo.foo.call.apply(Foo.foo, [this].concat(_toArray(arguments))); - Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_toArray(arguments))); + Foo.foo.call.apply(Foo.foo, [this].concat(_slice.call(arguments))); + Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_slice.call(arguments))); } } }, { @@ -51,8 +48,8 @@ var Test = (function (Foo) { writable: true, value: function () { Foo.prototype.test.call(this); - Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_toArray(arguments))); - Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_toArray(arguments))); + Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_slice.call(arguments))); + Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_slice.call(arguments))); } } }); diff --git a/test/fixtures/transformation/spread/arguments/expected.js b/test/fixtures/transformation/spread/arguments/expected.js index ac2f6ab06d..1ba8c3aeb2 100644 --- a/test/fixtures/transformation/spread/arguments/expected.js +++ b/test/fixtures/transformation/spread/arguments/expected.js @@ -1,11 +1,8 @@ "use strict"; -var _toArray = function (arr) { - return Array.isArray(arr) ? arr : Array.from(arr); -}; - +var _slice = Array.prototype.slice; function foo() { - return bar.apply(null, ["test"].concat(_toArray(arguments))); + return bar.apply(null, ["test"].concat(_slice.call(arguments))); } function bar(one, two, three) {