Skip to content

fix(javascript): land semantic precision fixes - #10538

Merged
N0zoM1z0 merged 8 commits into
mainfrom
fix/js-semantic-precision
Nov 14, 2026
Merged

N0zoM1z0 merged 8 commits into
mainfrom
fix/js-semantic-precision

Conversation

@N0zoM1z0

@N0zoM1z0 N0zoM1z0 commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Four JavaScript static-analysis precision fixes, each from a contributor PR with authorship kept, or reimplemented with credit. Merge with rebase to keep per-commit authorship.

Fixes #9229
Fixes #9998
Fixes #4490
Fixes #10002

Issue Change From
#9229 Class definition-time effects are projected through getters, and computed definition keys keep their conversion effects. Review follow-up: static blocks and static field values are definition-time work too, so a write through an alias of the getter's receiver invalidates it, while this there stays the class #9233, SahinurDEV
#9998 Trailing-slash exports subpaths keep their uncertainty instead of resolving as exact #10107, dimxxkun
#4490 Electron APIs are followed through aliases of Webpack externals (const s = n(id); const { BrowserWindow } = s), adapted to the alias_selections budget. Review follow-up: each hop checks that the aliased origin is available at that read (var saved=s; var s=n(K) stays unresolved), and the walk shares one visited set #6993, mohammadasim224
#10002 A net/tls acquisition whose host is statically truthy and not a string is dropped, because Node throws ERR_INVALID_ARG_TYPE from the call. It reads final options through one socketOptionReader shared with the TLS protocol-version check, and keeps the acquisition when a truthy path, a TLS socket, or an Object.prototype write that may supply one skips the host read reimplemented; truthy/falsy host tests from #9380 by 吴佳浩 (co-author). #9380's intrinsic-prototype gating is not included

Contribution scope: ordinary fixes within existing boundaries; maintainer scope decision not applicable.

  • Read existing files or captured data.

Evidence and regression coverage

  • [Bug] net/tls socket host member is not decided by its string type #10002: Node 24.22.1 behaviour was probed directly. net.connect({host: 1}), {host: true}, {host: {}}, {host: []} and tls.connect(1, {host: 1}) throw ERR_INVALID_ARG_TYPE. Falsy hosts (0, "", false, null), a truthy path, and a TLS socket connect. The 54 host-member cases follow that. One contributor case (path: "/tmp/x.sock" replaced by a spread path: undefined) was moved to "no acquisition", because Node throws there.
  • Review follow-ups: the hoisted-alias case and the three static-work cases fail without their fixes. staticJavaScriptTruthiness now parses BigInt literals with BigInt, so a 0x0n/0o0n/0b0n host stays falsy whether Babel stores a bigint or the source digits.
  • Contributor tests are kept for the other fixes.

Validation performed

Compatibility, safety, and release

  • Breaking changes: none. Some acquisitions Node can never return are no longer reported.

Author readiness

Human owner: N0zoM1z0 (PR author, exempt from the declaration per CONTRIBUTING.md).

Not included: #7559 (from #7716). Review showed each destructuring read evaluated the whole source object to get one path's presence. That needs a presence-only query in the value evaluator, so it is left for a follow-up.

Supersedes #9233, #10107, #6993 and #9380.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-14T13:08:03.862110Z
We couldn’t complete this review. Comment @codex review to try again.
1abd67a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5 Tier: plus

[Medium impact] The changes affect several JavaScript analysis results, but stay within that analysis workflow.

Do not merge until intermediate alias reads and class static effects are handled correctly, and the required shared-work cleanup is complete.

Findings

  1. P1 Aliases inherit later values ▶
  2. P1 Static work leaves stale values ▶
  3. P2 Zero BigInt hosts disappear ▶
  4. P2 Alias walks repeat growing copies ▶
  5. P2 Small reads rebuild whole objects ▶
Fix with agent prompt
### Issue 1
src/domain/javascript/javascriptSemanticAnalysis.ts:1160-1164
The alias walk follows a declaration without checking what the alias read captured. In a canonical Webpack consumer, `var saved=s; var s=n(45840); const {BrowserWindow}=saved; new BrowserWindow({});` now reaches the later Electron load, even though `saved` captured `undefined`. This can report an Electron window that cannot be created.

The existing `originAvailableAtRead` check only checks the final consumer binding. Use `semanticBindingAtRead` at each alias hop and stop when an ordered read has no initializer.

