Computed class properties (#4500)
* Support computed class property names (#4499) ** Depends on babel/babylon#121 ** * `babel-types`: Add `computed` field to `ClassProperty` * `babel-plugin-transform-class-properties`: handle computed property names correctly * `babel-generator`: add tests for class properties (computed/literal, static/instance) * doc: Update babel-types with ClassProperty.computed * chore(package): update babylon to v6.11.0 * babel-types: move ClassProperty.computed to be last builder arg
This commit is contained in:
committed by
Daniel Tschinder
parent
a81a0d0f84
commit
03d772c2ec
@@ -58,14 +58,15 @@ export default function ({ types: t }) {
|
||||
if (!propNode.value) continue;
|
||||
|
||||
let isStatic = propNode.static;
|
||||
let isComputed = propNode.computed || t.isLiteral(prop.key);
|
||||
|
||||
if (isStatic) {
|
||||
nodes.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(ref, propNode.key), propNode.value)
|
||||
t.assignmentExpression("=", t.memberExpression(ref, propNode.key, isComputed), propNode.value)
|
||||
));
|
||||
} else {
|
||||
instanceBody.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(t.thisExpression(), propNode.key), propNode.value)
|
||||
t.assignmentExpression("=", t.memberExpression(t.thisExpression(), propNode.key, isComputed), propNode.value)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user