Skip to content

fix(js,ts): this.m() and a local that shadows an import no longer link to the import - #3345

Merged
colbymchenry merged 1 commit into
mainfrom
claude/issue-2954-ts-import-scope
Nov 18, 2026
Merged

colbymchenry merged 1 commit into
mainfrom
claude/issue-2954-ts-import-scope

Conversation

@colbymchenry

@colbymchenry colbymchenry commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

A JS/TS file's import binds a name for the whole module, and the import resolver answers before name matching. Three kinds of call that it answered mean something else:

Root cause

Fix

  • resolveOneInner strategy 2: a TS/JS this./super. call skips import resolution, as Python's self. call does (isJsThisCall). Name matching then reaches the class's own member through the own-class walk (fix(resolution): resolve a call to the caller's own class member before ranking same-file namesakes #1952).
  • isImportShadowedByJsBinding reads the calling function and each function around it, innermost first (jsBindingAroundReference, on fix(ts): a call to a parameter of any type links nothing elsewhere #2732's jsBindingEnclosesReference), and also covers the receiver of a member call (stream in stream.onAbort). A shadowed import result is now dropped before name matching, which finds the local declaration. The function_ref branch does the same, so matchFunctionRef finds the local.
  • isImportBinding (which gates the TS receiver readers) counts a receiver as an import only when nothing shadows it, so the fix(ts): callback parameters, call results and type guards type the receiver #3319 callback-parameter reader types stream as StreamApi.
  • resolveViaImport: a member of a function imported by name is not a call of the function. A namespace merged with the function may declare it, as vscode's export namespace observableFromEvent { export function batchEventsGlobally … } does, and then it links that. fn.call, fn.apply and fn.bind still link the function. Anything else links nothing: matchMethodCallOn treats such a receiver as past guessing (isImportedFunctionReceiver), as it already did a namespace import.

Validation

  • New __tests__/js-import-binding-scope.test.ts, 6 cases: 5 fail on main and pass now. The guard (a call outside the shadowing function keeps the import) passes on both.

  • A/B against the 1.6.3 source (147fe290), both arms on the same 1.6.3 kernel, changed call sites triaged by reading each one:

    repo changed verdict
    codegraph's own src/ + 4 tests 9 retargeted, 2 added all right: ToolHandler's this.findAllSymbols ×4 and this.groupDefinitions ×3 to its own methods (the TypeScript: this.m() links to an imported function m instead of the class's own m #2954 examples); react.ts's two skipValue calls to their own skipString (the TypeScript: a local that shadows a project import is ignored from a nested arrow; the call links to the import #2949 examples); handleExplore's two calls of its local isTestPath, which the import used to gate to no edge
    excalidraw (d3a9c2a1) 1 retargeted, 3 removed all right: App's this.getFormFactor to its own method (the TypeScript: this.m() links to an imported function m instead of the class's own m #2954 example); a destructured Map named duplicateElements whose .keys/.get/.values linked the imported function
    vscode src/vs/base + src/vs/editor (1,871 files) 11 retargeted, 6 removed, 1 confidence retargets all right (this.dispose ×2, this.applyCodeAction ×3, this.getCodeActions, this.computeEditKind, StringSHA1.update/digest on a local hash, Color.isTransparent on a local, observableFromEvent.batchEventsGlobally); removed all right ($.filter ×4 and $.map on Event.chain's $ parameter, range.indexOf on a range: number[] parameter, each of which linked an imported function); mocha's this.timeout() keeps its old target at 0.7 instead of 0.9
    flask, gin (controls) byte-identical
  • Index cost, median of 3 interleaved rounds, CPU of all threads (a box shared with other agents' suites): vscode 68.1 s → 67.6 s, excalidraw 32.2 s → 32.8 s. Within noise.

  • Rebased onto 1ddbe69 (fix(rust): a call through a module that a glob use brings in links again #3334, Rust-only): the src and test patch is unchanged (git patch-id). On the rebased head, its own test file plus the 105 TS/JS resolution test files pass: 106 files, 1,335 passed, 1 skipped. Full suite: on the combination of this group's PRs, reported when it finishes.

Left out

  • A default import of a function (import stream from './streaming', const debug = require('./debug')) keeps today's link from fn.member() to the function: the issue is about named imports, and the CommonJS default form is fix(js,ts): a member of a required or default-imported module is that module's export #3162's.
  • After this PR, stream.onAbort() on a parameter written with an object type (stream: { onAbort(…): void }, line 9 of the issue's table) no longer links the import. When the project has exactly one onAbort method, it still takes the general one-method guess an untyped receiver takes. Ruling that guess out for every object-typed parameter lost right edges in the A/B (callers pass real objects), so it stays.

Fixes #2954
Fixes #2953
Fixes #2949

🤖 Generated with Claude Code

@colbymchenry
colbymchenry force-pushed the claude/issue-2954-ts-import-scope branch from 79060d3 to bf545b6 Compare November 17, 2026 23:08
…k to the import

A JS/TS file's import binds a name for the whole module, and the import
resolver answers before name matching. Three calls it answered mean
something else.

Issue 2954: this.findAll() is recorded by the bare name findAll, so a
class wrapping an imported helper of the same name linked its own calls
to the import. Python's self.m() already skips import resolution
(isPythonSelfCall); TS/JS now does the same (isJsThisCall), and name
matching reaches the class's own member, as it does for a name the file
doesn't import.

Issue 2949: isImportShadowedByJsBinding read a shadowing parameter or
local only in the calling function, so a nested arrow's call of a helper
its enclosing function declares linked to the import, and a shadowed call
in the declaring function itself linked nothing. It now reads the calling
function and each function around it, innermost first
(jsBindingAroundReference). A shadowed import result is dropped before
name matching, which finds the local declaration, rather than after it.

Issue 2953: a member call x.m() through a named import of a function fell
back to the function itself when it found no member m, and the shadow
check skipped dotted names, so stream.write() on a callback parameter
named stream linked to the imported stream(). The check now reads the
receiver of a member call (the import is dropped when a parameter or local
of that name is in scope, which the TS readers then type), the receiver
counts as an import binding only when nothing shadows it, and a member of
an imported function is no call of the function: a namespace merged with
the function may declare it (vscode's
observableFromEvent.batchEventsGlobally), fn.call/apply/bind still link
the function, and anything else links nothing rather than a guess by the
member's name. The CommonJS form in the issue (Reply.buildReply through
require) was already fixed in 1.6.3 by PR 3162.

Validation:
- New js-import-binding-scope.test.ts, 6 cases: 5 fail on main and pass
  now; the guard (a call outside the shadowing function keeps the import)
  passes on both.
- A/B against the 1.6.3 source, both arms on the 1.6.3 kernel:
  - codegraph's own src: 9 retargeted, ToolHandler's this.findAllSymbols
    x4 and this.groupDefinitions x3 to its own methods, react.ts's two
    skipValue calls to their own skipString; 2 added, handleExplore's
    calls of its local isTestPath, which the import used to shadow-gate
    to nothing.
  - excalidraw: App's this.getFormFactor to its own method; 3 removed,
    a destructured Map named duplicateElements whose .keys/.get/.values
    linked the imported function.
  - vscode src/vs/base + editor: 11 retargeted, all right (this.dispose,
    this.applyCodeAction x3, this.getCodeActions, this.computeEditKind,
    StringSHA1's update/digest on a local hash, Color.isTransparent on a
    local, observableFromEvent.batchEventsGlobally); 6 removed, calls on
    parameters named like an import ($.filter x4, $.map, range.indexOf);
    1 confidence change, mocha's this.timeout() still on async's timeout.
  - flask and gin: byte-identical.
- Index cost (median of 3, interleaved, CPU of all threads): vscode
  68.1 s -> 67.6 s, excalidraw 32.2 s -> 32.8 s; within noise.
- 106 TS/JS resolution test files pass on this commit (1,335 tests, 1 skipped).

Fixes #2954
Fixes #2953
Fixes #2949

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

1 participant