add basic support for class property initializers - #619
This commit is contained in:
@@ -167,6 +167,8 @@ ClassTransformer.prototype.buildBody = function () {
|
||||
} else if (t.isPrivateDeclaration(node)) {
|
||||
this.closure = true;
|
||||
body.unshift(node);
|
||||
} else if (t.isClassProperty(node)) {
|
||||
this.pushProperty(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,6 +247,28 @@ ClassTransformer.prototype.pushMethod = function (node) {
|
||||
defineMap.push(mutatorMap, methodName, "enumerable", node.computed, false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} node
|
||||
*/
|
||||
|
||||
ClassTransformer.prototype.pushProperty = function (node) {
|
||||
if (!node.value) return;
|
||||
|
||||
if (node.static) {
|
||||
var key = t.memberExpression(this.className, node.key);
|
||||
this.body.push(
|
||||
t.expressionStatement(t.assignmentExpression("=", key, node.value))
|
||||
);
|
||||
} else {
|
||||
var key = t.memberExpression(t.thisExpression(), node.key);
|
||||
this.constructor.body.body.unshift(
|
||||
t.expressionStatement(t.assignmentExpression("=", key, node.value))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Replace the constructor body of our class.
|
||||
*
|
||||
|
||||
@@ -99,6 +99,7 @@
|
||||
"key": null,
|
||||
"value": null,
|
||||
"computed": false,
|
||||
"static": false,
|
||||
"kind": null
|
||||
},
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
"AnyTypeAnnotation": [],
|
||||
"ArrayTypeAnnotation": [],
|
||||
"BooleanTypeAnnotation": [],
|
||||
"ClassProperty": ["key"],
|
||||
"ClassProperty": ["key", "value"],
|
||||
"DeclareClass": [],
|
||||
"DeclareFunction": [],
|
||||
"DeclareModule": [],
|
||||
|
||||
Reference in New Issue
Block a user