### Issue 2
src/domain/javascript/javascriptSemanticMemberMutations.ts:409-414
The definition-time walk still skips static field values and static blocks, including writes through an alias of the getter's receiver. For example, `const box={x:1,get trigger(){const self=this;return class {static {self.x=2;}};}}; box.trigger; return box.x;` changes `box.x` to `2`, but this walk never projects the write back to `box`, leaving the stale literal `1`.

Visit static work too. The existing receiver check can keep class-owned `this` separate from the getter's captured receiver. Add the static-field equivalent as well.

### Issue 3
src/domain/javascript/javascriptSemanticResources.ts:949-952
Base-prefixed zero BigInts are wrongly rejected by the new host filter. Babel retains spellings such as `"0x0"` in `BigIntLiteral.value`, while `staticJavaScriptTruthiness` only compares that value with `"0"`. Thus `net.connect({port: 1234, host: 0x0n})` loses its acquisition even though the host is falsy and Node accepts it. The same applies to `0o0n` and `0b0n`.

Normalize the BigInt value in the shared truthiness helper and cover these spellings.

### Issue 4
src/domain/javascript/javascriptSemanticAnalysis.ts:1181
Every alias hop copies the entire growing `visited` set, and separate consumer bindings repeat the same shared chain. A chain of `h` aliases therefore copies about `h²` set entries per consumer, even under the default budget.

This violates the repository requirement to reuse shared work and avoid unnecessary copies, which must be satisfied before merging. Use an iterative walk with one visited set and reuse intermediate origin results, while preserving the budget and read-time checks.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 5
src/domain/javascript/javascriptSemanticObjects.ts:157-160
Each destructuring read now evaluates the entire source object just to obtain path presence. The query cache is fresh for every call, and captured reads cannot use the shared whole-binding cache. Consequently, `n` reads of one field from an unchanged `w`-field object rebuild and sort all `w` fields `n` times.

This violates the repository requirement to reuse shared work and avoid unnecessary copies, which must be satisfied before merging. Use a presence-only query or share unchanged source facts across reads without restoring state-owned copies for every read.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR changes JavaScript analysis of getter effects, package exports, Electron aliases, socket options, and destructuring dependencies.

  • Getter analysis includes effects that run while nested classes and methods are defined.
  • Trailing-slash package subpaths can match wildcard exports.
  • Electron APIs from Webpack externals stay recognizable through stable local aliases.
  • Socket analysis skips calls that cannot acquire a socket because of an invalid host.
  • Destructuring dependencies keep the property presence captured when the source is read.

Review limits:

  • The analyzer probe stopped because zod is not installed. Node controls confirmed the static-block effect and accepted zero BigInt hosts; they did not verify analyzer output.
  • GitHub access was unavailable, so whether this PR has itself been superseded could not be checked.
  • N0zoM1z0 explicitly leaves intrinsic-prototype gating out of scope and keeps wildcard resolution uncertain. No findings were raised for those choices.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["Destructuring source read"] --> B["Evaluate source at that read"]
  B --> C["Keep sourcePresence"]
  C --> E["Project destructures edge"]
  D["Final binding value"] --> E
  E --> F["Resolved or candidate"]
Loading

Reviews (1) · Last reviewed commit: "fix(javascript): retain read-time destru..." · Reviewed by Greptile

Comment on lines +1160 to +1164
const alias =
t.isIdentifier(source) &&
!semanticResolutionBlocked(state, source, source.name)
? resolveSemanticBindingState(state, source, source.name)
: undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Aliases inherit later values

The alias walk follows a declaration without checking what the alias read captured. In a canonical Webpack consumer, var saved=s; var s=n(45840); const {BrowserWindow}=saved; new BrowserWindow({}); now reaches the later Electron load, even though saved captured undefined. This can report an Electron window that cannot be created.

The existing originAvailableAtRead check only checks the final consumer binding. Use semanticBindingAtRead at each alias hop and stop when an ordered read has no initializer.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticAnalysis.ts
Line: 1160-1164

Comment:
**Aliases inherit later values**

The alias walk follows a declaration without checking what the alias read captured. In a canonical Webpack consumer, `var saved=s; var s=n(45840); const {BrowserWindow}=saved; new BrowserWindow({});` now reaches the later Electron load, even though `saved` captured `undefined`. This can report an Electron window that cannot be created.

The existing `originAvailableAtRead` check only checks the final consumer binding. Use `semanticBindingAtRead` at each alias hop and stop when an ordered read has no initializer.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. Fixed in "stop an Electron alias walk at a read before its initializer": the consumer's read-time check is now one module-level originAvailableAt, and every alias hop applies it at the alias read. var saved=s; var s=n(45840); const {BrowserWindow}=saved; is now a no-window case in electronBundledRequireIdentity.test.ts, and it fails without the fix.

