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