diff --git a/src/babel/transformation/templates/helper-create-decorated-class.js b/src/babel/transformation/templates/helper-create-decorated-class.js index db321a5ef8..61c31b6867 100644 --- a/src/babel/transformation/templates/helper-create-decorated-class.js +++ b/src/babel/transformation/templates/helper-create-decorated-class.js @@ -24,7 +24,7 @@ } } - if (descriptor.initializer) { + if (descriptor.initializer !== undefined) { initializers[key] = descriptor; continue; } diff --git a/src/babel/transformation/templates/helper-create-decorated-object.js b/src/babel/transformation/templates/helper-create-decorated-object.js index f9350882fa..15b6d1e68f 100644 --- a/src/babel/transformation/templates/helper-create-decorated-object.js +++ b/src/babel/transformation/templates/helper-create-decorated-object.js @@ -26,9 +26,10 @@ } } - descriptor.value = descriptor.initializer.call(target); - - Object.defineProperty(target, key, descriptor); + if (descriptor.initializer) { + descriptor.value = descriptor.initializer.call(target); + Object.defineProperty(target, key, descriptor); + } } return target; diff --git a/src/babel/transformation/templates/helper-define-decorated-property-descriptor.js b/src/babel/transformation/templates/helper-define-decorated-property-descriptor.js index e4bc5c14f7..dbc2f05562 100644 --- a/src/babel/transformation/templates/helper-define-decorated-property-descriptor.js +++ b/src/babel/transformation/templates/helper-define-decorated-property-descriptor.js @@ -6,6 +6,7 @@ for (var _key in _descriptor) descriptor[_key] = _descriptor[_key]; // initialize it + if (!descriptor.initializer) return; descriptor.value = descriptor.initializer.call(target); Object.defineProperty(target, key, descriptor); diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index 332b0767b3..27fee12443 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -550,8 +550,12 @@ class ClassTransformer { if (node.decorators) { var body = []; - if (node.value) body.push(t.returnStatement(node.value)); - node.value = t.functionExpression(null, [], t.blockStatement(body)); + if (node.value) { + body.push(t.returnStatement(node.value)); + node.value = t.functionExpression(null, [], t.blockStatement(body)); + } else { + node.value = t.literal(null); + } this.pushToMap(node, true, "initializer"); var initializers; @@ -575,7 +579,7 @@ class ClassTransformer { ]) )); } else { - node.value = node.value || t.identifier("undefined"); + if (!node.value && !node.decorators) return; if (node.static) { // can just be added to the static map 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 index cc057f33bb..c99d5881af 100644 --- a/test/core/fixtures/transformation/es7.class-properties/instance-undefined/expected.js +++ b/test/core/fixtures/transformation/es7.class-properties/instance-undefined/expected.js @@ -2,5 +2,4 @@ var Foo = function Foo() { babelHelpers.classCallCheck(this, Foo); - this.bar = undefined; -}; \ No newline at end of file +}; 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 index 0771105a61..ed37421154 100644 --- a/test/core/fixtures/transformation/es7.class-properties/static-undefined/exec.js +++ b/test/core/fixtures/transformation/es7.class-properties/static-undefined/exec.js @@ -2,5 +2,5 @@ class Foo { static num; } -assert.equal("num" in Foo, true); +assert.equal("num" in Foo, false); 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 index f5c17bfa15..c99d5881af 100644 --- a/test/core/fixtures/transformation/es7.class-properties/static-undefined/expected.js +++ b/test/core/fixtures/transformation/es7.class-properties/static-undefined/expected.js @@ -1,14 +1,5 @@ "use strict"; -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } - - babelHelpers.createClass(Foo, null, [{ - key: "bar", - value: undefined, - enumerable: true - }]); - return Foo; -})(); +var Foo = function Foo() { + babelHelpers.classCallCheck(this, Foo); +}; diff --git a/test/core/fixtures/transformation/es7.decorators/class-no-init-instance-props/expected.js b/test/core/fixtures/transformation/es7.decorators/class-no-init-instance-props/expected.js index b0975298af..1a02daa7e6 100644 --- a/test/core/fixtures/transformation/es7.decorators/class-no-init-instance-props/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/class-no-init-instance-props/expected.js @@ -11,8 +11,8 @@ var Foo = (function () { babelHelpers.createDecoratedClass(Foo, [{ key: "foo", decorators: [bar], - initializer: function () {}, + initializer: null, enumerable: true }], null, _instanceInitializers); return Foo; -})(); \ No newline at end of file +})(); diff --git a/test/core/fixtures/transformation/es7.decorators/class-no-init-static-props/expected.js b/test/core/fixtures/transformation/es7.decorators/class-no-init-static-props/expected.js index 89d557f801..50e829f93d 100644 --- a/test/core/fixtures/transformation/es7.decorators/class-no-init-static-props/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/class-no-init-static-props/expected.js @@ -10,7 +10,7 @@ var Foo = (function () { babelHelpers.createDecoratedClass(Foo, null, [{ key: "foo", decorators: [bar], - initializer: function () {}, + initializer: null, enumerable: true }], null, _staticInitializers); babelHelpers.defineDecoratedPropertyDescriptor(Foo, "foo", _staticInitializers);