#6972

feat(javascript): model objects assigned to properties after declaration

OpenIvenKooLabwants to merge intofrom

Summary

Models an object literal assigned to a property after declaration (Game.config = { ACCEL: 0.001 }) the same way an initializer object is modelled, so literals inside it become traceable. Fixes #6192.

  • The assignment-flow IR (from #6206) now carries the statically evaluated container for an unconditional top-level assignment of a literal object/array into a static property path (assignedValue: receiver name, property path, evaluated value).
  • A shared projection helper (foldedAssignedContainerValues) applies two filters and both the value and object projections consume it: repeated top-level literal writers keep only the last value; any other write intersecting the path — conditional, inside a function or loop, or a non-literal right-hand side — leaves the value unknown, preserving the existing mutation semantics.
  • Value projection materializes the ancestor slot chain so the container slot reports object/array status; object projection folds the value into the map reads resolve against, which is what lets read:/config/ACCEL resolve.

Evidence

The issue's fixtures, through the compiled CLI on this branch (found = the full chain 0.001 → ACCEL → read:/config/ACCEL → return):

fixtureslotstrace(0.001)
function Game() {} + assignmentconfig:object, config.ACCEL:literalfound (control parity)
const Game = {} + assignmentconfig:object, config.ACCEL:literalfound (control parity)
initializer controlunchangedfound
conditional assignmentunknownpartial (unchanged)
assignment inside a functionunknownpartial (unchanged)

Also verified: later non-literal writer keeps unknown; repeated literal assignments fold to the last value; nested paths (App.settings.limits.retries) and arrays (App.list = [7, 8]) model correctly.

Testing

  • JavaScriptSemanticGraphPropertyObjects.test.ts — 9/9 (function/assigned receivers, control parity, conditional/in-function/loop guards, non-literal writer, last-write-wins, nested paths and arrays)
  • javascriptPropertyObjectModeling.test.ts (compiled CLI) — both issue fixtures through analyze-javascript-application + trace-javascript-semantics to found with the read site and return reached
  • Regression: src/application/javascript/ + the #6206 CLI acceptance 572/572; src/domain/javascript/ + tests/evaluation/ 4316 passed / 2 pre-existing skips; tsc --noEmit, knip, formatting and lint clean

Author readiness

Human owner: @IvenKooLab

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Activity

6
chatgpt-codex-connector[bot]1mo ago
Codex Review Summary: ✅ Completed

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

ReviewStatusCommitReview trigger
📝 Code Review✅ Completed 2026-11-09T10:44:12.913848Z4617f06New commits
ℹ️ 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.

greptile-apps[bot]1mo ago

Confidence Score: 4/5

[Medium impact] The PR changes JavaScript semantic results and traces for eligible property assignments.

Do not merge until stores to read-only function and class properties stop producing confirmed values.

Findings

  1.  Rejected writes become confirmed values ▶
  2.  Large bundles repeat full scans ▶
Fix with agent prompt
### Issue 1
src/domain/javascript/javascriptSemanticValues.ts:1042-1049
The new fold turns a function or class into an empty object with `unknownProperties: false`. This treats existing read-only properties as missing writable slots.

For `function Game() {}; Game.length = { ACCEL: 0.001 }; export function accel() { return Game.length.ACCEL; }`, the analyzer retains `0.001`, although assigning `Game.length` is ignored or throws. Getter-only static properties have the same problem. Analysts can therefore get a confirmed trace from a literal the program never stores.

Preserve these property restrictions, or keep the stores unknown, before confirming the assigned value.

### Issue 2
src/application/javascript/JavaScriptSemanticGraphAssignedValues.ts:45-57
Each folded assignment scans all bindings and object operations, and both projection passes repeat the calculation. A large bundle with many independent top-level property objects therefore adds quadratic work before the next yield. Index receivers and writes once, reuse the fold result, and allow long folding work to yield.

---

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

Summary

The PR moves post-declaration object and array stores into semantic binding values.

  • Assigned object and array literals can now be traced through their properties.

Validation was source-based; dependencies were unavailable, so tests were not run. No actionable security issue was identified. Whether another PR supersedes this one could not be checked because GitHub access was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Collected property write] --> B{Single definite top-level literal store?}
  B -- No --> U[Keep affected value unknown]
  B -- Yes --> C{Overlapping writer or earlier read?}
  C -- Yes --> U
  C -- No --> D[Update semantic binding value]
  D --> E[Apply remaining writes and escapes]
  E --> F[Project property slots and reads]

Reviews (4) · Last reviewed commit: "fix(javascript): own retained property s..." · Reviewed by Greptile

IvenKooLab1mo ago

