Skip to content
New issue

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

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

Already on GitHub? # 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.

@weswigham weswigham force-pushed the exportstar-skip-locals branch from ece0b05 to 44bbf14 Compare February 28, 2020 00:46
@weswigham weswigham requested a review from rbuckton February 28, 2020 00:49
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

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

Successfully merging this pull request may close these issues.

5 participants