Skip to content

support multiple assignment of export.default in Babel 7#82

Open
henryqdineen wants to merge 1 commit into59naga:masterfrom
henryqdineen:export-as-default
Open

support multiple assignment of export.default in Babel 7#82
henryqdineen wants to merge 1 commit into59naga:masterfrom
henryqdineen:export-as-default

Conversation

@henryqdineen
Copy link
Copy Markdown

@henryqdineen henryqdineen commented Oct 18, 2019

We ran into an odd issue when migrating from Babel 6 to 7 that I tracked down to this plugin. It is specific to Babel 7 and using the same variable multiple times in a ExportNamedDeclaration. I understand that this is plugin is deprecated and don't expect new version but I thought I would leave this here for posterity.

Consider this code here:

const foo = 'bar';
export { foo, foo as default };`

In Babel 6 it would be transpiled as:

Object.defineProperty(exports, "__esModule", {
  value: true
});
var foo = 'bar';
exports.foo = foo;
exports.default = foo;

In Babel 7 it would be transpiled as:

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.foo = void 0;
var foo = 'bar';
exports.default = exports.foo = foo;

The issue I found is that babel-plugin-add-module-exports will incorrectly add the module.exports because the isOnlyExportsDefault() does not correctly handle the case of exports.default = exports.foo = foo;. It only looks at root level expression statements and does not expect this multiple assignment.

My quick fix was to recursively call findExports on the right hand side of the assignment so it can analyze the other exports.

@henryqdineen henryqdineen changed the title support multiple assingnment of 'export.default` in Babel 7 support multiple assignment of export.default in Babel 7 Oct 18, 2019
@aminya
Copy link
Copy Markdown

aminya commented Jul 24, 2020

@59naga Could you take a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants