[PR #5594] [CLOSED] fix(javascript): carry a directly returned value's literal to its return site #6987

Closed
opened 2026-11-01 21:44:30 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5594
Author: @kaoru0822-kitauji
Created: 10/20/2026
Status: ❌ Closed

Base: main ← Head: fix/js-return-member-provenance


📝 Commits (1)

  • ad3d995 fix(javascript): carry a directly returned value's literal to its return site

📊 Changes

3 files changed (+100 additions, -7 deletions)

View changed files

📝 src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts (+31 -0)
📝 src/application/javascript/JavaScriptSemanticGraphFlowProjection.ts (+8 -0)
📝 src/application/javascript/JavaScriptSemanticGraphValueProjection.ts (+61 -7)

📄 Description

Summary

Fixes #5585. Backward provenance from const b = viaMember() lost the known string "products" when viaMember directly returned settings.index, and reported ambiguous. Returning through a local variable, or assigning settings.index directly, kept it. Now all three bindings reach "products" through resolved flow with status found, with candidates disabled and enabled.

Problem and expected behavior

collectSemanticReturns evaluates each return expression (settings.index → literal "products"), but graph projection used that value nowhere:

  • projectSemanticValues projected literals only for binding values.
  • projectSemanticReturnValues linked identifier references inside the return expression as aliases: resolved only when the whole expression is that identifier, otherwise candidate. For return settings.index the only edge into the return site was a candidate alias from the receiver settings, which is not the returned value.

Change and scope

  • JavaScriptSemanticGraphValueProjection.ts: for return sites without an identity reference (any non-identifier return), project the evaluated primitive as a literal node that defines the return site. A literal value is resolved; a union gives one candidate per member, mirroring binding values. The literal helper now takes an explicit owner key, location and function node, so binding literals keep their existing role keys.
  • JavaScriptSemanticGraphFlowProjection.ts: when such a return evaluates to one exact literal, its inner references are no longer emitted as candidate aliases. A primitive is not an alias of the receiver, matching how const direct = settings.index is already projected.
  • Identifier returns (return value) and non-literal returns are unchanged.

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

Contract and boundary impact

  • Semantic owner and earliest changed stage: semantic graph projection of return sites (src/application/javascript/JavaScriptSemanticGraph*Projection.ts).

  • Contribution scope fit and linked maintainer decision: ordinary fix; not applicable.

  • CLI and MCP/tool-catalog contract: no schema change. Graphs gain literal -defines-> return-site relations, and lose receiver candidate aliases for literal-valued non-identifier returns.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: provenance becomes more precise for these returns; identities of existing binding literal nodes are unchanged.

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

  • Launch or attach to a process.

  • Inject instrumentation or run scripts/code.

  • Change process memory, registers, files, or configuration.

  • Contact network services.

  • Recover protected code or work around protections.

  • Documentation or usability only; no target interaction.

  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Test added in JavaScriptSemanticGraphBuilder.test.ts: the issue's fixture, with candidates off and on. Backward provenance from both a (via local) and b (direct member return) is found with exactly the "products" literal.

  • Base reproduction: with the two projection files stashed, both cases fail.

  • Issue repro through the built CLI (analyze-javascript-application then trace-javascript-semantics, candidates off) on the fixed build: a, b and direct each reach "products" with status found. The issue recorded b as ambiguous with no literal on base.

  • Remaining proof gaps: other non-identifier return shapes with literal values (e.g. return 1, return x ? "a" : "b") follow the same rule but have no dedicated test beyond the existing suites.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- all 70 JavaScript semantic test files (src/application/javascript/JavaScriptSemantic*.test.ts, src/domain/javascript/javascriptSemantic*.test.ts, and every test under tests/ mentioning semantic traces, backward provenance or return sites): 70 files, 1615 tests passed (before adding the new test)
  • npm run test:focused -- src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts: 70 passed; with the projection changes stashed: 2 failed (new cases), 68 passed
  • npm run check:fast: passed
  • npm run build:cached then the issue's CLI trace for a, b and direct: all found with "products"

Compatibility, safety, and release

  • Breaking changes or migration steps: none; semantic graph content changes as described.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; static analysis only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no execution of analyzed code.

Author readiness

Human owner: @kaoru0822-kitauji

  • 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.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5594 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/js-return-member-provenance` --- ### 📝 Commits (1) - [`ad3d995`](https://github.com/morluto/rea/commit/ad3d9956047bcd00baaf4e96455a76c7d9c7b90d) fix(javascript): carry a directly returned value's literal to its return site ### 📊 Changes **3 files changed** (+100 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts` (+31 -0) 📝 `src/application/javascript/JavaScriptSemanticGraphFlowProjection.ts` (+8 -0) 📝 `src/application/javascript/JavaScriptSemanticGraphValueProjection.ts` (+61 -7) </details> ### 📄 Description ## Summary Fixes #5585. Backward provenance from `const b = viaMember()` lost the known string `"products"` when `viaMember` directly returned `settings.index`, and reported `ambiguous`. Returning through a local variable, or assigning `settings.index` directly, kept it. Now all three bindings reach `"products"` through resolved flow with status `found`, with candidates disabled and enabled. ## Problem and expected behavior `collectSemanticReturns` evaluates each return expression (`settings.index` → literal `"products"`), but graph projection used that value nowhere: - `projectSemanticValues` projected literals only for binding values. - `projectSemanticReturnValues` linked identifier references inside the return expression as aliases: resolved only when the whole expression is that identifier, otherwise `candidate`. For `return settings.index` the only edge into the return site was a candidate alias from the receiver `settings`, which is not the returned value. ## Change and scope - `JavaScriptSemanticGraphValueProjection.ts`: for return sites without an identity reference (any non-identifier return), project the evaluated primitive as a `literal` node that `defines` the return site. A literal value is `resolved`; a union gives one `candidate` per member, mirroring binding values. The literal helper now takes an explicit owner key, location and function node, so binding literals keep their existing role keys. - `JavaScriptSemanticGraphFlowProjection.ts`: when such a return evaluates to one exact literal, its inner references are no longer emitted as candidate aliases. A primitive is not an alias of the receiver, matching how `const direct = settings.index` is already projected. - Identifier returns (`return value`) and non-literal returns are unchanged. Contribution scope: ordinary fix within existing boundaries; maintainer scope decision not applicable. ## Contract and boundary impact - Semantic owner and earliest changed stage: semantic graph projection of return sites (`src/application/javascript/JavaScriptSemanticGraph*Projection.ts`). - Contribution scope fit and linked maintainer decision: ordinary fix; not applicable. - CLI and MCP/tool-catalog contract: no schema change. Graphs gain `literal -defines-> return-site` relations, and lose receiver candidate aliases for literal-valued non-identifier returns. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: provenance becomes more precise for these returns; identities of existing binding literal nodes are unchanged. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Test added in `JavaScriptSemanticGraphBuilder.test.ts`: the issue's fixture, with candidates off and on. Backward provenance from both `a` (via local) and `b` (direct member return) is `found` with exactly the `"products"` literal. - Base reproduction: with the two projection files stashed, both cases fail. - Issue repro through the built CLI (`analyze-javascript-application` then `trace-javascript-semantics`, candidates off) on the fixed build: `a`, `b` and `direct` each reach `"products"` with status `found`. The issue recorded `b` as `ambiguous` with no literal on base. - Remaining proof gaps: other non-identifier return shapes with literal values (e.g. `return 1`, `return x ? "a" : "b"`) follow the same rule but have no dedicated test beyond the existing suites. - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:focused --` all 70 JavaScript semantic test files (`src/application/javascript/JavaScriptSemantic*.test.ts`, `src/domain/javascript/javascriptSemantic*.test.ts`, and every test under `tests/` mentioning semantic traces, backward provenance or return sites): 70 files, 1615 tests passed (before adding the new test) - `npm run test:focused -- src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts`: 70 passed; with the projection changes stashed: 2 failed (new cases), 68 passed - `npm run check:fast`: passed - `npm run build:cached` then the issue's CLI trace for `a`, `b` and `direct`: all `found` with `"products"` ## Compatibility, safety, and release - Breaking changes or migration steps: none; semantic graph content changes as described. - Real Hopper/Ghidra, browser, or OS coverage: not applicable; static analysis only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no execution of analyzed code. ## Author readiness Human owner: @kaoru0822-kitauji - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [ ] This PR addresses a concrete problem or an agreed enhancement. - [ ] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [ ] The PR has one focused outcome and the title follows `type(scope): outcome`. - [ ] Related issue is linked, or the reason for not linking one is stated above. - [ ] Tests cover changed observable behavior and meaningful failure paths. - [ ] Owning docs, contracts, and generated metadata are updated where needed. - [ ] User-visible CLI/MCP changes include representative output. - [ ] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:44:30 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6987
No description provided.