add descriptor for all class properties - fixes #1235

This commit is contained in:
Sebastian McKenzie
2015-04-12 08:53:01 -07:00
parent 652d3c7320
commit 26b5174dfa
7 changed files with 48 additions and 19 deletions

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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;
})();
})();

View File

@@ -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);

View File

@@ -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;
})();

View File

@@ -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);

View File

@@ -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);