infer class name for classes that have static properties (#3589)

This commit is contained in:
Keyan Zhang
2016-07-22 06:50:03 -07:00
committed by Henry Zhu
parent a289dfbbab
commit 879f69f0fb
5 changed files with 18 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
"babel-plugin"
],
"dependencies": {
"babel-helper-function-name": "^6.8.0",
"babel-plugin-syntax-class-properties": "^6.8.0",
"babel-runtime": "^6.9.1"
},

View File

@@ -1,5 +1,6 @@
/* eslint max-len: 0 */
// todo: define instead of assign
import nameFunction from "babel-helper-function-name";
export default function ({ types: t }) {
let findBareSupers = {
@@ -43,6 +44,7 @@ export default function ({ types: t }) {
let ref;
if (path.isClassExpression() || !path.node.id) {
nameFunction(path);
ref = path.scope.generateUidIdentifier("class");
} else { // path.isClassDeclaration() && path.node.id
ref = path.node.id;

View File

@@ -0,0 +1,3 @@
var Foo = class {
static num = 0;
}

View File

@@ -0,0 +1,7 @@
var Foo = class {
static num = 0;
}
assert.equal(Foo.num, 0);
assert.equal(Foo.num = 1, 1);
assert.equal(Foo.name, "Foo");

View File

@@ -0,0 +1,5 @@
var _class, _temp;
var Foo = (_temp = _class = function Foo() {
babelHelpers.classCallCheck(this, Foo);
}, _class.num = 0, _temp);