Fix T6953,T2541 export-from statement renamed default issue

- Use `interopRequireDefault` helper if local name is default.

Via 59naga/babel-plugin-add-module-exports#20
This commit is contained in:
59naga
2016-01-20 02:54:54 +09:00
parent f1ef0ff5e9
commit c509847588
3 changed files with 12 additions and 1 deletions

View File

@@ -295,7 +295,11 @@ export default function () {
} else if (specifier.isExportDefaultSpecifier()) {
// todo
} else if (specifier.isExportSpecifier()) {
topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), t.memberExpression(ref, specifier.node.local)));
if (specifier.node.local.name === "default") {
topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), t.memberExpression(t.callExpression(this.addHelper("interopRequireDefault"), [ref]), specifier.node.local)));
} else {
topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), t.memberExpression(ref, specifier.node.local)));
}
nonHoistedExportNames[specifier.node.exported.name] = true;
}
}