Skip to content

fix: prevent unrelated CommonJS member call targets - #28

Merged
inth3shadows merged 7 commits into
mainfrom
fix/commonjs-missing-member
Nov 17, 2026
Merged

inth3shadows merged 7 commits into
mainfrom
fix/commonjs-missing-member

Conversation

@inth3shadows

@inth3shadows inth3shadows commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

CommonJS default-binding member calls could resolve to an unrelated class when the imported module does not export that member. This change adds the namespace guard, sync dependency tracking, scope checks, and an isolated tokenizer-based export reader while preserving explicitly exported callable aliases.

Draft checkpoint of the current work. Do not merge by itself: known review finding F8 mistakes wrap(eval)("ignored") for grouped direct eval, which can restore a decoy call for a missing member. The separate correction is #29, based on this branch; review and integrate that follow-up before considering this PR for main.

Validation on this checkpoint: 91 focused tests and npm run build passed. The pre-final-eval full suite passed 10,650 tests (2 expected failures, 448 skips), predating the last eval adjustment. The final checkpoint full run was deliberately interrupted after review demonstrated F8. Both native review lanes completed; the intended eval cases passed, but the broad lane reproduced F8. Final combined verification is tracked in #29.

Refs #27. No deployment or upstream report is included.

Track imported export files during sync, retain callable export aliases, and require block visibility for local class shadows.
A whole-file `module.exports = require('./m')` forwarder was matched on
raw text, so a license header or a trailing comment line made it look
like other code. The default binding then lost its namespace answer and
an absent member fell back to an unrelated class's method by name.
Match the forwarder on comment-blanked text instead.
… and syncs

A .js module is read in JSX mode, where a Flow or TS generic such as
`type Fn = <T>(x: T) => T;` opens an element that never closes and turns
the rest of the file into text. A later `module.exports = new Store()`
went unseen, the module read as a namespace, and a correct member call was
dropped. A read that ends with an element still open is now uncertain.

A call the namespace guard leaves unresolved waits under the module key of
the binding it goes through. Behind a `module.exports = require('./m')`
forwarder that key names the forwarder, so an edit to m.js that made the
call resolvable was never retried, and a sync disagreed with a fresh
index. The sync's failed-reference retry now adds the keys of the
forwarders that reach a changed file.
…onJS writes

A Flow or TS generic such as `type Fn = <T>(x: T) => T;` reads as a JSX
element in JSX mode, and a `</div>` later in a comment or string closes it,
so the file looked fully read while `module.exports = new Decoy()` sat in
the swallowed text. The module read as a namespace and a correct member call
was dropped. A file with any JSX is now read in plain mode as well: either
read being uncertain makes it uncertain, and a member either read sees is a
member. Both only hand the file back to the resolution it had before.

A whole-file forwarder needs both `require(` and `exports`, so files without
them skip the comment strip (the sync's forwarder walk reads every importer).
@inth3shadows
inth3shadows force-pushed the fix/commonjs-missing-member branch from 8c34a85 to c6bb300 Compare November 17, 2026 11:40
@inth3shadows
inth3shadows marked this pull request as ready for review November 17, 2026 11:41
@inth3shadows
inth3shadows merged commit 2963976 into main Nov 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant