-
-
Notifications
You must be signed in to change notification settings - Fork 163
fix(modules): preserve named Node builtin re-exports #10867
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
1
commit into
PerryTS:main
from
proggeramlug:fix/10432-10802-builtin-reexports
Closed
Changes from all commits
Commits
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,6 @@ | ||
| Named exports from Node builtins now survive a local facade module. Both | ||
| `export { createHash } from "node:crypto"` and the equivalent import-then-export | ||
| form publish a live getter for the builtin ESM export value, instead of linking | ||
| to a nonexistent local function or returning an `undefined` stub. This unblocks | ||
| ethers' crypto facade and other packages that wrap Node builtins (#10432, | ||
| #10802). |
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
33 changes: 33 additions & 0 deletions
33
crates/perry/tests/source_graph_export_regressions/issue_10432.rs
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,33 @@ | ||
| use super::{compile_and_run, write}; | ||
|
|
||
| #[test] | ||
| fn named_node_builtin_exports_survive_local_modules() { | ||
| let dir = tempfile::tempdir().expect("tempdir"); | ||
| write( | ||
| dir.path(), | ||
| "direct.ts", | ||
| "export { createHash } from 'node:crypto';\n", | ||
| ); | ||
| write( | ||
| dir.path(), | ||
| "local.ts", | ||
| "import { join } from 'node:path';\n\ | ||
| export { join as pathJoin };\n", | ||
| ); | ||
| write( | ||
| dir.path(), | ||
| "main.ts", | ||
| "import { createHash } from './direct';\n\ | ||
| import { pathJoin } from './local';\n\ | ||
| console.log(typeof createHash, typeof pathJoin);\n\ | ||
| console.log(createHash('sha256').update('x').digest('hex'));\n\ | ||
| console.log(pathJoin('a', 'b'));\n", | ||
| ); | ||
|
|
||
| assert_eq!( | ||
| compile_and_run(dir.path(), "main.ts"), | ||
| "function function\n\ | ||
| 2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881\n\ | ||
| a/b\n" | ||
| ); | ||
| } |
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 | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 26528
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 45525
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 383
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 42172
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 304
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 32018
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 45528
Preserve mutable lookup for
defaultbuiltin re-exports.export { default } from "node:fs"initializes a snapshot cell and the generated getter callsjs_native_module_named_esm_export_value. If the builtin namespace’sdefaultproperty is overwritten after initialization, the re-export can return the cached value instead of the override. Skip named-cell initialization fordefaultand usejs_native_module_esm_export_valuefor that getter. Keep the named helper for actual named exports; the runtime already routes the listedpromises,types,ucs2, and inspector submodule aliases.📍 Affects 2 files
crates/perry-hir/src/lower/module_decl.rs#L1483-L1501(this comment)crates/perry-codegen/src/codegen/artifacts.rs#L771-L812🤖 Prompt for AI Agents