diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index 4af1e12c32..649adcf86d 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -552,6 +552,11 @@ class ClassTransformer { this.instancePropBody.push(t.expressionStatement( t.assignmentExpression("=", t.memberExpression(t.thisExpression(), node.key), node.value) )); + + node.value = null; + } + + if (!node.value) { node.value = t.identifier("undefined"); } diff --git a/test/core/fixtures/transformation/es7.class-properties/instance-undefined/actual.js b/test/core/fixtures/transformation/es7.class-properties/instance-undefined/actual.js new file mode 100644 index 0000000000..a36cdd975c --- /dev/null +++ b/test/core/fixtures/transformation/es7.class-properties/instance-undefined/actual.js @@ -0,0 +1,3 @@ +class Foo { + bar; +} diff --git a/test/core/fixtures/transformation/es7.class-properties/instance-undefined/expected.js b/test/core/fixtures/transformation/es7.class-properties/instance-undefined/expected.js new file mode 100644 index 0000000000..4fed431790 --- /dev/null +++ b/test/core/fixtures/transformation/es7.class-properties/instance-undefined/expected.js @@ -0,0 +1,14 @@ +"use strict"; + +var Foo = (function () { + function Foo() { + babelHelpers.classCallCheck(this, 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/static-undefined/actual.js b/test/core/fixtures/transformation/es7.class-properties/static-undefined/actual.js new file mode 100644 index 0000000000..4ee31b9c35 --- /dev/null +++ b/test/core/fixtures/transformation/es7.class-properties/static-undefined/actual.js @@ -0,0 +1,3 @@ +class Foo { + static bar; +} diff --git a/test/core/fixtures/transformation/es7.class-properties/static-undefined/exec.js b/test/core/fixtures/transformation/es7.class-properties/static-undefined/exec.js new file mode 100644 index 0000000000..0771105a61 --- /dev/null +++ b/test/core/fixtures/transformation/es7.class-properties/static-undefined/exec.js @@ -0,0 +1,6 @@ +class Foo { + static num; +} + +assert.equal("num" in Foo, true); +assert.equal(Foo.num, undefined); diff --git a/test/core/fixtures/transformation/es7.class-properties/static-undefined/expected.js b/test/core/fixtures/transformation/es7.class-properties/static-undefined/expected.js new file mode 100644 index 0000000000..f5c17bfa15 --- /dev/null +++ b/test/core/fixtures/transformation/es7.class-properties/static-undefined/expected.js @@ -0,0 +1,14 @@ +"use strict"; + +var Foo = (function () { + function Foo() { + babelHelpers.classCallCheck(this, Foo); + } + + babelHelpers.createClass(Foo, null, [{ + key: "bar", + value: undefined, + enumerable: true + }]); + return Foo; +})();