[PR #538] [MERGED] fix(javascript): correct lexical and dynamic scope analysis #2058

Closed
opened 2026-10-16 21:13:49 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/538
Author: @morluto
Created: 10/5/2026
Status: ✅ Merged
Merged: 10/5/2026
Merged by: @morluto

Base: main ← Head: cleanup/semantic-scope-and-shadowing


📝 Commits (2)

  • 2abfd56 fix(javascript): gate CommonJS exports on unshadowed globals and record dynamic scope
  • ec91661 fix(javascript): correct dynamic and switch scope boundaries

📊 Changes

13 files changed (+337 additions, -28 deletions)

View changed files

📝 docs/product-catalog.json (+2 -2)
📝 docs/verification/managed-conformance-manifest.json (+2 -2)
📝 skills/reverse-engineer-anything/SKILL.md (+1 -1)
📝 src/application/JavaScriptSemanticGraphFlowProjection.ts (+16 -6)
➕ src/application/JavaScriptSemanticGraphScope.test.ts (+147 -0)
📝 src/domain/javascriptSemanticAnalysis.structure.test.ts (+58 -0)
📝 src/domain/javascriptSemanticAnalysis.ts (+42 -6)
📝 src/domain/javascriptSemanticCalls.ts (+32 -0)
📝 src/domain/javascriptSemanticGraphSchemas.ts (+1 -0)
📝 src/domain/javascriptSemanticIr.ts (+13 -2)
📝 src/domain/javascriptSemanticProjection.ts (+12 -8)
📝 src/domain/javascriptSemanticState.ts (+10 -0)
📝 src/generatedMcpToolCatalog.ts (+1 -1)

📄 Description

Static JavaScript analysis could invent CommonJS exports from shadowed names, resolve switch discriminants against case-local declarations, and fail graph construction when encountering with or direct eval.

This change checks lexical and dynamic environments before recognizing CommonJS globals, isolates static-block declarations, shares one lexical scope across switch cases while evaluating the discriminant in its outer scope, and exposes dynamic-scope unknowns through the graph schema. with blocks outer-name resolution while retaining lexical locals; shadowed, optional, and indirect eval calls do not receive a direct-eval frontier. Computed assignments on unrelated or shadowed objects no longer invent wildcard exports.

Rebased onto current main, preserving the existing destructuring-write and compound-assignment read/write fixes. This is static analysis; it does not restore runtime replay or execute analyzed source.

Validation:

  • npm run check:pr: passed; 349 test files, 1,971 tests passed and one skipped.
  • Final semantic regression run: 92 tests across 12 files passed, including public graph construction.
  • npm run check:fast: passed.
  • npm run docs:generate: passed; generated catalog and evidence metadata refreshed.
  • No real Hopper/Ghidra verification performed; these changes affect static JavaScript analysis.

🔄 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/538 **Author:** [@morluto](https://github.com/morluto) **Created:** 10/5/2026 **Status:** ✅ Merged **Merged:** 10/5/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `cleanup/semantic-scope-and-shadowing` --- ### 📝 Commits (2) - [`2abfd56`](https://github.com/morluto/rea/commit/2abfd56b1dcd08dd3b71df4d6cbcc3391ce494cd) fix(javascript): gate CommonJS exports on unshadowed globals and record dynamic scope - [`ec91661`](https://github.com/morluto/rea/commit/ec916614577aa0f6cf67989597de6d2527cd5ff0) fix(javascript): correct dynamic and switch scope boundaries ### 📊 Changes **13 files changed** (+337 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `docs/product-catalog.json` (+2 -2) 📝 `docs/verification/managed-conformance-manifest.json` (+2 -2) 📝 `skills/reverse-engineer-anything/SKILL.md` (+1 -1) 📝 `src/application/JavaScriptSemanticGraphFlowProjection.ts` (+16 -6) ➕ `src/application/JavaScriptSemanticGraphScope.test.ts` (+147 -0) 📝 `src/domain/javascriptSemanticAnalysis.structure.test.ts` (+58 -0) 📝 `src/domain/javascriptSemanticAnalysis.ts` (+42 -6) 📝 `src/domain/javascriptSemanticCalls.ts` (+32 -0) 📝 `src/domain/javascriptSemanticGraphSchemas.ts` (+1 -0) 📝 `src/domain/javascriptSemanticIr.ts` (+13 -2) 📝 `src/domain/javascriptSemanticProjection.ts` (+12 -8) 📝 `src/domain/javascriptSemanticState.ts` (+10 -0) 📝 `src/generatedMcpToolCatalog.ts` (+1 -1) </details> ### 📄 Description Static JavaScript analysis could invent CommonJS exports from shadowed names, resolve switch discriminants against case-local declarations, and fail graph construction when encountering `with` or direct `eval`. This change checks lexical and dynamic environments before recognizing CommonJS globals, isolates static-block declarations, shares one lexical scope across switch cases while evaluating the discriminant in its outer scope, and exposes dynamic-scope unknowns through the graph schema. `with` blocks outer-name resolution while retaining lexical locals; shadowed, optional, and indirect `eval` calls do not receive a direct-eval frontier. Computed assignments on unrelated or shadowed objects no longer invent wildcard exports. Rebased onto current main, preserving the existing destructuring-write and compound-assignment read/write fixes. This is static analysis; it does not restore runtime replay or execute analyzed source. Validation: - `npm run check:pr`: passed; 349 test files, 1,971 tests passed and one skipped. - Final semantic regression run: 92 tests across 12 files passed, including public graph construction. - `npm run check:fast`: passed. - `npm run docs:generate`: passed; generated catalog and evidence metadata refreshed. - No real Hopper/Ghidra verification performed; these changes affect static JavaScript analysis. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-16 21:13:49 +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#2058
No description provided.