[PR #1803] [CLOSED] fix(javascript): retain unbound require semantic module links #4827

Closed
opened 2026-10-31 00:55:29 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/1803
Author: @rekcilyssup
Created: 10/11/2026
Status: ❌ Closed

Base: main ← Head: fix/javascript-unbound-require-semantic-link


📝 Commits (1)

  • 6227285 fix(javascript): retain unbound require semantic module links

📊 Changes

3 files changed (+163 additions, -0 deletions)

View changed files

📝 src/domain/javascript/javascriptSemanticAnalysis.structure.test.ts (+58 -0)
📝 src/domain/javascript/javascriptSemanticProjection.ts (+69 -0)
📝 tests/boundary/filesystem/javascriptRequireLiteralPaths.test.ts (+36 -0)

📄 Description

Summary

Fixes #1793.

Bare require calls established no binding, so collectSemanticModuleLink never visited the call itself. The application graph kept the static asset reference but omitted the semantic module-to-module edge and reported import_relationships: 0 for the importing module.

Problem and expected behavior

Repro from #1793 (main.cjs containing only require("./dependency.cjs");):

  • Before: zero module_link_kind: "require" edges from main.cjs; source-module observation reports import_relationships: 0.
  • After: one resolved semantic require edge with null imported/local/exported names; import_relationships: 1.

Change and scope

  • src/domain/javascript/javascriptSemanticProjection.ts: collectSemanticModuleLink now also visits CallExpression nodes via collectUnboundRequireLink. It walks up through member-expression bases and transparent TS/paren wrappers to find the owning root; declarator initializers and assignment right-hand sides stay owned by collectRequireLink/collectCommonJsExport (even when their patterns yield no binding, so no duplicate links). semanticRequireOrigin still enforces lexical shadowing and literal specifiers, and member-chain requires (non-empty imported path) are skipped.
  • Not included: package target selection after a link exists (covered by #1762).

Contract and boundary impact

  • Semantic owner and earliest changed stage: collectSemanticModuleLink in the JavaScript semantic projection; bare require calls now emit require module links with null imported/local/exported names.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none; static JavaScript analysis only.
  • Evidence, artifact, provenance, or reconstruction contract: analyze-javascript-application now emits a semantic imports edge plus an incremented import_relationships count for unbound requires; module_format can flip from unknown to commonjs for files whose only require was unbound. No evidence shape changes; the new link uses the existing module-link transfer schema (all-nullable name fields already allowed).
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated:

    • src/domain/javascript/javascriptSemanticAnalysis.structure.test.ts: bare require emits one null-named link; call/argument/return positions each emit one; bound/destructured/export-owned positions gain no duplicate; shadowed and dynamic calls stay link-free.
    • tests/boundary/filesystem/javascriptRequireLiteralPaths.test.ts: end-to-end CLI-shape boundary test reproducing #1793 (three-file fixture from the issue), asserting the resolved semantic edge, null names, import_relationships: 1, and complete coverage.
  • Base reproduction or other evidence: reproduced on 12c41600 with the issue's exact fixture (static asset edges present, zero semantic require edges); after the fix the same command yields one resolved semantic edge and import_relationships: 1.

  • User-visible CLI/MCP output (if applicable): one additional imports edge with module_link_kind: "require" for previously unbound requires.

  • Remaining proof gaps: MCP transport parity not run separately; the boundary test exercises the shared reconstruction workflow both transports use.

  • 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

  • npx vitest run --project domain src/domain/javascript/ — 43 files, 825 tests passed
  • npm run check:fast — typecheck + lint passed
  • npx vitest run --project boundary tests/boundary/filesystem/javascriptRequireLiteralPaths.test.ts tests/boundary/filesystem/javascriptPackagePrecedence.test.ts tests/boundary/filesystem/javascriptHtmlResourcePaths.test.ts tests/boundary/filesystem/referenceSourceShadowedRequire.test.ts tests/boundary/cli/javascriptSelfImportRelationships.test.ts tests/boundary/javascript/javascriptApplicationCancellation.test.ts — 5 files, 54 tests passed
  • npx vitest run --project composition tests/composition/javascript-applications/javascriptModuleRelationships.test.ts — 3 tests passed
  • npx vitest run --project acceptance tests/acceptance/applications/packageJsonImports.test.ts tests/acceptance/applications/packageSubpathsCli.test.ts — 4 tests passed
  • npx vitest run --project services src/application/javascript/ — 18 files, 285 tests passed
  • npm run test:fast — 377 files, 4346 tests passed, 7 skipped
  • node scripts/rea.mjs analyze-javascript-application /tmp/repro1793 --artifact-format directory --json — before: 0 semantic require edges, import_relationships: 0; after: 1 resolved edge, import_relationships: 1

Compatibility, safety, and release

No breaking changes. Files whose only require was previously unbound gain one semantic edge and count; downstream consumers handle null-name require links (same shape as the existing side-effect ESM import link). No migration, package, platform, or security implications.


🔄 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/1803 **Author:** [@rekcilyssup](https://github.com/rekcilyssup) **Created:** 10/11/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/javascript-unbound-require-semantic-link` --- ### 📝 Commits (1) - [`6227285`](https://github.com/morluto/rea/commit/622728582f93cf4d297f831b9c1298ebae82f2d5) fix(javascript): retain unbound require semantic module links ### 📊 Changes **3 files changed** (+163 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/domain/javascript/javascriptSemanticAnalysis.structure.test.ts` (+58 -0) 📝 `src/domain/javascript/javascriptSemanticProjection.ts` (+69 -0) 📝 `tests/boundary/filesystem/javascriptRequireLiteralPaths.test.ts` (+36 -0) </details> ### 📄 Description ## Summary Fixes #1793. Bare `require` calls established no binding, so `collectSemanticModuleLink` never visited the call itself. The application graph kept the static asset reference but omitted the semantic module-to-module edge and reported `import_relationships: 0` for the importing module. ## Problem and expected behavior Repro from #1793 (`main.cjs` containing only `require("./dependency.cjs");`): - Before: zero `module_link_kind: "require"` edges from `main.cjs`; source-module observation reports `import_relationships: 0`. - After: one resolved semantic `require` edge with null imported/local/exported names; `import_relationships: 1`. ## Change and scope - `src/domain/javascript/javascriptSemanticProjection.ts`: `collectSemanticModuleLink` now also visits `CallExpression` nodes via `collectUnboundRequireLink`. It walks up through member-expression bases and transparent TS/paren wrappers to find the owning root; declarator initializers and assignment right-hand sides stay owned by `collectRequireLink`/`collectCommonJsExport` (even when their patterns yield no binding, so no duplicate links). `semanticRequireOrigin` still enforces lexical shadowing and literal specifiers, and member-chain requires (non-empty imported path) are skipped. - Not included: package target selection after a link exists (covered by #1762). ## Contract and boundary impact - Semantic owner and earliest changed stage: `collectSemanticModuleLink` in the JavaScript semantic projection; bare require calls now emit `require` module links with null imported/local/exported names. - CLI and MCP/tool-catalog contract: none. - Provider, bridge, target-format, or platform compatibility: none; static JavaScript analysis only. - Evidence, artifact, provenance, or reconstruction contract: `analyze-javascript-application` now emits a semantic `imports` edge plus an incremented `import_relationships` count for unbound requires; `module_format` can flip from `unknown` to `commonjs` for files whose only require was unbound. No evidence shape changes; the new link uses the existing `module-link` transfer schema (all-nullable name fields already allowed). - Process execution, authorization, cleanup, or containment impact: none. - Generated metadata, package, or installation impact: none. ## Evidence and regression coverage - Tests added or updated: - `src/domain/javascript/javascriptSemanticAnalysis.structure.test.ts`: bare require emits one null-named link; call/argument/return positions each emit one; bound/destructured/export-owned positions gain no duplicate; shadowed and dynamic calls stay link-free. - `tests/boundary/filesystem/javascriptRequireLiteralPaths.test.ts`: end-to-end CLI-shape boundary test reproducing #1793 (three-file fixture from the issue), asserting the resolved semantic edge, null names, `import_relationships: 1`, and complete coverage. - Base reproduction or other evidence: reproduced on `12c41600` with the issue's exact fixture (static asset edges present, zero semantic require edges); after the fix the same command yields one resolved semantic edge and `import_relationships: 1`. - User-visible CLI/MCP output (if applicable): one additional `imports` edge with `module_link_kind: "require"` for previously unbound requires. - Remaining proof gaps: MCP transport parity not run separately; the boundary test exercises the shared reconstruction workflow both transports use. - [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 - `npx vitest run --project domain src/domain/javascript/` — 43 files, 825 tests passed - `npm run check:fast` — typecheck + lint passed - `npx vitest run --project boundary tests/boundary/filesystem/javascriptRequireLiteralPaths.test.ts tests/boundary/filesystem/javascriptPackagePrecedence.test.ts tests/boundary/filesystem/javascriptHtmlResourcePaths.test.ts tests/boundary/filesystem/referenceSourceShadowedRequire.test.ts tests/boundary/cli/javascriptSelfImportRelationships.test.ts tests/boundary/javascript/javascriptApplicationCancellation.test.ts` — 5 files, 54 tests passed - `npx vitest run --project composition tests/composition/javascript-applications/javascriptModuleRelationships.test.ts` — 3 tests passed - `npx vitest run --project acceptance tests/acceptance/applications/packageJsonImports.test.ts tests/acceptance/applications/packageSubpathsCli.test.ts` — 4 tests passed - `npx vitest run --project services src/application/javascript/` — 18 files, 285 tests passed - `npm run test:fast` — 377 files, 4346 tests passed, 7 skipped - `node scripts/rea.mjs analyze-javascript-application /tmp/repro1793 --artifact-format directory --json` — before: 0 semantic require edges, `import_relationships: 0`; after: 1 resolved edge, `import_relationships: 1` ## Compatibility, safety, and release No breaking changes. Files whose only require was previously unbound gain one semantic edge and count; downstream consumers handle null-name require links (same shape as the existing side-effect ESM import link). No migration, package, platform, or security implications. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 00:55:29 +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#4827
No description provided.