From 831b420df3ddd27056f4a47022a17107293fc033 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 13 Jan 2015 01:09:10 +1100 Subject: [PATCH] special case single super method call with spread, fixes #227 --- .../transformers/es6-classes.js | 16 ++++++++++---- .../accessing-super-class/expected.js | 22 +++++++++---------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/6to5/transformation/transformers/es6-classes.js b/lib/6to5/transformation/transformers/es6-classes.js index 15f8b7addc..8fcf90c7ba 100644 --- a/lib/6to5/transformation/transformers/es6-classes.js +++ b/lib/6to5/transformation/transformers/es6-classes.js @@ -289,10 +289,18 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) { var superProperty = self.superProperty(property, methodNode.static, computed, thisReference); if (args) { - return t.callExpression( - t.memberExpression(superProperty, t.identifier("call"), false), - [thisReference].concat(args) - ); + if (args.length === 1 && t.isSpreadElement(args[0])) { + // super(...arguments); + return t.callExpression( + t.memberExpression(superProperty, t.identifier("apply"), false), + [thisReference, args[0].argument] + ); + } else { + return t.callExpression( + t.memberExpression(superProperty, t.identifier("call"), false), + [thisReference].concat(args) + ); + } } else { return superProperty; } diff --git a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js index d467b433f5..a762c97203 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js @@ -45,16 +45,16 @@ var _inherits = function (subClass, superClass) { var Test = (function (Foo) { function Test() { - var _get2, _get3, _get4, _get5; + var _get2, _get3; woops["super"].test(); _get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this); _get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); - (_get2 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get2, [this].concat(_slice.call(arguments))); - (_get3 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get3, [this, "test"].concat(_slice.call(arguments))); + _get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments); + (_get2 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get2, [this, "test"].concat(_slice.call(arguments))); - (_get4 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get4, [this].concat(_slice.call(arguments))); - (_get5 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get5, [this, "test"].concat(_slice.call(arguments))); + _get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); + (_get3 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get3, [this, "test"].concat(_slice.call(arguments))); } _inherits(Test, Foo); @@ -62,10 +62,10 @@ var Test = (function (Foo) { _prototypeProperties(Test, { foo: { value: function () { - var _get6, _get7; + var _get4; _get(Object.getPrototypeOf(Test), "foo", this).call(this); - (_get6 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get6, [this].concat(_slice.call(arguments))); - (_get7 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get7, [this, "test"].concat(_slice.call(arguments))); + _get(Object.getPrototypeOf(Test), "foo", this).apply(this, arguments); + (_get4 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get4, [this, "test"].concat(_slice.call(arguments))); }, writable: true, enumerable: true, @@ -74,10 +74,10 @@ var Test = (function (Foo) { }, { test: { value: function () { - var _get8, _get9; + var _get5; _get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); - (_get8 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get8, [this].concat(_slice.call(arguments))); - (_get9 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get9, [this, "test"].concat(_slice.call(arguments))); + _get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); + (_get5 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get5, [this, "test"].concat(_slice.call(arguments))); }, writable: true, enumerable: true,