Synced with current main, which had evolved the #6206 landing since this PR branched:

  • JavaScriptSemanticGraphAssignments.test.ts is an add/add against main's adjusted copy — took main's version verbatim (this PR's changes live in the new JavaScriptSemanticGraphPropertyObjects.test.ts).
  • The assignment collector now runs on main's erased-syntax-aware walker (traverseJavaScriptValueAstSteps) with its state-first signature; the conditional-depth guard and the assignedValue capture are re-fitted onto it unchanged.
  • The IR keeps the assignedValue field; tests adopt the query schema's new required fields (include_ambiguous_dynamic_edges, expected).

Verification on the merged head: the property-object suites 9/9, main's assignment tests, and the compiled-CLI acceptance all pass (25/25 focused; src/application/javascript/ 570/570); tsc --noEmit, knip, formatting clean.

IvenKooLab1mo ago

All review findings are addressed in 49855457e (plus one design note and one follow-up). Summary per finding:

Fixed:

  • Compound operators (P1, collector): assignedContainerValue now requires operator === "=".
  • Skipped-expression branches (P1, collector): the local node-type set is replaced by the shared semanticBranchMayBeSkipped owner, so destructuring defaults, logical right sides, optional-chain arguments and the rest of its coverage no longer fold.
  • Mutation invalidation on escape (P1): a later read of the container itself (path equal to or a prefix of the folded path) after the assignment vetoes the fold — the reference may have escaped and been mutated.
  • Reads before the assignment (P1): folded values now apply positionally in objectTarget; only reads at or after the assignment's target observe them.
  • Dynamic member writes (P1): a null-path write on the same receiver vetoes every candidate fold for it (folded targets themselves are exempt).
  • Non-object receivers (P1): receiverObjectCapable rejects concrete primitive/null receivers; unknown covers functions and classes with expando properties.
  • Shadowed receivers (P2): folds resolve through the object operation's objectBindingId, never a display-name lookup.
  • Nested-writer evaluation order (P2): the assignment that commits last wins, selected by whole-expression source-range enclosure (an inner write inside the RHS loses to its enclosing assignment).
  • Array receiver named properties (P2): valueWithAssignedContainer inserts named slots for array receivers too, matching JavaScript's named own properties on arrays.

Each scenario is pinned by a guard test in JavaScriptSemanticGraphPropertyObjects.test.ts (now 17 cases).

Design note — literal attribution (P1, value projection): folded literals intentionally keep the slot-anchored node identity (property:[binding, path] role key) rather than the assignment's source location. Re-keying literal nodes by assignment position would split identical values across nodes per write site and churn node identities the #6206 defines edges already anchor; the assignment's own operator and target are carried by those edges instead. If Evidence should cite the assignment range explicitly, that belongs in the relation metadata, and I'm happy to add it on request.

Follow-up — fully resolved dual-writer chains (P1 read-order remainder): in the initializer-plus-fold scenario (const G={config:{x:1}}; read; G.config={x:2}; read), the later read reaches the folded literal through candidate edges because the initializer-written container keeps its mutation-unknown presence. The positional application is in place; upgrading that chain to fully resolved needs presence reconciliation between initializer facts and folds, which I'd rather land separately with its own tests.

Verification on 49855457e: src/application/javascript/ + the compiled-CLI acceptance 579/579; src/domain/javascript/ + tests/evaluation/ 4368 passed / 2 pre-existing skips; tsc --noEmit, knip, formatting clean.

On the three failing CI checks: packagedWasmVerifierOwnership fails identically on current main (verified locally at upstream/main: 3/3 failing with the same rea-verifier-command-… vs /^rea-package-command-/ prefix assertion, from main's in-flight verifier-naming change) — this PR's diff does not touch the wasm/process domains.

CassieFox2317d ago

TL;DR: The PR's 2 test files pass, 18 of 18 on Node 22.23.4, 24.22.1 and 26.12.1. I probed the overlap case from a code read, and it shows no stale value. That is only because Game.config.sub = { B: 1 } doesn't fold even without the overwrite, so I have one question.

CheckNode 22.23.4Node 24.22.1Node 26.12.1
Head 49855457e4, the PR's 2 test filespass: 18 of 18 testspass: 18 of 18 testspass: 18 of 18 tests
Head 49855457e4, my probe filepass: 2 of 2 testspass: 2 of 2 testspass: 2 of 2 tests

The overlap probe

A code read raised a worry. When a parent is written after a child, the folded child value might survive. I wrote a probe file to check, using the same helpers as JavaScriptSemanticGraphPropertyObjects.test.ts. It traces forward from the literal 1. Its assertions pin the slot states below, and it logs the trace.

SourceSlot statesTrace from 1
Game.config = {}; Game.config.sub = { B: 1 }; Game.config = { A: 1 }; then read Game.config.subconfig.A:literal, config.sub:unknown, config:objectfound: nodes 1 and A, no read:/config/sub
The same without Game.config = { A: 1 }config.sub:unknown, config:objectpartial: no nodes

After the overwrite, config.sub is unknown, and the trace doesn't reach the read. So there is no stale value in this case. But the second row gives the same unknown for config.sub, and the 1 in B isn't traced at all. A write to a two-level member path doesn't seem to fold. So the probe can't tell a cleared fold from no fold.

One question

The PR body says nested paths like App.settings.limits.retries model correctly. The test for that, models nested property paths and arrays at line 114, writes App.settings = { limits: { retries: 3 } };. That is a one-level write with a nested literal.

Is a write to a nested member path, like Game.config.sub = { B: 1 }, meant to fold too? If not, maybe the body could say so.

CI

  • CI, PR readiness and PR title are completed/success.
  • 21 check runs passed, including Portable tests, Source tests, Static checks and CI required. 19 were skipped.
  • GitHub reports mergeable true and state clean. The head is 1395 commits behind main 25d3c7237f.

Not run

  • tsc, knip and lint on the PR branch.
  • A merge with current main, 25d3c7237f.
Probe file

Saved as src/application/javascript/JavaScriptSemanticGraphPropertyObjectsProbe.test.ts on the head.

import { describe, expect, it } from "vitest";
import { graphForJavaScript } from "../../../tests/fixtures/javascriptSemanticGraph.js";
import { queryJavaScriptSemanticGraph } from "../../domain/javascript/javascriptSemanticQuery.js";

const slotStates = (graph: ReturnType<typeof graphForJavaScript>) =>
  graph.nodes
    .filter((node) => node.kind === "property-slot")
    .map(
      (node) =>
        `${(node.properties as { property_path: string[] }).property_path.join(".")}:${
          (node.properties as { value_status: string }).value_status
        }`,
    )
    .sort();

it("does not report a nested property after the container is overwritten", () => {
  const graph = graphForJavaScript(`
    const Game = {};
    Game.config = {};
    Game.config.sub = { B: 1 };
    Game.config = { A: 1 };
    export const out = Game.config.sub;
  `);

  console.log("slotStates (overwritten container)", JSON.stringify(slotStates(graph)));

  expect(slotStates(graph)).toEqual(["config.A:literal", "config.sub:unknown", "config:object"]);
  expect(slotStates(graph)).not.toContain("config.sub:object");
  expect(slotStates(graph)).not.toContain("config.sub:B");

  const trace = queryJavaScriptSemanticGraph(graph, {
    seed: { kind: "literal", value: 1 },
    direction: "forward-influence",
    include_ambiguous_dynamic_edges: true,
    expected: null,
  });
  console.log("trace status (overwritten container)", JSON.stringify(trace.status));
  console.log("trace nodes labels (overwritten container)", JSON.stringify(trace.nodes.map((n) => n.label)));

  const subReads = trace.nodes.filter((n) => n.label === "read:/config/sub");
  console.log("read:/config/sub nodes (overwritten container)", JSON.stringify(subReads));

  const aReads = trace.nodes.filter((n) => n.label === "read:/config/A");
  console.log("read:/config/A nodes (overwritten container)", JSON.stringify(aReads));
});

it("reports a nested property when the container is not overwritten", () => {
  const graph = graphForJavaScript(`
    const Game = {};
    Game.config = {};
    Game.config.sub = { B: 1 };
    export const out = Game.config.sub;
  `);

  console.log("slotStates (not overwritten container)", JSON.stringify(slotStates(graph)));

  expect(slotStates(graph)).toEqual(["config.sub:unknown", "config:object"]);

  const trace = queryJavaScriptSemanticGraph(graph, {
    seed: { kind: "literal", value: 1 },
    direction: "forward-influence",
    include_ambiguous_dynamic_edges: true,
    expected: null,
  });
  console.log("trace status (not overwritten container)", JSON.stringify(trace.status));
  console.log("trace nodes labels (not overwritten container)", JSON.stringify(trace.nodes.map((n) => n.label)));

  const subReads = trace.nodes.filter((n) => n.label === "read:/config/sub");
  console.log("read:/config/sub nodes (not overwritten container)", JSON.stringify(subReads));
});
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 49855457e4 / 2e86294c86 (merge base with main)
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/application/javascript/JavaScriptSemanticGraphPropertyObjects.test.ts tests/boundary/cli/javascriptPropertyObjectModeling.test.ts
xvfb-run -a npm run test:focused -- src/application/javascript/JavaScriptSemanticGraphPropertyObjectsProbe.test.ts

🤖 Written and tested with Claude Code (Opus 5.5), posted with my OK 🦊