-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
loader, docs, test: named exports from commonjs modules #16675
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
Changes from 1 commit
81fef20
d3647dd
e8478e2
116b470
1a53fd1
ac2b4a1
4a1c95a
49add2b
28f58f6
c6da711
1220d06
fe73e26
c4a6c27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -47,7 +47,7 @@ loaders.set('cjs', async (url) => { | |||
| const keys = es ? Object.keys(exports) : ['default']; | ||||
| return createDynamicModule(keys, url, (reflect) => { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It maps names to safeguard against this already: node/lib/internal/loader/ModuleWrap.js Line 18 in f5a7a9e
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah so it does, my mistake. Missed the |
||||
| if (es) { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is branching like this faster? Otherwise seems like the else branch does exactly what the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't understand what you mean, those two blocks do different things
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sign, nevermind, just another case of misreading. |
||||
| for (let i = 0; i < keys.length; i++) | ||||
| for (var i = 0; i < keys.length; i++) | ||||
| reflect.exports[keys[i]].set(exports[keys[i]]); | ||||
| } else { | ||||
| reflect.exports.default.set(exports); | ||||
|
|
@@ -63,7 +63,7 @@ loaders.set('builtin', async (url) => { | |||
| const keys = Object.keys(exports); | ||||
| return createDynamicModule(['default', ...keys], url, (reflect) => { | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not documented that builtin modules still have a default export.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps for these native module keys we should add a filter -
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not; |
||||
| reflect.exports.default.set(exports); | ||||
| for (let i = 0; i < keys.length; i++) | ||||
| for (var i = 0; i < keys.length; i++) | ||||
| reflect.exports[keys[i]].set(exports[keys[i]]); | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the worries with doing this for native modules was that any updates to native module exports won't be seen. Specifically I think this was an issue when considering APM use cases that monkey patch any native internals. That said, if such issues do come up, setter detection on native modules could possibly be configured to update named exports. |
||||
| }); | ||||
| }); | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // Flags: --experimental-modules | ||
| /* eslint-disable required-modules */ | ||
|
|
||
| // eslint-disable-next-line no-unused-vars | ||
| import eightyfour, { fourtytwo } | ||
| from '../fixtures/es-module-loaders/babel-to-esm-override.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would
Object.getOwnPropertyNames(exports)make more sense?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i chose to use Object.keys so that it only exports enumerable properties. (it says so in the esm doc)