Repository navigation
fix(reference): stop attributing overwritten require members to Node - #3801
Conversation
import-reference-source treated require.resolve(...) and require.main(...) as Node's resolver even after the file replaced that member, so a literal argument became a parsed internal dependency that the source never loads. Attribute member calls only while the loader's resolve and main members keep Node's identity: no write to either member or a computed member (assignment, update, delete, destructuring) and no use of require as a value where a mutator or alias could replace them. Bare require(...) calls are unaffected. Fixes #3393 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; both previous findings are addressed. SummaryThe PR stops treating overwritten
Reviews (2) · Last reviewed commit: "fix(reference): keep optional and wrappe..." · Reviewed by Greptile |
An optional call require?.(...) or a TypeScript or parenthesis wrapper around require was read as require escaping as a value, which disabled every member-call link in the file. Look through inert wrappers and accept optional calls before deciding the loader escaped, and add controls for bare calls after a member overwrite, a local loader's member write, and optional calls. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #3393
Root cause
unshadowedReferenceSourceRequireCalls(src/domain/referenceSourceRequireBindings.ts) decides which calls are Node's loader. Forrequire.resolve(...)andrequire.main(...)it checked only therequirebinding: unbound or wrapper-owned, and never reassigned. It never checked whether the member had been replaced. Afterrequire.resolve = () => "custom", the literal argument still became a parsed internalrequiresedge, although the call never resolves a module.Change
Member calls are attributed only while the loader's
resolveandmainmembers keep Node's identity (requireLoaderMembersIntact). Their identity is unknown, and the member calls are not attributed, when either holds:require.resolve,require.mainor a computedrequire[...]. Write sites come from the sharedsemanticWriteSiteTarget/semanticWriteTargetshelpers, so assignment, compound assignment, update,delete,for…in/ofand destructuring targets are all covered.requireused as a value other than a direct call, a member read ortypeof, for exampleObject.defineProperty(require, …),Object.assign(require, …)orconst r = require. A mutator or alias can then replace members without a visible member write.This matches how the boundary already excludes shadowed or reassigned loaders. Bare
require("…")calls are unaffected.Validation
The issue's repro and controls, public CLI,
mainvs this PR:main.cjsmainrequire.resolve = () => "custom"; require.resolve("./dep.cjs")requires dep.cjs(false)Object.defineProperty(require, "resolve", …); require.resolve("./dep.cjs")requires dep.cjs(false)patch(require); require.resolve("./dep.cjs")requires dep.cjsrequire.resolve("./dep.cjs")(control)requires dep.cjsrequires dep.cjspatch(require); require("./dep.cjs")(bare call)requires dep.cjsrequires dep.cjsReal sources,
mainvs this PR: relationships are identical and the rest of the graph is byte-identical.node_modules/pinohas 575 relationships (0.55 s / 0.53 s),playwright-core/lib1,362 (2.24 s / 2.26 s) and REAsrc/11,637 (2.97 s / 2.99 s). Output size is unchanged.Tests:
does not attribute overwritten require members to Node's resolverinreferenceSourceShadowedRequire.test.tscovers assigned,definePropertyand computed-key overwrites plus a control. Each is first executed under Node to establish the oracle (customorstring), and only the control keeps its edge. The test fails onmain; I checked by restoring main's classifier and rebuilding.npm run check:fast.🤖 Generated with Claude Code