[PR #5387] [MERGED] fix(javascript): resolve preceding exported variable initializers and computed method keys #6915

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5387
Author: @ahmed-husssain
Created: 10/20/2026
Status: ✅ Merged
Merged: 10/27/2026
Merged by: @morluto

Base: main ← Head: fix/js-call-graph-var-initializer


📝 Commits (1)

  • 51388e1 fix(javascript): resolve variable initializers before computed method keys

📊 Changes

3 files changed (+86 additions, -2 deletions)

View changed files

📝 src/domain/javascript/javascriptSemanticCallResolution.test.ts (+53 -0)
📝 src/domain/javascript/javascriptSemanticMutationInitializers.test.ts (+27 -1)
📝 src/domain/javascript/javascriptSemanticMutationInitializers.ts (+6 -1)

📄 Description

Summary

Allow top-level effect ordering to traverse through computed method keys, resolving preceding variable initializers and computed method keys as straight-line evaluations.

Problem and expected behavior

When a variable initializer is evaluated and invoked within a computed method key before a subsequent conditional mutation:

function original() {}
function replacement() {}
let make = original;
const obj = { [make()]() { return 1; } };
if (flag) [make] = [replacement];

semanticTopLevelEffectFollowsCapture previously aborted its traversal at t.isFunction(node) without checking whether the child was a computed method key evaluated during object/class definition in the enclosing environment. This caused the write to fail precedence proof, leaving the call target as an ambiguous candidate rather than completely resolved.

Expected behavior:
Computed method keys execute in the enclosing activation during object construction, so preceding straight-line bindings must be recognized as preceding writes and resolve completely (exact).

Change and scope

  1. In src/domain/javascript/javascriptSemanticMutationInitializers.ts, updated semanticTopLevelEffectFollowsCapture to check !semanticComputedMethodKey(node, child) before aborting at function nodes, reusing semanticComputedMethodKey from javascriptSemanticEvaluationOrder.js.
  2. In src/domain/javascript/javascriptSemanticMutationInitializers.test.ts, added unit tests verifying that class and object computed method key reads are ordered as evaluated at definition time.
  3. In src/domain/javascript/javascriptSemanticCallResolution.test.ts, added regression coverage verifying that calls in computed method keys before subsequent conditional pattern writes resolve as exact.

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/javascript/javascriptSemanticMutationInitializers.ts (semanticTopLevelEffectFollowsCapture)
  • Contribution scope fit and linked maintainer decision: not applicable (domain bug fix within existing boundaries)
  • CLI and MCP/tool-catalog contract: none
  • Provider, bridge, target-format, or platform compatibility: static JavaScript application analysis
  • Evidence, artifact, provenance, or reconstruction contract: none
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • 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

  • Tests added or updated:
    • src/domain/javascript/javascriptSemanticMutationInitializers.test.ts (orders method key reads with static=false only when evaluated at class definition, orders computed method key reads evaluated during object literal definition)
    • src/domain/javascript/javascriptSemanticCallResolution.test.ts (resolves calls in computed method keys before subsequent pattern writes)
  • Base reproduction or other evidence: Reverting the change causes the two unit tests to fail with expected false to be true and the call resolution test to fail with resolution: ambiguous instead of resolution: exact.
  • User-visible CLI/MCP output (if applicable): none
  • Remaining proof gaps: none

For evidence-bearing changes:

  • 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 -- src/domain/javascript/javascriptSemanticCallResolution.test.ts src/domain/javascript/javascriptSemanticMutationInitializers.test.ts — 40 passed (27 + 13), 0 failed
  • npm run test:focused -- src/domain/javascript/javascriptSemanticAnalysis.calls.test.ts tests/boundary/filesystem/javascript-applications/javascriptApplicationTypeScript.test.ts — 28 passed (16 + 12), 0 failed
  • npm run check:fast — 2 tasks successful (typecheck, lint)
  • npm run docs:check — 6 tasks successful, README consistency passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none
  • Real Hopper/Ghidra, browser, or OS coverage: static analysis domain logic
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: none

Author readiness

Human owner: @ahmed-husssain

  • 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 (No standalone issue was filed; resolves incomplete call resolution identified during exploration of top-level mutation ordering across computed method keys).
  • 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.

🔄 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/5387 **Author:** [@ahmed-husssain](https://github.com/ahmed-husssain) **Created:** 10/20/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/js-call-graph-var-initializer` --- ### 📝 Commits (1) - [`51388e1`](https://github.com/morluto/rea/commit/51388e197a8d0f7c47f1de90d2c442275b9a3aa0) fix(javascript): resolve variable initializers before computed method keys ### 📊 Changes **3 files changed** (+86 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/domain/javascript/javascriptSemanticCallResolution.test.ts` (+53 -0) 📝 `src/domain/javascript/javascriptSemanticMutationInitializers.test.ts` (+27 -1) 📝 `src/domain/javascript/javascriptSemanticMutationInitializers.ts` (+6 -1) </details> ### 📄 Description ## Summary Allow top-level effect ordering to traverse through computed method keys, resolving preceding variable initializers and computed method keys as straight-line evaluations. ## Problem and expected behavior When a variable initializer is evaluated and invoked within a computed method key before a subsequent conditional mutation: ```js function original() {} function replacement() {} let make = original; const obj = { [make()]() { return 1; } }; if (flag) [make] = [replacement]; ``` `semanticTopLevelEffectFollowsCapture` previously aborted its traversal at `t.isFunction(node)` without checking whether the child was a computed method key evaluated during object/class definition in the enclosing environment. This caused the write to fail precedence proof, leaving the call target as an ambiguous candidate rather than completely resolved. Expected behavior: Computed method keys execute in the enclosing activation during object construction, so preceding straight-line bindings must be recognized as preceding writes and resolve completely (`exact`). ## Change and scope 1. In `src/domain/javascript/javascriptSemanticMutationInitializers.ts`, updated `semanticTopLevelEffectFollowsCapture` to check `!semanticComputedMethodKey(node, child)` before aborting at function nodes, reusing `semanticComputedMethodKey` from `javascriptSemanticEvaluationOrder.js`. 2. In `src/domain/javascript/javascriptSemanticMutationInitializers.test.ts`, added unit tests verifying that class and object computed method key reads are ordered as evaluated at definition time. 3. In `src/domain/javascript/javascriptSemanticCallResolution.test.ts`, added regression coverage verifying that calls in computed method keys before subsequent conditional pattern writes resolve as exact. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). Unresolved scope, authority, side effects, or required verification block integration. Link the required maintainer scope decision for new providers or capabilities involving target execution, injection, mutation, or protection recovery; ordinary fixes within existing boundaries may state "not applicable". Draft PRs may leave the scope decision pending and the readiness and merge checklists unchecked. Maintainers can help resolve open questions. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/domain/javascript/javascriptSemanticMutationInitializers.ts` (`semanticTopLevelEffectFollowsCapture`) - Contribution scope fit and linked maintainer decision: not applicable (domain bug fix within existing boundaries) - CLI and MCP/tool-catalog contract: none - Provider, bridge, target-format, or platform compatibility: static JavaScript application analysis - Evidence, artifact, provenance, or reconstruction contract: none - Target selection, authority, upstream behavior, and cleanup details (if applicable): none - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [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 - Tests added or updated: - `src/domain/javascript/javascriptSemanticMutationInitializers.test.ts` (`orders method key reads with static=false only when evaluated at class definition`, `orders computed method key reads evaluated during object literal definition`) - `src/domain/javascript/javascriptSemanticCallResolution.test.ts` (`resolves calls in computed method keys before subsequent pattern writes`) - Base reproduction or other evidence: Reverting the change causes the two unit tests to fail with `expected false to be true` and the call resolution test to fail with `resolution: ambiguous` instead of `resolution: exact`. - User-visible CLI/MCP output (if applicable): none - Remaining proof gaps: none For evidence-bearing changes: - [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 -- src/domain/javascript/javascriptSemanticCallResolution.test.ts src/domain/javascript/javascriptSemanticMutationInitializers.test.ts` — 40 passed (27 + 13), 0 failed - `npm run test:focused -- src/domain/javascript/javascriptSemanticAnalysis.calls.test.ts tests/boundary/filesystem/javascript-applications/javascriptApplicationTypeScript.test.ts` — 28 passed (16 + 12), 0 failed - `npm run check:fast` — 2 tasks successful (typecheck, lint) - `npm run docs:check` — 6 tasks successful, README consistency passed ## Compatibility, safety, and release - Breaking changes or migration steps: none - Real Hopper/Ghidra, browser, or OS coverage: static analysis domain logic - Package or release metadata impact: none - Security, privacy, process, or containment review: none ## Author readiness Human owner: @ahmed-husssain - [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 - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above (No standalone issue was filed; resolves incomplete call resolution identified during exploration of top-level mutation ordering across computed method keys). - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <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:02 +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#6915
No description provided.