-
-
Notifications
You must be signed in to change notification settings - Fork 161
fix(dynamic-import): preserve aliased live bindings #9879
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
Closed
proggeramlug
wants to merge
2
commits into
PerryTS:main
from
proggeramlug:fix/9778-dynamic-import-alias
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,3 @@ | ||
| Dynamic imports now expose aliased local `var`, `let`, and `const` exports | ||
| instead of resolving them as `undefined`. Namespace reads also preserve live | ||
| bindings when an exported mutable variable is reassigned after import. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
| var aliasedVar = new Set(["var-before"]); | ||
| let aliasedLet = new Set(["let-before"]); | ||
| const aliasedConst = new Set(["const"]); | ||
|
|
||
| export const directConst = new Set(["direct"]); | ||
|
|
||
| function check(values: Set<string>, expected: string): boolean { | ||
| return values.has(expected); | ||
| } | ||
|
|
||
| function reassign(): void { | ||
| aliasedVar = new Set(["var-after"]); | ||
| aliasedLet = new Set(["let-after"]); | ||
| } | ||
|
|
||
| export { | ||
| aliasedVar as VAR_SET, | ||
| aliasedLet as LET_SET, | ||
| aliasedConst as CONST_SET, | ||
| check as checkAlias, | ||
| reassign, | ||
| }; |
This file contains hidden or 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,29 @@ | ||
| // parity-env: PERRY_GC_SCHEDULE_SEED=9778 PERRY_GC_SCHEDULE_RATE=0.25 PERRY_GC_SCHEDULE_ALLOC_KB=0 PERRY_GC_FORCE_EVACUATE=1 PERRY_GC_VERIFY_EVACUATION=1 PERRY_GC_PROTECT_FROMSPACE=1 | ||
|
|
||
| async function main(): Promise<void> { | ||
| const ns = await import("./dynamic_import_alias_binding.ts"); | ||
|
|
||
| console.log( | ||
| typeof ns.VAR_SET, | ||
| typeof ns.LET_SET, | ||
| typeof ns.CONST_SET, | ||
| typeof ns.directConst, | ||
| typeof ns.checkAlias, | ||
| ); | ||
| console.log( | ||
| ns.checkAlias(ns.VAR_SET, "var-before"), | ||
| ns.checkAlias(ns.LET_SET, "let-before"), | ||
| ns.checkAlias(ns.CONST_SET, "const"), | ||
| ns.checkAlias(ns.directConst, "direct"), | ||
| ); | ||
|
|
||
| ns.reassign(); | ||
| console.log( | ||
| ns.checkAlias(ns.VAR_SET, "var-after"), | ||
| ns.checkAlias(ns.LET_SET, "let-after"), | ||
| ns.checkAlias(ns.VAR_SET, "var-before"), | ||
| ns.checkAlias(ns.LET_SET, "let-before"), | ||
| ); | ||
| } | ||
|
|
||
| main(); |
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.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🌐 Web query:
According to the ECMAScript Language Specification, what descriptor does Module Namespace Exotic Objects [[GetOwnProperty]] return for an exported binding? Does it return a data descriptor with [[Value]] and [[Writable]] true, or an accessor descriptor?💡 Result:
According to the ECMAScript Language Specification (e.g., section 10.4.6.5 in the 2026 specification), the [[GetOwnProperty]] internal method of a Module Namespace Exotic Object returns a data descriptor [1][2][3]. For an exported binding, it returns a data descriptor with the following attributes: { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: false } [4][5]. While the returned descriptor specifies [[Writable]]: true, these objects are designed to provide live bindings to the module's exports [6]. Despite the descriptor's [[Writable]] attribute, attempting to modify these properties via [[Set]] does not update the underlying binding; in fact, the specification and implementation logic often treat such attempts as a no-op or otherwise restricted due to the nature of namespace objects [6]. Accessor descriptors are not used for these properties [6].
Citations:
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🤖 get_repo_knowledge executed:
get_repo_knowledge PerryTS/perry /tmp/coderabbit-repo-knowledge/perryts-perry-d4a878bc/learningsLength of output: 17684
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 25265
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 19953
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 22520
Preserve module namespace property semantics.
js_create_namespaceinstalls live exports withjs_object_define_accessor. The generic descriptor path reportsgetandset, but ECMAScript module namespaces require enumerable, non-configurable data descriptors with the current value andwritable: true.Snapshot exports use the ordinary setter, and
js_finalize_namespaceonly prevents new properties. Namespace writes must reject updates to every export.Special-case
MODULE_NAMESPACE_CLASS_IDin own-property descriptor and set paths. Materialize live values as data descriptors and reject writes. Add coverage for live reads, descriptor shape, and assignment rejection.🤖 Prompt for AI Agents