transform-es2015-classes: check if node.id is null

This commit is contained in:
Henry Zhu
2015-11-05 10:09:23 -05:00
parent 232439460f
commit f1a62ef078
3 changed files with 17 additions and 2 deletions

View File

@@ -0,0 +1 @@
export default class extends A {}

View File

@@ -0,0 +1,12 @@
var _class = (function (_A) {
babelHelpers.inherits(_class, _A);
function _class() {
babelHelpers.classCallCheck(this, _class);
return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(_class).apply(this, arguments));
}
return _class;
})(A);
export default _class;

View File

@@ -8,13 +8,15 @@ export default function ({ types: t }) {
ClassDeclaration(path) {
let { node } = path;
let ref = node.id || path.scope.generateUidIdentifier("class");
if (path.parentPath.isExportDefaultDeclaration()) {
path = path.parentPath;
path.insertAfter(t.exportDefaultDeclaration(node.id));
path.insertAfter(t.exportDefaultDeclaration(ref));
}
path.replaceWith(t.variableDeclaration("let", [
t.variableDeclarator(node.id, t.toExpression(node))
t.variableDeclarator(ref, t.toExpression(node))
]));
},