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

@@ -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))
]));
},