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

Hoist initial assignment to exported names in cjs to they are not blocked by bindings made by __exportStar #37093

Merged
merged 4 commits into from
Feb 28, 2020

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Feb 27, 2020

We need this because now that __createBinding is used by __exportStar to create live-updating getters, if you had input like

export * from "mod";
export const nameFromMod = 0;

we'd output

__exportStar(exports, require("mod"));
exports.nameFromMod = 0;

the assignment will throw because the __exportStar made a getter which can't be overridden with a simple assignment. By emitting

exports.nameFromMod = void 0;
__exportStar(exports, require("mod"));
exports.nameFromMod = 0;

we prevent __exportStar from overwriting nameFromMod with a getter (so the assignment succeeds).

This also neatly ensures all export names are available to reexport when resolving within a circular module graph.

Copy link
Member

@rbuckton rbuckton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need to discuss in design meeting.

@fightingcat
Copy link

Missed the case of exported namespace (export * as foo from 'foo').

@RobertLowe
Copy link

Curious, this violates no-void https://eslint.org/docs/2.0.0/rules/no-void

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

Successfully merging this pull request may close these issues.

5 participants