Comment on lines +409 to +414
const definitionTimeExpressions = (node: t.Function | t.Class): t.Node[] => [
...(t.isClass(node) && node.superClass != null ? [node.superClass] : []),
...computedDefinitionMembers(node).flatMap((member) =>
"key" in member ? [member.key] : [],
),
];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Static work leaves stale values

The definition-time walk still skips static field values and static blocks, including writes through an alias of the getter's receiver. For example, const box={x:1,get trigger(){const self=this;return class {static {self.x=2;}};}}; box.trigger; return box.x; changes box.x to 2, but this walk never projects the write back to box, leaving the stale literal 1.

Visit static work too. The existing receiver check can keep class-owned this separate from the getter's captured receiver. Add the static-field equivalent as well.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticMemberMutations.ts
Line: 409-414

Comment:
**Static work leaves stale values**

The definition-time walk still skips static field values and static blocks, including writes through an alias of the getter's receiver. For example, `const box={x:1,get trigger(){const self=this;return class {static {self.x=2;}};}}; box.trigger; return box.x;` changes `box.x` to `2`, but this walk never projects the write back to `box`, leaving the stale literal `1`.

Visit static work too. The existing receiver check can keep class-owned `this` separate from the getter's captured receiver. Add the static-field equivalent as well.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. Fixed in "project getter class static work onto the captured receiver": definitionTimeExpressions now includes static blocks and static field values. New cases cover a static block, a static field value, and a static block of a nested heritage class writing through const self = this; all three invalidate box.x and fail without the fix. The existing this-in-static-work cases still keep the literal, because there this is the class.

