Repository navigation
fix(javascript): land semantic precision fixes - #10538
Conversation
Codex Review Summary: ❌ FailedThis 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 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
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.SummaryThis PR changes JavaScript analysis of getter effects, package exports, Electron aliases, socket options, and destructuring dependencies.
Review limits:
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"]
Reviews (1) · Last reviewed commit: "fix(javascript): retain read-time destru..." · Reviewed by Greptile |
| const alias = | ||
| t.isIdentifier(source) && | ||
| !semanticResolutionBlocked(state, source, source.name) | ||
| ? resolveSemanticBindingState(state, source, source.name) | ||
| : undefined; |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
| 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] : [], | ||
| ), | ||
| ]; |
There was a problem hiding this 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.
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.There was a problem hiding this comment.
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.
| // Every statically truthy shape other than a string literal is a non-string. | ||
| return ( | ||
| staticJavaScriptTruthiness(host) === true && | ||
| !t.isStringLiteral(unwrapJavaScriptExpression(host).node) |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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])); |
There was a problem hiding this 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)
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!
There was a problem hiding this comment.
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.
| const sourceValue = | ||
| initializer == null | ||
| ? undefined | ||
| : evaluateSemanticExpression(initializer, state, initializer, "query"); |
There was a problem hiding this 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)
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!
There was a problem hiding this comment.
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.
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]>
Fixes #9998 Supersedes #10107 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]>
1abd67a to
3098277
Compare
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
thisthere stays the classexportssubpaths keep their uncertainty instead of resolving as exactconst s = n(id); const { BrowserWindow } = s), adapted to thealias_selectionsbudget. 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 setnet/tlsacquisition whosehostis statically truthy and not a string is dropped, because Node throwsERR_INVALID_ARG_TYPEfrom the call. It reads final options through onesocketOptionReadershared with the TLS protocol-version check, and keeps the acquisition when a truthypath, a TLSsocket, or anObject.prototypewrite that may supply one skips the host readContribution scope: ordinary fixes within existing boundaries; maintainer scope decision not applicable.
Evidence and regression coverage
net.connect({host: 1}),{host: true},{host: {}},{host: []}andtls.connect(1, {host: 1})throwERR_INVALID_ARG_TYPE. Falsy hosts (0,"",false,null), a truthypath, and a TLSsocketconnect. The 54 host-member cases follow that. One contributor case (path: "/tmp/x.sock"replaced by a spreadpath: undefined) was moved to "no acquisition", because Node throws there.staticJavaScriptTruthinessnow parses BigInt literals withBigInt, so a0x0n/0o0n/0b0nhost stays falsy whether Babel stores a bigint or the source digits.Validation performed
npm run test:focused --on the changed test files, after rebasing onto current main: 598 passed (before dropping [Bug] A later scalar property assignment makes an earlier destructuring dependency ambiguous #7559).npm run check:fast(pre-push): passed.oxfmt --checkon the changed files: clean.Compatibility, safety, and release
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.