Skip to content

Update __exportStar helper to skip default and __esModule members - #37236

Merged
Wesley Wigham (weswigham) merged 4 commits into
microsoft:masterfrom
weswigham:skip-default-in-exportStar
Apr 13, 2020
Merged

Wesley Wigham (weswigham) merged 4 commits into
microsoft:masterfrom
weswigham:skip-default-in-exportStar

Conversation

@weswigham

Copy link
Copy Markdown
Member

Fixes #37234

text: `
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && p !== "__esModule" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Won't __esModule always be skipped because we emit it unconditionally anyways?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm, fair, yeah.

@bluelovers

Copy link
Copy Markdown
Contributor

i think this not a good way for avoid bug

u will see bug happen again when run e1.ts

e1.ts

export * from './e2'

export function abc()
{

}

e2.ts

export function abc()
{

}

@weswigham

Copy link
Copy Markdown
Member Author

bluelovers (@bluelovers) We hoist an undefined member assignment so that actually works just fine (as the hoisted assignment blocks us from overwriting it with the exportStar helper). It's only default that's a little different, since we don't track default as an exported name. That may actually be a better fix - hoisting an exports.default = void 0 assignment would be a bit more inline with other exports, at least.

@weswigham

Copy link
Copy Markdown
Member Author

Ron Buckton (@rbuckton) you think we should hoist an assignment to default, rather than change the helper?

@bluelovers

bluelovers (bluelovers) commented Mar 5, 2020 •

Copy link
Copy Markdown
Contributor

every named export after export * if that name exists in import target

will Cannot set property xxx of #<Object> which has only a getter

every export after export * should overwrite exists

@weswigham

Wesley Wigham (weswigham) commented Mar 5, 2020 •

Copy link
Copy Markdown
Member Author

Except it doesn't, because

export * from './e2'

export function abc()
{

}

compiles to

exports.abc = void 0;
__exportStar(require("./e2"), exports);
function abc() {
}
exports.abc = abc;

and that hoisted exports.abc = void 0 assignment prevents the __exportStar helper from overwriting that member.

@bluelovers

Copy link
Copy Markdown
Contributor

oh, i see

it already fix in current next version

my version still at 20200228

@rbuckton

Copy link
Copy Markdown
Contributor

Wesley Wigham (@weswigham) no, I don't think we should hoist an assignment for default, as that is observable on the module object in CommonJS (and wouldn't be observable on the module namespace object in a true ES module).

I think the behavior of the helper to explicitly skip default is correct and consistent with the spec behavior: https://tc39.es/ecma262/#sec-getexportednames (Step 9.c.i.)

@bluelovers

Copy link
Copy Markdown
Contributor

how about make a exports.default = void 0;
when has export default

@sandersn Nathan Shively-Sanders (sandersn) added the For Milestone Bug PRs that fix a bug with a specific milestone label Mar 25, 2020
@weswigham

Copy link
Copy Markdown
Member Author

Ron Buckton (@rbuckton) ?

@weswigham
Wesley Wigham (weswigham) merged commit 6a5508b into microsoft:master Apr 13, 2020
@weswigham
Wesley Wigham (weswigham) deleted the skip-default-in-exportStar branch April 13, 2020 20:10
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Default export conflicts with star (regression)

5 participants