-
Notifications
You must be signed in to change notification settings - Fork 28
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
fix: Duplicate declarations #79
Closed
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cbe0eb1
Fix duplicate declarations
timfish 52c5ac5
Test for which export takes priority
timfish 0cda956
Merge remote-tracking branch 'upstream/main' into fix-duplicate-export
timfish b0e4e4c
Simplify test since the exports vary by node version
timfish f4b3b47
Merge branch 'main' into fix-duplicate-export
timfish fcda35a
Exclude duplicate exports
timfish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const foo = 'a' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const foo = 'b' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './duplicate-a.mjs' | ||
export * from './duplicate-b.mjs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Hook from '../../index.js' | ||
import { foo } from '../fixtures/duplicate.mjs' | ||
import { strictEqual } from 'assert' | ||
|
||
Hook((exports, name) => { | ||
if (name.endsWith('/duplicate.mjs')) { | ||
// The last export always takes priority | ||
strictEqual(exports.foo, 'b') | ||
exports.foo = '1' | ||
} | ||
}) | ||
|
||
strictEqual(foo, '1') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this change invalidate the preceding comment, which is saying:
a.mjs
exports entities fromb.mjs
b.mjs
exports a default entityb.mjs
should be namedb
under the namespace associated withb.mjs
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.
Not sure, need to check that the tests cover this!
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.
Why does iitm have this namespacing of default exports behaviour? It means that iitm adds additional exports that don't exist without iitm in use. I can see this was added in #53, but why is this desirable?
I assumed we should be exporting exactly the same exports as when the loader is not in use?
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.
IITM basically has to re-implement ESM loading from scratch because it needs to be able to wrap up any of the entities exported by a module. But transitive modules can export entities with the same identifiers as the module that loaded the transitive dependency (or any ancestor module for that matter). This, combined with star exports, means we have to figure out which one is which in some sort of way. The way chosen is a namespace per module.
export * from 'module'
ESM syntax #43 added support for handling star exportsAll of this could be avoided if we had an API where Node does all of the ESM loading and merely gives us back a malleable set of exports.
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.
Yeah I wish for this too. Is this already being addressed as part of nodejs/node#52219, or do we need to push for a separate proposal?
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.
@AbhiPrasad yes, that proposal is what we need to participate in to get the API we would like.