Comment on lines +949 to +952
// Every statically truthy shape other than a string literal is a non-string.
return (
staticJavaScriptTruthiness(host) === true &&
!t.isStringLiteral(unwrapJavaScriptExpression(host).node)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Zero BigInt hosts disappear

Base-prefixed zero BigInts are wrongly rejected by the new host filter. Babel retains spellings such as "0x0" in BigIntLiteral.value, while staticJavaScriptTruthiness only compares that value with "0". Thus net.connect({port: 1234, host: 0x0n}) loses its acquisition even though the host is falsy and Node accepts it. The same applies to 0o0n and 0b0n.

Normalize the BigInt value in the shared truthiness helper and cover these spellings.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticResources.ts
Line: 949-952

Comment:
**Zero BigInt hosts disappear**

Base-prefixed zero BigInts are wrongly rejected by the new host filter. Babel retains spellings such as `"0x0"` in `BigIntLiteral.value`, while `staticJavaScriptTruthiness` only compares that value with `"0"`. Thus `net.connect({port: 1234, host: 0x0n})` loses its acquisition even though the host is falsy and Node accepts it. The same applies to `0o0n` and `0b0n`.

Normalize the BigInt value in the shared truthiness helper and cover these spellings.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. With the Babel version this repo installs, BigIntLiteral.value is already a normalized bigint (0x0n parses to 0n), so this does not reproduce today. The helper's comment notes that older Babel kept the source digits, though, so "read a BigInt literal's truthiness from any spelling" parses the value with BigInt, which handles both. The host tests now include 0x0n, 0o0n and 0b0n, which keep the acquisition; Node 24.22.1 connects with host: 0x0n.

semanticBindingMayHaveOpaqueEffect(hop, state),
)
? undefined
: bindingOrigin(alias, state, new Set([...visited, binding.bindingId]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Alias walks repeat growing copies

Every alias hop copies the entire growing visited set, and separate consumer bindings repeat the same shared chain. A chain of h aliases therefore copies about h² set entries per consumer, even under the default budget.

This violates the repository requirement to reuse shared work and avoid unnecessary copies, which must be satisfied before merging. Use an iterative walk with one visited set and reuse intermediate origin results, while preserving the budget and read-time checks.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticAnalysis.ts
Line: 1181

Comment:
**Alias walks repeat growing copies**

Every alias hop copies the entire growing `visited` set, and separate consumer bindings repeat the same shared chain. A chain of `h` aliases therefore copies about `h²` set entries per consumer, even under the default budget.

This violates the repository requirement to reuse shared work and avoid unnecessary copies, which must be satisfied before merging. Use an iterative walk with one visited set and reuse intermediate origin results, while preserving the budget and read-time checks.

**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. The walk is linear (one alias per hop), so it now passes one mutable visited set instead of copying it at each hop. The alias budget check still reads its size. I did not add cross-consumer memoization of intermediate origins; the copy was the quadratic part.

Comment on lines +157 to +160
const sourceValue =
initializer == null
? undefined
: evaluateSemanticExpression(initializer, state, initializer, "query");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Small reads rebuild whole objects

Each destructuring read now evaluates the entire source object just to obtain path presence. The query cache is fresh for every call, and captured reads cannot use the shared whole-binding cache. Consequently, n reads of one field from an unchanged w-field object rebuild and sort all w fields n times.

This violates the repository requirement to reuse shared work and avoid unnecessary copies, which must be satisfied before merging. Use a presence-only query or share unchanged source facts across reads without restoring state-owned copies for every read.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticObjects.ts
Line: 157-160

Comment:
**Small reads rebuild whole objects**

Each destructuring read now evaluates the entire source object just to obtain path presence. The query cache is fresh for every call, and captured reads cannot use the shared whole-binding cache. Consequently, `n` reads of one field from an unchanged `w`-field object rebuild and sort all `w` fields `n` times.

This violates the repository requirement to reuse shared work and avoid unnecessary copies, which must be satisfied before merging. Use a presence-only query or share unchanged source facts across reads without restoring state-owned copies for every read.

**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Avoiding this needs a presence-only query (or shared unchanged source facts) in the value evaluator, which is larger than this batch should carry. The #7559 commit is dropped from this PR and left for a follow-up; the PR body says so.

SahinurDEV and others added 8 commits November 14, 2026 13:24
Computed keys and superclass expressions evaluate against the enclosing
getter receiver. Visit those definition-time expressions when collecting
accessor effects, and walk past class/method boundaries in #ownsThis when
the path arrives from heritage or a computed key so receiver writes are
not dropped.

Fixes #9229

Supersedes #9233

Co-Authored-By: gensokyo-dev <[email protected]>
Defining a computed class or object member converts its key to a property
name, so preserve that coercion escape alongside the key expression walk.
Reuse javaScriptComputedDefinitionKey for computed-key ownership in the
getter result walker instead of repeating the check.

Refs #9229

Co-Authored-By: gensokyo-dev <[email protected]>
General provenance only knew a literal require, so a bundled Electron
external held in one binding and destructured from another
(`const s=n(K);const{BrowserWindow}=s`) lost its windows and IPC. The
Electron binding origin now follows stable lexical aliases, and stops at
a rebindable binding that direct eval may have changed.

Fixes #4490
Supersedes #6993

Squashed from #6993 and rebased onto main. Rebase adaptation: the walk
uses the caller-selectable precision.alias_selections budget (the fixed
SEMANTIC_ALIAS_SELECTION_LIMIT it used was removed by #9706) and records
alias-selections when it stops there; a test pins that an over-budget
chain is not claimed and the limit is reported.

Co-Authored-By: gensokyo-dev <[email protected]>
net and tls connect through options.host || "localhost" and throw
ERR_INVALID_ARG_TYPE from the call when that is not a string, so a truthy
non-string host leaves no socket. Read the final host, path and TLS socket
members through one option reader shared with the TLS protocol-version
check, and drop the acquisition only when the host is statically truthy and
not a string while no truthy path or TLS socket, or an Object.prototype
write that may supply one, skips the host read.

The truthy and falsy host tests come from #9380. Its intrinsic-prototype
gating changes are not included.

Fixes #10002

Co-Authored-By: 吴佳浩 <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
…eceiver

Static blocks and static field values run when a class is defined, so a
getter that returns a class whose static work writes through an alias of the
getter's receiver changes that receiver. The definition-time walk now visits
static work too; `this` inside it stays the class.

Refs #9229

Co-Authored-By: gensokyo-dev <[email protected]>
…tializer

The alias walk followed `var saved=s; var s=n(K)` to the later Electron load
although `saved` captured undefined. Each hop now checks, as the consumer
read already did, that the aliased binding's stable origin is available at
that read. The walk also shares one visited set instead of copying it at
every hop.

Refs #4490

Co-Authored-By: gensokyo-dev <[email protected]>
Older Babel keeps a BigInt literal's source digits, which may carry a
0x/0o/0b prefix, so a hexadecimal zero read as truthy and a falsy socket host
such as 0x0n could drop a valid acquisition. Parse the value with BigInt.

Refs #10002

Co-Authored-By: gensokyo-dev <[email protected]>
@N0zoM1z0
N0zoM1z0 merged commit fe80d52 into main Nov 14, 2026
51 of 53 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/js-semantic-precision branch November 14, 2026 13:44
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

6 participants