From 1c2bafe0e1fa2333c3a3a17030952f7a27b61574 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 13 Jan 2015 23:18:38 +1100 Subject: [PATCH] use assignment instead of define for fast classes --- .../transformers/es6-classes.js | 13 ++++++ .../accessing-super-class/expected.js | 40 +++++++------------ .../calling-super-properties/expected.js | 15 +++---- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/lib/6to5/transformation/transformers/es6-classes.js b/lib/6to5/transformation/transformers/es6-classes.js index d736dfcd5d..2e7fb8b06f 100644 --- a/lib/6to5/transformation/transformers/es6-classes.js +++ b/lib/6to5/transformation/transformers/es6-classes.js @@ -188,6 +188,19 @@ Class.prototype.pushMethod = function (node) { } if (kind === "") { + if (this.isFast) { + // use assignments instead of define properties for fast classes + + var className = this.className; + if (!node.static) className = t.memberExpression(className, t.identifier("prototype")); + methodName = t.memberExpression(className, methodName, node.computed); + + var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value)); + t.inheritsComments(expr, node); + this.body.push(expr); + return; + } + kind = "value"; } diff --git a/test/fixtures/transformation/es6-classes-fast/accessing-super-class/expected.js b/test/fixtures/transformation/es6-classes-fast/accessing-super-class/expected.js index a0dce8e571..6c9bd8d668 100644 --- a/test/fixtures/transformation/es6-classes-fast/accessing-super-class/expected.js +++ b/test/fixtures/transformation/es6-classes-fast/accessing-super-class/expected.js @@ -37,31 +37,21 @@ var Test = (function (Foo) { _inherits(Test, Foo); - _prototypeProperties(Test, { - foo: { - value: function () { - var _Foo$foo, _Foo$foo2; - Foo.foo.call(this); - (_Foo$foo = Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments))); - (_Foo$foo2 = Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments))); - }, - writable: true, - enumerable: true, - configurable: true - } - }, { - test: { - value: function () { - var _Foo$prototype$test3, _Foo$prototype$test4; - Foo.prototype.test.call(this); - (_Foo$prototype$test3 = Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(_slice.call(arguments))); - (_Foo$prototype$test4 = Foo.prototype.test).call.apply(_Foo$prototype$test4, [this, "test"].concat(_slice.call(arguments))); - }, - writable: true, - enumerable: true, - configurable: true - } - }); + Test.prototype.test = function () { + var _Foo$prototype$test3, _Foo$prototype$test4; + Foo.prototype.test.call(this); + (_Foo$prototype$test3 = Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(_slice.call(arguments))); + (_Foo$prototype$test4 = Foo.prototype.test).call.apply(_Foo$prototype$test4, [this, "test"].concat(_slice.call(arguments))); + }; + + Test.foo = function () { + var _Foo$foo, _Foo$foo2; + Foo.foo.call(this); + (_Foo$foo = Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments))); + (_Foo$foo2 = Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments))); + }; + + _prototypeProperties(Test, {}, {}); return Test; })(Foo); diff --git a/test/fixtures/transformation/es6-classes-fast/calling-super-properties/expected.js b/test/fixtures/transformation/es6-classes-fast/calling-super-properties/expected.js index 7891b464e4..529795221c 100644 --- a/test/fixtures/transformation/es6-classes-fast/calling-super-properties/expected.js +++ b/test/fixtures/transformation/es6-classes-fast/calling-super-properties/expected.js @@ -28,16 +28,11 @@ var Test = (function (Foo) { _inherits(Test, Foo); - _prototypeProperties(Test, { - test: { - value: function () { - return Foo.wow.call(this); - }, - writable: true, - enumerable: true, - configurable: true - } - }); + Test.test = function () { + return Foo.wow.call(this); + }; + + _prototypeProperties(Test, {}); return Test; })(Foo);