make export { foo as default }; trigger common interop

This commit is contained in:
Sebastian McKenzie 2015-02-07 19:29:59 +11:00
parent 7f985fe08a
commit 07c7b5b419
3 changed files with 13 additions and 2 deletions

View File

@ -27,7 +27,7 @@ function DefaultFormatter(file) {
}
DefaultFormatter.prototype.doDefaultExportInterop = function (node) {
return node.default && !this.noInteropRequireExport && !this.hasNonDefaultExports;
return t.isSpecifierDefault(node) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
};
DefaultFormatter.prototype.bumpImportOccurences = function (node) {

View File

@ -64,6 +64,17 @@ CommonJSFormatter.prototype.importDeclaration = function (node, nodes) {
}, true));
};
CommonJSFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
if (this.doDefaultExportInterop(node)) {
nodes.push(util.template("exports-default-assign", {
VALUE: t.getSpecifierId(specifier)
}, true));
return;
}
DefaultFormatter.prototype.exportSpecifier.apply(this, arguments);
};
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
if (this.doDefaultExportInterop(node)) {
var declar = node.declaration;

View File

@ -760,7 +760,7 @@ t.getSpecifierId = function (specifier) {
*/
t.isSpecifierDefault = function (specifier) {
return specifier.default || t.isIdentifier(specifier.id) && specifier.id.name === "default";
return specifier.default || t.isIdentifier(specifier.id, { name: "default" });
};
toFastProperties(t);