Repository navigation
fix(reference): ignore lexically shadowed require lookups - #1657
rudycelekli wants to merge 4 commits into
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: The fix works. In my 6 shadowed-require cases, Node loads nothing and head makes no dependency edge, where base made one. It also drops the edge in 3 cases where Node does load the file: Thanks, rudycelekli, for the clear PR text and the test that runs the fixtures in Node first. I ran your new test and a second reader through Results
On base, the 8 extra edges all point at On Second readerI wrote 15 small files and ran each one in Node 22.23.1, 24.18.0 and 26.11.1. All three Node versions agreed on every file. Each file requires its own target, and the target prints a line when Node loads it. Then I ran
The last three rows are the ones to look at. In a .cjs file, Node wraps the code in a function that takes For Cases this PR does not change, same at base and head: All 15 cases, one row per fileEdges to node:module from the createRequire files are the same at base and head and are left out.
In total, base made 16 relationships and head made 6. Not run
Test setup
Commandsgit archive 8de54e086 | tar -x -C /tmp/p9-1657/head # same for 4999e4be and d21132fc9
npm ci && npm run build && npm run test:prepare
node node_modules/vitest/vitest.mjs run --project boundary tests/boundary/filesystem/referenceSourceShadowedRequire.test.ts
node node_modules/vitest/vitest.mjs run --project boundary tests/boundary/filesystem/referenceSource
node node_modules/vitest/vitest.mjs run src/domain/referenceSource
node scripts/rea.mjs import-reference-source <folder> --format json🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Integrated the lexical-binding fix on The implementation reuses the shared lexical analyzer, preserves the CommonJS wrapper binding after an uninitialized top-level All 30 tests across the import, computed require, dynamic import, shadowed require, and TypeScript-extension boundary suites passed. Closing this PR as integrated. |
|
TL;DR: Two of the three missing edges are fixed on main. They are Thanks, morluto, for the fix and the note. Thanks, rudycelekli, for the PR and its test. I reran my 15 small files on main 83e5255. It holds f998fcb and three later commits. Of those, only 83e5255 changes the loader files. It only reformats them. Main has since moved to 3749cce, which does not touch them. Node 22.23.1, 24.18.0 and 26.11.1 agreed on which files load. The edges come from
The six shadowed forms (01, 02, 03, 06, 08 and 13) still make no edge on main. Node loads none of them. Rows that did not change from 8de54e0:
The 05 gap fits the note: the code only matches a top-level Tests on main 83e5255:
Not run
All 15 cases, one row per fileEdges to node:module from the createRequire files are left out. The PR head column is from my earlier run, not rerun.
In total, main made 7 relationships and 8de54e0 made 6. Two of the 7 on main point at node:module. Test setup🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
@rudycelekli, thanks for showing that lexically shadowed |
Reference source import currently treats locally bound
requirecalls as CommonJS dependencies. For example,function load(require) { return require("./throwing.cjs"); }creates a dependency edge even when the caller supplies its own loader. The JavaScript semantic analyzer already understands lexical bindings; this change reuses it to accept only unbound globalrequirereferences, including the supportedresolveandmainforms.The regression executes owned Node fixtures and imports them through the production resource-owned source importer. It covers parameters, destructuring, hoisted declarations, catch bindings, dynamic lookup, genuine CommonJS controls, and static/dynamic ESM controls. Existing parser diagnostics are preserved. This addresses source-import relationships; the earlier semantic-analyzer fix in #509 is reused.
Validation on application commit
8de54e086308a2386a0fd0b898d7e2764e36ca4c:npm run verify:test-discovery,npm run check, andnpm run build:cachedpassed with locked dependencies, Node 24.18.0 and npm 11.16.0.The tested base is
4999e4be; main subsequently advanced to26038912without changes to either PR file. The shared semantic projection change only removes the bare CommonJS exports alias and does not alter reference collection. Full-suite and native-provider verification are not claimed. Prepared with AI assistance.