-
-
Notifications
You must be signed in to change notification settings - Fork 161
fix(module): synchronize named builtin exports #9944
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed named imports from Node builtins to retain their ESM export value until `syncBuiltinESMExports()` copies CommonJS namespace changes. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #[test] | ||
| fn direct_named_calls_use_the_synchronized_esm_cell() { | ||
| let source = r#" | ||
| import { readFile } from "node:fs"; | ||
| import { syncBuiltinESMExports } from "node:module"; | ||
| syncBuiltinESMExports(); | ||
| readFile(); | ||
| "#; | ||
| let module = perry_parser::parse_typescript(source, "sync-builtins.ts").expect("source parses"); | ||
| let hir = super::super::lower_module(&module, "sync-builtins", "sync-builtins.ts") | ||
| .expect("source lowers"); | ||
| let dump = format!("{:#?}", hir.init); | ||
| assert!( | ||
| dump.contains("js_native_module_named_esm_export_value"), | ||
| "named call must read the synchronized ESM cell: {dump}" | ||
| ); | ||
| assert!( | ||
| dump.matches("js_native_module_named_esm_export_value") | ||
| .count() | ||
| >= 2, | ||
|
Comment on lines
+18
to
+20
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Assert the exact ESM-cell arguments and order.
🤖 Prompt for AI Agents |
||
| "named import must initialize its ESM cell before the dynamic call: {dump}" | ||
| ); | ||
| assert!( | ||
| !dump.contains("module: \"fs\",\n class_name: None,\n object: None,\n method: \"readFile\""), | ||
| "named call must not bypass the ESM cell through native dispatch: {dump}" | ||
| ); | ||
| } | ||
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
Initialize routed named object exports through an ESM cell.
Line 16 excludes named imports whose routed
native_methodisNone. This includesimport { promises } from "node:fs"andimport { types } from "node:util".Those bindings are lowered as
NativeModuleRefvalues. They never enterNATIVE_ESM_EXPORT_VALUES, sosyncBuiltinESMExports()cannot refresh them after a CommonJS property replacement. Preserve the original named-export identity and lower these imports through the snapshot-backed getter while retaining submodule member dispatch.🤖 Prompt for AI Agents