Skip to content

fix(javascript): resolve exported callables through lexical bindings - #1351

Merged
morluto merged 5 commits into
morluto:mainfrom
Y0UW1SH:fix/javascript-exported-function-bindings
Oct 9, 2026
Merged

morluto merged 5 commits into
morluto:mainfrom
Y0UW1SH:fix/javascript-exported-function-bindings

Conversation

@Y0UW1SH

@Y0UW1SH Y0UW1SH commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix exported callable resolution so reassigned bindings cannot retain stale return shapes and private function names cannot attach to unrelated exports. Also resolve nested CommonJS exports through their actual lexical binding and account for writes before hoisted declarations. Reported directly during a source audit; no issue number was supplied.

Problem and expected behavior

Two versions that reassign an exported function to return count: 1 and count: 2 incorrectly compared as zero changes and zero unknowns. Callable IDs and display names bypassed binding checks. Root-scope lookup also associated nested CommonJS exports with unrelated outer bindings, and writes collected before declarations could be dropped or assigned to the wrong scope.

Uncertain, multiply assigned exports must report the existing unavailable/unknown result. Stable function exports and aliases must still compare their actual return shapes.

Change and scope

  • Resolve named export links through the lexical binding captured at the export site; remove callable display-name matching.
  • Retain direct callable IDs for exports without local bindings, including anonymous defaults and directly exported private expressions.
  • Collect declarations before resolving assignment, update, and loop writes, preserving hoisted targets and local shadowing.
  • Keep parameter expressions outside body declarations and evaluate computed method keys in their containing scope. Traverse binding patterns only when detecting parameter expressions.
  • Preserve the existing single-initializer and alias-cycle checks. Exact execution-order selection after multiple writes remains outside this static model.

Contract and boundary impact

  • Semantic owner and earliest changed stages: JavaScript lexical definition collection and module-to-callable resolution.
  • CLI/MCP schemas, inputs, and tool catalog are unchanged; corrected associations use existing selected or unavailable/unknown outcomes.
  • Artifact identity and source provenance are preserved. Production analysis remains inert; tests execute only source-owned fixtures.
  • No provider, dependency, authorization, package, installation, or generated metadata changes.

Evidence and regression coverage

  • Twenty-nine compiled CLI acceptance cases cover reassignment, private-name collisions, stable exports, hoisted writes, local shadowing, nested/block CommonJS exports, parameter defaults and closures, computed destructuring keys, and object/class computed method keys.
  • Node execution independently verifies the fixture exports and the real count: 1 versus count: 2 behavior.
  • Regressions failed before their respective fixes, including six follow-up lexical/hoisting cases and eight function-evaluation-context cases.
  • Reassigned or unrelated numeric exports expose left.status = right.status = "unavailable", summary.unknown = 1, and partial coverage. Stable callable comparisons retain the /count change.
  • Real stdio MCP output matches CLI output for private-name and nested CommonJS numeric collisions.

Validation performed

  • npm run test:local -- src/domain/javascript/*.test.ts: 557 passed across 36 files.
  • Final npm run test:focused -- tests/acceptance/applications/exportedFunctionBindingsCli.test.ts: all 29 compiled CLI/MCP regression cases passed.
  • npm run check: passed, including typecheck, lint, formatting, unused-code, metadata, and module-boundary checks.
  • npm run check:ci: passed, including duplication and TODO checks. Shared assertions reduce local duplicated lines to 2.49% under the 2.5% gate.
  • npm run verify:test-discovery: all 696 local test files discovered exactly once.
  • git diff --check: passed.
  • Independent read-only review and compiled-runtime probes: no remaining blocking findings; verified parameter ownership, capture ancestry, nested aliases, and computed-key scope restoration.

Compatibility and review

No schema migration or execution authority change. Real Hopper/Ghidra and browser verification was not performed because this changes static JavaScript binding resolution only. Full deterministic coverage remains with CI as directed by the repository's focused-check workflow.

  • Concrete bug and reason for no linked issue documented.
  • Regression coverage exercises observable CLI/MCP behavior and independent runtime fixture oracles.
  • Unsupported and uncertain outcomes remain visible.
  • No owning schema or generated metadata update required.
  • Final diff checked for unrelated changes, credentials, and unsupported claims.

@Y0UW1SH
Y0UW1SH marked this pull request as ready for review October 9, 2026 19:24
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

CassieFox23 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: I checked this on Linux, and it fixes the cases it targets. On 6.2.0 and main, a reassigned function export keeps its old return shape. So a real change between two versions reads as "no change". On this branch the same comparison comes back partial. A plain export that really changed is still caught.

The PR's exportedFunctionBindingsCli.test.ts passes: 41 tests.

The full suite passes too, after npm run test:prepare. That was 6,223 tests passed and 89 skipped, with no failures.

For a before and after, each build analyzed v1 and v2 of one app.mjs. Then compare-javascript-export-shapes compared the default export.

Pair, v1 vs v2 6.2.0 and main 7738c1f This branch
P1: a function reassigned later no change 1 unknown, partial
P3: a number beside a named function no change 1 unknown, partial
P2: a reassigned alias 1 unknown, partial 1 unknown, partial
S1: a plain arrow default /count changed /count changed

Here is P1's v1. Its v2 returns count: 2:

function current() { return { count: 0 }; }
current = () => ({ count: 1 });
export { current as default };

P3's v1 is const hidden = function current() { return { count: 0 }; }; const current = 1; export { current as default };.

On 6.2.0 and main, P1 and P3 report the { count: 0 } shape from line 1. But the export no longer points at that function. In P3 the export is a plain number.

One more thing, and it isn't from this PR. Over stdio MCP, a second partial comparison in one session fails with revision_conflict. It does that on 6.2.0 and main too. My test was two alias pairs like P2, compared back to back. This branch makes more results partial, so it will hit that more often.

Test setup
  • Box: Linux x86-64
  • Node: 22.23.1
  • Head: 3a9c1b1c5, from a fresh clone

🤖 Generated with Claude Code (Opus 5.5) 🦊

@morluto

morluto commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Reviewed 0e59898. No blocking correctness issue found. Retaining the lexical binding for each module link fixes the important distinction between callable display names and binding identity. Deferring writes until declarations are collected addresses hoisting/shadowing, and the parameter-expression/body environment plus computed method-key handling is supported by the supplied runtime-oracle cases.

The public CLI/MCP tests cover reassignment uncertainty, private-name collisions, nested CommonJS bindings and stable export controls. CI is green at this head. I would merge this before #1292, then rebase/retest the latter: both change semantic state/collection and their combined behavior needs the exported-binding and reference-lifetime regressions, even if Git currently reports each as conflict-free.

Review scope: changed collection/projection/return-binding code and supplied producer-backed tests. This is not a claim that I independently ran every acceptance case or optional real-provider lane.

@morluto
morluto merged commit a9f5dad into morluto:main Oct 9, 2026
20 checks passed
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: Thanks for the review and the merge. I ran the combined check you asked for on main, with both PRs in. It's clean: the full suite passes, and this PR's cases still come out the same. The details are on #1292.

🤖 Generated with Claude Code (Opus 5.5) 🦊

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…orluto#1351)

* fix(javascript): resolve exported callables through lexical bindings

* fix(javascript): preserve export scope and hoisted writes

* test(javascript): consolidate export binding assertions

* fix(javascript): account for skipped initializers and loop binding writes

* fix(javascript): preserve parameters copied into body variables
@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants