fix no RHS in class properties causing undefined to be used instead of a noop - fixes #1396
This commit is contained in:
parent
571cb4928f
commit
d26e7ad577
@ -24,7 +24,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor.initializer) {
|
if (descriptor.initializer !== undefined) {
|
||||||
initializers[key] = descriptor;
|
initializers[key] = descriptor;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,9 +26,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor.value = descriptor.initializer.call(target);
|
if (descriptor.initializer) {
|
||||||
|
descriptor.value = descriptor.initializer.call(target);
|
||||||
Object.defineProperty(target, key, descriptor);
|
Object.defineProperty(target, key, descriptor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return target;
|
return target;
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
|
for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
|
||||||
|
|
||||||
// initialize it
|
// initialize it
|
||||||
|
if (!descriptor.initializer) return;
|
||||||
descriptor.value = descriptor.initializer.call(target);
|
descriptor.value = descriptor.initializer.call(target);
|
||||||
|
|
||||||
Object.defineProperty(target, key, descriptor);
|
Object.defineProperty(target, key, descriptor);
|
||||||
|
|||||||
@ -550,8 +550,12 @@ class ClassTransformer {
|
|||||||
|
|
||||||
if (node.decorators) {
|
if (node.decorators) {
|
||||||
var body = [];
|
var body = [];
|
||||||
if (node.value) body.push(t.returnStatement(node.value));
|
if (node.value) {
|
||||||
node.value = t.functionExpression(null, [], t.blockStatement(body));
|
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");
|
this.pushToMap(node, true, "initializer");
|
||||||
|
|
||||||
var initializers;
|
var initializers;
|
||||||
@ -575,7 +579,7 @@ class ClassTransformer {
|
|||||||
])
|
])
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
node.value = node.value || t.identifier("undefined");
|
if (!node.value && !node.decorators) return;
|
||||||
|
|
||||||
if (node.static) {
|
if (node.static) {
|
||||||
// can just be added to the static map
|
// can just be added to the static map
|
||||||
|
|||||||
@ -2,5 +2,4 @@
|
|||||||
|
|
||||||
var Foo = function Foo() {
|
var Foo = function Foo() {
|
||||||
babelHelpers.classCallCheck(this, Foo);
|
babelHelpers.classCallCheck(this, Foo);
|
||||||
this.bar = undefined;
|
};
|
||||||
};
|
|
||||||
|
|||||||
@ -2,5 +2,5 @@ class Foo {
|
|||||||
static num;
|
static num;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.equal("num" in Foo, true);
|
assert.equal("num" in Foo, false);
|
||||||
assert.equal(Foo.num, undefined);
|
assert.equal(Foo.num, undefined);
|
||||||
|
|||||||
@ -1,14 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Foo = (function () {
|
var Foo = function Foo() {
|
||||||
function Foo() {
|
babelHelpers.classCallCheck(this, Foo);
|
||||||
babelHelpers.classCallCheck(this, Foo);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
babelHelpers.createClass(Foo, null, [{
|
|
||||||
key: "bar",
|
|
||||||
value: undefined,
|
|
||||||
enumerable: true
|
|
||||||
}]);
|
|
||||||
return Foo;
|
|
||||||
})();
|
|
||||||
|
|||||||
@ -11,8 +11,8 @@ var Foo = (function () {
|
|||||||
babelHelpers.createDecoratedClass(Foo, [{
|
babelHelpers.createDecoratedClass(Foo, [{
|
||||||
key: "foo",
|
key: "foo",
|
||||||
decorators: [bar],
|
decorators: [bar],
|
||||||
initializer: function () {},
|
initializer: null,
|
||||||
enumerable: true
|
enumerable: true
|
||||||
}], null, _instanceInitializers);
|
}], null, _instanceInitializers);
|
||||||
return Foo;
|
return Foo;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -10,7 +10,7 @@ var Foo = (function () {
|
|||||||
babelHelpers.createDecoratedClass(Foo, null, [{
|
babelHelpers.createDecoratedClass(Foo, null, [{
|
||||||
key: "foo",
|
key: "foo",
|
||||||
decorators: [bar],
|
decorators: [bar],
|
||||||
initializer: function () {},
|
initializer: null,
|
||||||
enumerable: true
|
enumerable: true
|
||||||
}], null, _staticInitializers);
|
}], null, _staticInitializers);
|
||||||
babelHelpers.defineDecoratedPropertyDescriptor(Foo, "foo", _staticInitializers);
|
babelHelpers.defineDecoratedPropertyDescriptor(Foo, "foo", _staticInitializers);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user