Merge pull request #3113 from phantom10111/fix-static-class-properties
Fix static class properties - fixes T2983
This commit is contained in:
commit
4f69482896
@ -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);
|
||||
|
||||
7
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T2983/actual.js
vendored
Normal file
7
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T2983/actual.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
call(class {
|
||||
static test = true
|
||||
});
|
||||
|
||||
export default class {
|
||||
static test = true
|
||||
};
|
||||
18
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T2983/expected.js
vendored
Normal file
18
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T2983/expected.js
vendored
Normal 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;
|
||||
;
|
||||
|
||||
3
packages/babel-plugin-transform-class-properties/test/fixtures/regression/options.json
vendored
Normal file
3
packages/babel-plugin-transform-class-properties/test/fixtures/regression/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers-2", "transform-class-properties", "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
|
||||
}
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user