diff --git a/src/babel/transformation/helpers/define-map.js b/src/babel/transformation/helpers/define-map.js index de02f1275a..d6acd8e93e 100644 --- a/src/babel/transformation/helpers/define-map.js +++ b/src/babel/transformation/helpers/define-map.js @@ -33,12 +33,14 @@ export function push(mutatorMap, node, kind, file) { throw file.errorWithNode(node, "Key conflict with sibling node"); } - if (node.kind === "init") kind = "value"; - if (node.kind === "get") kind = "get"; - if (node.kind === "set") kind = "set"; + if (node.value) { + if (node.kind === "init") kind = "value"; + if (node.kind === "get") kind = "get"; + if (node.kind === "set") kind = "set"; - t.inheritsComments(node.value, node); - map[kind] = node.value; + t.inheritsComments(node.value, node); + map[kind] = node.value; + } return map; } diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index 47cb9777d2..d0c1c9aef4 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -517,8 +517,6 @@ class ClassTransformer { */ pushProperty(node: { type: "ClassProperty" }) { - if (!node.value && !node.decorators) return; - var key; this.scope.traverse(node, collectPropertyReferencesVisitor, { @@ -545,16 +543,17 @@ class ClassTransformer { }, true)); } } else { - if (node.static) { - // can just be added to the static map - this.pushToMap(node, true); - } else { + if (!node.static && node.value) { // add this to the instancePropBody which will be added after the super call in a derived constructor // or at the start of a constructor for a non-derived constructor this.instancePropBody.push(t.expressionStatement( t.assignmentExpression("=", t.memberExpression(t.thisExpression(), node.key), node.value) )); + node.value = t.identifier("undefined"); } + + // can just be added to the static map + this.pushToMap(node, true); } } diff --git a/test/core/fixtures/transformation/es7.class-properties/constructor-collision/expected.js b/test/core/fixtures/transformation/es7.class-properties/constructor-collision/expected.js index 7717ef7e3d..8122a0d904 100644 --- a/test/core/fixtures/transformation/es7.class-properties/constructor-collision/expected.js +++ b/test/core/fixtures/transformation/es7.class-properties/constructor-collision/expected.js @@ -12,10 +12,14 @@ var Foo = (function () { } babelHelpers.createClass(Foo, [{ + key: "bar", + value: undefined, + enumerable: true + }, { key: "__initializeProperties", value: function __initializeProperties() { this.bar = foo; } }]); return Foo; -})(); +})(); \ No newline at end of file diff --git a/test/core/fixtures/transformation/es7.class-properties/derived/expected.js b/test/core/fixtures/transformation/es7.class-properties/derived/expected.js index 1e6b388886..3f8f712ec7 100644 --- a/test/core/fixtures/transformation/es7.class-properties/derived/expected.js +++ b/test/core/fixtures/transformation/es7.class-properties/derived/expected.js @@ -12,5 +12,10 @@ var Foo = (function (_Bar) { } babelHelpers.inherits(Foo, _Bar); + babelHelpers.createClass(Foo, [{ + key: "bar", + value: undefined, + enumerable: true + }]); return Foo; -})(Bar); +})(Bar); \ No newline at end of file diff --git a/test/core/fixtures/transformation/es7.class-properties/instance/expected.js b/test/core/fixtures/transformation/es7.class-properties/instance/expected.js index 8f200f662d..69e1324fea 100644 --- a/test/core/fixtures/transformation/es7.class-properties/instance/expected.js +++ b/test/core/fixtures/transformation/es7.class-properties/instance/expected.js @@ -1,6 +1,15 @@ "use strict"; -var Foo = function Foo() { - babelHelpers.classCallCheck(this, Foo); - this.bar = "foo"; -}; +var Foo = (function () { + function Foo() { + babelHelpers.classCallCheck(this, Foo); + this.bar = "foo"; + } + + babelHelpers.createClass(Foo, [{ + key: "bar", + value: undefined, + enumerable: true + }]); + return Foo; +})(); \ No newline at end of file diff --git a/test/core/fixtures/transformation/es7.class-properties/super-expression/expected.js b/test/core/fixtures/transformation/es7.class-properties/super-expression/expected.js index 53454b3c98..fe3a1cdc34 100644 --- a/test/core/fixtures/transformation/es7.class-properties/super-expression/expected.js +++ b/test/core/fixtures/transformation/es7.class-properties/super-expression/expected.js @@ -10,5 +10,10 @@ var Foo = (function (_Bar) { } babelHelpers.inherits(Foo, _Bar); + babelHelpers.createClass(Foo, [{ + key: "bar", + value: undefined, + enumerable: true + }]); return Foo; -})(Bar); +})(Bar); \ No newline at end of file diff --git a/test/core/fixtures/transformation/es7.class-properties/super-statement/expected.js b/test/core/fixtures/transformation/es7.class-properties/super-statement/expected.js index 6b92483d80..6d64624dcd 100644 --- a/test/core/fixtures/transformation/es7.class-properties/super-statement/expected.js +++ b/test/core/fixtures/transformation/es7.class-properties/super-statement/expected.js @@ -9,5 +9,10 @@ var Foo = (function (_Bar) { } babelHelpers.inherits(Foo, _Bar); + babelHelpers.createClass(Foo, [{ + key: "bar", + value: undefined, + enumerable: true + }]); return Foo; -})(Bar); +})(Bar); \ No newline at end of file