-
-
Notifications
You must be signed in to change notification settings - Fork 159
fix(hir): a createRequire-backed local require is not a shadow (#8465)
#8466
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 @@ | ||
| fix(hir): a local `require` created by node:module's `createRequire` no longer counts as shadowing the require intrinsic (#8465). #8343's shadow guard regressed `const require = createRequire(import.meta.url); const net = require("net")` — the mysql2/turbopack bundling idiom — off the static native-namespace fold and onto a runtime dispatch surface whose `net.connect` arm is a null function pointer in default-feature builds, silently returning undefined. The binding is now marked createRequire-backed at declaration and exempted; a real `function require(...)` body (the CJS wrap's synthetic require, #8343) still shadows. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -982,6 +982,17 @@ pub struct LoweringContext { | |
| /// observe the failure instead of rejecting the whole user source at | ||
| /// compile time. Outside try blocks, `require(literal)` still hard-errors. | ||
| pub(crate) optional_require_try_depth: u32, | ||
| /// #8465: `const require = createRequire(import.meta.url)` (node:module's | ||
| /// own ESM idiom, including an aliased import of `createRequire`) binds | ||
| /// the REAL module-scoped CommonJS require — for builtin specifiers it | ||
| /// returns exactly the native namespace. Set when that declaration is | ||
| /// seen so `require_is_shadowed_by_local` does not treat the binding as | ||
| /// shadowing the require intrinsic; the CJS wrap's synthetic | ||
| /// `function require(...)` (a real function with a body) still shadows | ||
| /// via `lookup_func`. Module-wide and scope-blind like `proxy_locals` — | ||
| /// strictly narrower than the pre-#8343 behavior, which ignored ALL | ||
| /// local `require` bindings on this path. | ||
| pub(crate) require_local_is_create_require: bool, | ||
|
Comment on lines
+985
to
+995
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 | 🟠 Major | 🏗️ Heavy lift Track the createRequire-backed binding by This module-wide boolean remains true after lowering a nested createRequire-backed Track the resolved createRequire-backed 🤖 Prompt for AI Agents |
||
| /// Pre-scanned constant environment for `new Function` / `Function(...)` | ||
| /// argument resolution (single-assignment module vars, `toString`-bearing | ||
| /// object literals, counters). Built once per module in | ||
|
|
||
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 | ⚡ Quick win
Verify that
createRequirecomes from Node'smoduleAPI.The direct-name branch accepts any local function named
createRequire. The imported-name branch also accepts an export namedcreateRequirefrom any module. Both cases can cause a user-definedrequireto foldrequire("net")as Node's native namespace.Resolve the callee to a named import from
node:moduleormodulebefore setting this state.🤖 Prompt for AI Agents