Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

henryqdineen
Copy link

@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

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.

None yet

2 participants