diff --git a/lib/6to5/transformation/templates/property-method-assignment-wrapper.js b/lib/6to5/transformation/templates/property-method-assignment-wrapper.js new file mode 100644 index 0000000000..ebb3da0acf --- /dev/null +++ b/lib/6to5/transformation/templates/property-method-assignment-wrapper.js @@ -0,0 +1,11 @@ +(function (FUNCTION_KEY) { + var WRAPPER_KEY = function FUNCTION_ID() { + return FUNCTION_KEY.apply(this, arguments); + }; + + WRAPPER_KEY.toString = function () { + return FUNCTION_KEY.toString(); + }; + + return WRAPPER_KEY; +})(FUNCTION) diff --git a/lib/6to5/transformation/transform.js b/lib/6to5/transformation/transform.js index 03a9128292..562c33f4b9 100644 --- a/lib/6to5/transformation/transform.js +++ b/lib/6to5/transformation/transform.js @@ -66,7 +66,7 @@ _.each({ exponentiationOperator: require("./transformers/es7-exponentiation-operator"), spread: require("./transformers/es6-spread"), templateLiterals: require("./transformers/es6-template-literals"), - propertyMethodAssignment: require("./transformers/es5-property-method-assignment"), + propertyMethodAssignment: require("./transformers/es6-property-method-assignment"), destructuring: require("./transformers/es6-destructuring"), defaultParameters: require("./transformers/es6-default-parameters"), forOf: require("./transformers/es6-for-of"), @@ -88,6 +88,7 @@ _.each({ _moduleFormatter: require("./transformers/_module-formatter"), useStrict: require("./transformers/use-strict"), + protoToAssign: require("./transformers/optional-proto-to-assign"), coreAliasing: require("./transformers/optional-core-aliasing"), undefinedToVoid: require("./transformers/optional-undefined-to-void"), diff --git a/lib/6to5/transformation/transformers/es5-property-method-assignment.js b/lib/6to5/transformation/transformers/es5-property-method-assignment.js deleted file mode 100644 index 1bbb88640a..0000000000 --- a/lib/6to5/transformation/transformers/es5-property-method-assignment.js +++ /dev/null @@ -1,41 +0,0 @@ -var util = require("../../util"); -var t = require("../../types"); - -exports.Property = function (node) { - if (node.method) node.method = false; -}; - -exports.ObjectExpression = function (node, parent, file) { - var mutatorMap = {}; - var hasAny = false; - - node.properties = node.properties.filter(function (prop) { - if (prop.kind === "get" || prop.kind === "set") { - hasAny = true; - util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.value); - return false; - } else { - return true; - } - }); - - if (!hasAny) return; - - if (node.properties.length) { - var objId = t.getUid(parent, file); - - return util.template("object-define-properties-closure", { - KEY: objId, - OBJECT: node, - CONTENT: util.template("object-define-properties", { - OBJECT: objId, - PROPS: util.buildDefineProperties(mutatorMap) - }) - }); - } else { - return util.template("object-define-properties", { - OBJECT: node, - PROPS: util.buildDefineProperties(mutatorMap) - }); - } -}; diff --git a/test/fixtures/transformation/es5-property-methods-assignment/getter-and-setter/actual.js b/test/fixtures/transformation/es6-property-methods-assignment/getter-and-setter/actual.js similarity index 58% rename from test/fixtures/transformation/es5-property-methods-assignment/getter-and-setter/actual.js rename to test/fixtures/transformation/es6-property-methods-assignment/getter-and-setter/actual.js index 11ed1f3e1d..5760e76545 100644 --- a/test/fixtures/transformation/es5-property-methods-assignment/getter-and-setter/actual.js +++ b/test/fixtures/transformation/es6-property-methods-assignment/getter-and-setter/actual.js @@ -1,8 +1,8 @@ var obj = { get foo() { - return 5 + 5; + return 5 + 5; }, set foo(value) { - this._foo = value; + this._foo = value; } }; diff --git a/test/fixtures/transformation/es5-property-methods-assignment/getter-and-setter/expected.js b/test/fixtures/transformation/es6-property-methods-assignment/getter-and-setter/expected.js similarity index 100% rename from test/fixtures/transformation/es5-property-methods-assignment/getter-and-setter/expected.js rename to test/fixtures/transformation/es6-property-methods-assignment/getter-and-setter/expected.js diff --git a/test/fixtures/transformation/es5-property-methods-assignment/getter/actual.js b/test/fixtures/transformation/es6-property-methods-assignment/getter/actual.js similarity index 100% rename from test/fixtures/transformation/es5-property-methods-assignment/getter/actual.js rename to test/fixtures/transformation/es6-property-methods-assignment/getter/actual.js diff --git a/test/fixtures/transformation/es5-property-methods-assignment/getter/expected.js b/test/fixtures/transformation/es6-property-methods-assignment/getter/expected.js similarity index 100% rename from test/fixtures/transformation/es5-property-methods-assignment/getter/expected.js rename to test/fixtures/transformation/es6-property-methods-assignment/getter/expected.js diff --git a/test/fixtures/transformation/es6-property-methods-assignment/method-self-reference/actual.js b/test/fixtures/transformation/es6-property-methods-assignment/method-self-reference/actual.js new file mode 100644 index 0000000000..dfa4898e55 --- /dev/null +++ b/test/fixtures/transformation/es6-property-methods-assignment/method-self-reference/actual.js @@ -0,0 +1,19 @@ +var bar = { + foo() { + console.log(foo); + } +}; + +var bar = { + foo() { + var foo = 41; + console.log(foo); + } +}; + +var foobar = 123; +var foobar2 = { + foobar() { + return foobar; + } +}; diff --git a/test/fixtures/transformation/es6-property-methods-assignment/method-self-reference/expected.js b/test/fixtures/transformation/es6-property-methods-assignment/method-self-reference/expected.js new file mode 100644 index 0000000000..41e330b3f7 --- /dev/null +++ b/test/fixtures/transformation/es6-property-methods-assignment/method-self-reference/expected.js @@ -0,0 +1,42 @@ +"use strict"; + +var bar = { + foo: (function (_foo) { + var _fooWrapper = function foo() { + return _foo.apply(this, arguments); + }; + + _fooWrapper.toString = function () { + return _foo.toString(); + }; + + return _fooWrapper; + })(function () { + console.log(foo); + }) +}; + +var bar = { + foo: function foo() { + var foo = 41; + console.log(foo); + } +}; + +var foobar = 123; +var foobar2 = { + foobar: (function (_foobar) { + var _foobarWrapper = function foobar() { + return _foobar.apply(this, arguments); + }; + + _foobarWrapper.toString = function () { + return _foobar.toString(); + }; + + return _foobarWrapper; + })(function () { + console.log(foobar); + }) +}; + diff --git a/test/fixtures/transformation/es5-property-methods-assignment/method/actual.js b/test/fixtures/transformation/es6-property-methods-assignment/method/actual.js similarity index 64% rename from test/fixtures/transformation/es5-property-methods-assignment/method/actual.js rename to test/fixtures/transformation/es6-property-methods-assignment/method/actual.js index cbc9cb2f75..9114ccf44c 100644 --- a/test/fixtures/transformation/es5-property-methods-assignment/method/actual.js +++ b/test/fixtures/transformation/es6-property-methods-assignment/method/actual.js @@ -1,5 +1,5 @@ var obj = { method() { - return 5 + 5; + return 5 + 5; } }; diff --git a/test/fixtures/transformation/es5-property-methods-assignment/method/expected.js b/test/fixtures/transformation/es6-property-methods-assignment/method/expected.js similarity index 63% rename from test/fixtures/transformation/es5-property-methods-assignment/method/expected.js rename to test/fixtures/transformation/es6-property-methods-assignment/method/expected.js index 7c847fa38b..5d05971896 100644 --- a/test/fixtures/transformation/es5-property-methods-assignment/method/expected.js +++ b/test/fixtures/transformation/es6-property-methods-assignment/method/expected.js @@ -1,7 +1,7 @@ "use strict"; var obj = { - method: function () { + method: function method() { return 5 + 5; } }; diff --git a/test/fixtures/transformation/es5-property-methods-assignment/setter/actual.js b/test/fixtures/transformation/es6-property-methods-assignment/setter/actual.js similarity index 100% rename from test/fixtures/transformation/es5-property-methods-assignment/setter/actual.js rename to test/fixtures/transformation/es6-property-methods-assignment/setter/actual.js diff --git a/test/fixtures/transformation/es5-property-methods-assignment/setter/expected.js b/test/fixtures/transformation/es6-property-methods-assignment/setter/expected.js similarity index 100% rename from test/fixtures/transformation/es5-property-methods-assignment/setter/expected.js rename to test/fixtures/transformation/es6-property-methods-assignment/setter/expected.js