Skip to content

fix(sync): a call through an imported object follows an edit to its members - #3373

Merged
colbymchenry merged 1 commit into
mainfrom
claude/issue-3015-sync-object-members
Nov 18, 2026
Merged

colbymchenry merged 1 commit into
mainfrom
claude/issue-3015-sync-object-members

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

Summary

In JavaScript and TypeScript, a call through an imported object (api.bar() after import { api } from './api', with export const api = { foo, bar }) binds to the member the object literal names, or to the object itself when it names none. When a sync edited the literal (adding, removing or repointing a member), the call in the unchanged caller kept its old target until the caller changed or the project was indexed again. A sync now follows such an edit, and its result matches a fresh index.

Root cause

The caller's file is unchanged, so its references aren't re-resolved. The edit declares no name: { foo } → { foo, bar } adds no definition (bar already existed), and neither does { bar } → { bar: baz }. So the definition-delta rebind (CG-33) and the module re-open passes (default exports, barrels, name-matched imports, re-export targets) had nothing to go on. The literal's members aren't stored in the index; the resolver reads them from source each time.

Fix

A new sync pass, reopenReferencesThroughObjectMembers (src/resolution/module-importers.ts), runs after the other re-open passes for edited modules.

  1. For each object literal that an edited JS/TS file exports to another file, it reads the literal's members from the new text. Such a literal is a constant or variable that an imports edge reaches.
  2. It takes each importer's references through that object (L.m…, under whatever local name the importer uses) with getResolutionEdgesThrough.
  3. It sends back to pending only the references that the new text disagrees with:
    • on the object, though the literal now has the member;
    • anywhere else, though the literal no longer has the member;
    • on a different name than the identifier the member names (an import alias of that identifier counts as the same name);
    • outside the literal, though the member is now written inline.

The orphan sweep then resolves them exactly as a full index does. An edit that leaves the members alone re-opens nothing. A literal whose members a spread or computed key hides is left as before. CODEGRAPH_NO_REBIND=1 turns the pass off together with the rebind.

The pass reads members with the same scan the resolver uses (objectLiteralProperty in name-matcher.ts), now split into objectLiteralMemberSpans / objectLiteralMemberOf so both share it.

Validation

  • New tests. __tests__/sync-object-members.test.ts indexes the first tree, edits, syncs, and compares the whole graph (edges and unresolved refs) with a full index of the final tree.

    • It covers a member that is added, removed, repointed (bar → bar: baz) and written inline.
    • It covers a facade whose members come from another module, reached under an alias (import { api as A }) and through a barrel.
    • It checks that neither an aliased-import member nor an untouched member is re-opened.
    • The 5 change cases fail on main and pass here (7 passed).
  • Area tests. Sync, object-literal and alias-resolution test files: 18 files, 321 passed.

  • Fresh indexes are byte-identical to v1.6.3's sources (3 interleaved rounds) on taxonomy, excalidraw, vscode-be, and the controls flask and gin. The shared member scan changed nothing.

  • Sync cost on excalidraw (1,318 files), medians of 3, with the arm order alternating each round. Two runs, v1.6.3 sources → this branch:

    sync run 1 run 2
    nothing changed 2.05 s → 1.87 s 1.36 s → 1.37 s
    body edit (scene/Renderer.ts) 4.42 s → 4.33 s 3.26 s → 3.55 s
    edit to common/src/keys.ts, whose KEYS literal 67 files import (~710 uses) 5.46 s → 4.17 s 3.61 s → 3.73 s

    Timed on its own (CODEGRAPH_SYNTH_TIMINGS), the pass takes 0–1 ms on the body edit and 67–113 ms on the keys.ts edit, re-opening nothing. The rest of the swings are this shared machine's noise.

  • Full suite: see the PR's READY note.

Left out

  • A literal hidden behind a spread or a computed key keeps today's behaviour.
  • Class statics (K.bar() after adding static bar) and Object.assign targets aren't followed.
  • A member that names an identifier is checked by name. A target reached under a third name, beyond the import alias that is handled, is re-opened and re-resolved on each edit of that file: correct, at a small cost.

Thanks @inth3shadows for the report and the differential harness that found it.

Fixes #3015

🤖 Generated with Claude Code

@colbymchenry
colbymchenry force-pushed the claude/issue-3015-sync-object-members branch from b930d01 to 3eb619e Compare November 18, 2026 03:54
…embers

In JavaScript and TypeScript, a call through an imported object binds to
the object's member when the object literal has one, and to the object
itself when it doesn't: `api.bar()` after `import { api } from './api'`,
with `export const api = { foo, bar }`. When a sync edited the literal, the
caller's file was unchanged, so its references weren't re-resolved, and the
edit declares no name (`{ foo }` to `{ foo, bar }`, `{ bar }` to
`{ bar: baz }`), so the definition-delta rebind (CG-33) and the other
module passes re-opened nothing. The call kept its old target, the object
or the old member, until the caller changed or the project was indexed
again, including through a facade whose members come from another module.

A new sync pass, after the other re-open passes for edited modules, reads
each object literal an edited JS/TS file exports to another file (a
constant or variable an `imports` edge reaches) from its new text, takes
the importers' references through it (`L.m`, under whatever local name),
and sends back to pending only those its text now disagrees with: on the
object though the literal has the member; elsewhere though it has the
member no more; on another name than the identifier the member names (an
import alias counts as that name); outside the literal though the member is
written inline. The orphan sweep then resolves them as a full index would.
An edit that leaves the members alone re-opens nothing. A literal whose
members a spread or computed key hides is left as before.
CODEGRAPH_NO_REBIND=1 turns the pass off with the rebind.

The literal's members are read by the same scan the resolver uses
(objectLiteralProperty), now split so both share it.

Validation:
- sync-object-members.test.ts: a member added, removed, repointed and
  written inline; a facade whose members come from another module, reached
  under an alias and through a barrel; an aliased import member and an
  untouched member re-open nothing. Each case compares the synced graph with
  a full index of the final tree. The 5 change cases fail on main and pass
  here (7 passed).
- Sync, object-literal and alias resolution tests: 18 files, 321 passed.
- Sync cost on excalidraw (1,318 files), medians of 3 with the arm order
  alternating, in two runs (v1.6.3 sources vs this branch): no-change sync
  2.05 s vs 1.87 s and 1.36 s vs 1.37 s; a body edit 4.42 s vs 4.33 s and
  3.26 s vs 3.55 s; an edit to packages/common/src/keys.ts, whose KEYS
  literal 67 files import, 5.46 s vs 4.17 s and 3.61 s vs 3.73 s. Timed on
  its own (CODEGRAPH_SYNTH_TIMINGS), the pass takes 0-1 ms on the body edit
  and 67-113 ms on the keys.ts edit, re-opening nothing; the rest is this
  shared machine's noise.
- Fresh indexes are byte-identical to v1.6.3 sources on taxonomy,
  excalidraw, vscode-be and controls flask and gin (3 interleaved rounds).

Fixes #3015

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sync: a call through an imported object stays put when a sync adds or removes the object's member

1 participant