Merge pull request #3113 from phantom10111/fix-static-class-properties

Fix static class properties - fixes T2983
This commit is contained in:
Henry Zhu 2015-12-01 22:21:37 -05:00
commit 4f69482896
5 changed files with 42 additions and 9 deletions

View File

@ -41,9 +41,9 @@ export default function ({ types: t }) {
let nodes = [];
let ref;
if (path.isClassExpression()) {
ref = path.scope.generateUidIdentifier();
} else { // path.isClassDeclaration()
if (path.isClassExpression() || !path.node.id) {
ref = path.scope.generateUidIdentifier("class");
} else { // path.isClassDeclaration() && path.node.id
ref = path.node.id;
}
@ -131,11 +131,16 @@ export default function ({ types: t }) {
if (!nodes.length) return;
if (path.isClassExpression()) {
nodes.push(t.expressionStatement(ref));
}
path.scope.push({ id: ref });
path.replaceWith(t.assignmentExpression("=", ref, path.node));
} else { // path.isClassDeclaration()
if (!path.node.id) {
path.node.id = ref;
}
if (path.isClassDeclaration() && path.parentPath.isExportDeclaration()) {
path = path.parentPath;
if (path.parentPath.isExportDeclaration()) {
path = path.parentPath;
}
}
path.insertAfter(nodes);

View File

@ -0,0 +1,7 @@
call(class {
static test = true
});
export default class {
static test = true
};

View File

@ -0,0 +1,18 @@
var _class, _temp;
call((_temp = _class = (function () {
function _class2() {
babelHelpers.classCallCheck(this, _class2);
}
return _class2;
})(), _class.test = true, _temp));
var _class3 = function _class3() {
babelHelpers.classCallCheck(this, _class3);
};
_class3.test = true;
export default _class3;
;

View File

@ -0,0 +1,3 @@
{
"plugins": ["external-helpers-2", "transform-class-properties", "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
}

View File

@ -224,7 +224,7 @@ export default class Scope {
* Generate a unique identifier.
*/
generateUidIdentifier(name: string) {
generateUidIdentifier(name: string = "temp") {
return t.identifier(this.generateUid(name));
}
@ -232,7 +232,7 @@ export default class Scope {
* Generate a unique `_id1` binding.
*/
generateUid(name: string) {
generateUid(name: string = "temp") {
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
let uid;