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;
}
}

View File

@@ -4,3 +4,4 @@ export {foo, bar} from "foo";
export {foo as bar} from "foo";
export {foo as default} from "foo";
export {foo as default, bar} from "foo";
export {default as foo} from "foo";

View File

@@ -57,4 +57,10 @@ Object.defineProperty(exports, "bar", {
get: function () {
return _foo.bar;
}
});
Object.defineProperty(exports, "foo", {
enumerable: true,
get: function () {
return babelHelpers.interopRequireDefault(_foo).default;
}
});