Repository navigation
fix(js,ts): this.m() and a local that shadows an import no longer link to the import - #3345
Merged
Merged
Conversation
colbymchenry
force-pushed
the
claude/issue-2954-ts-import-scope
branch
from
November 17, 2026 23:08
79060d3 to
bf545b6
Compare
…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>
colbymchenry
force-pushed
the
claude/issue-2954-ts-import-scope
branch
from
November 18, 2026 00:16
bf545b6 to
8869ba4
Compare
This was referenced Nov 18, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
this.findAll(q)in a class that wraps an importedfindAlllinked to the import, not the class's ownfindAll.const skipString = …aroundconst skipValue = (j) => skipString(j)) linked to the file'simport { skipString }; a call in the declaring function itself linked nothing at all.stream.onAbort()on a callback parameter namedstreaminside hono-stylestream(c, async (stream) => …)linked to the importedstream()function, and so did anyfn.member()on an imported function. The CommonJS form in the issue (Reply.buildReply(Reply)throughrequire) was already fixed in 1.6.3 by fix(js,ts): a member of a required or default-imported module is that module's export #3162; this PR fixes the TypeScript part.Root cause
this.findAll()by the bare namefindAll, andresolveViaImporttook that for the file's import. Python'sself.m()already skips import resolution (isPythonSelfCall); TS/JS had no counterpart.isImportShadowedByJsBinding(fix(ts): a call to a parameter of any type links nothing elsewhere #2732) read a shadowing parameter or local only in the calling function. And it ran afterresolveOneInnerhad finished, so a shadowed import became no edge at all, never the local the name match would have found.Fix
resolveOneInnerstrategy 2: a TS/JSthis./super.call skips import resolution, as Python'sself.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).isImportShadowedByJsBindingreads 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'sjsBindingEnclosesReference), and also covers the receiver of a member call (streaminstream.onAbort). A shadowed import result is now dropped before name matching, which finds the local declaration. Thefunction_refbranch does the same, somatchFunctionReffinds 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 typesstreamasStreamApi.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'sexport namespace observableFromEvent { export function batchEventsGlobally … }does, and then it links that.fn.call,fn.applyandfn.bindstill link the function. Anything else links nothing:matchMethodCallOntreats 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:src/+ 4 testsToolHandler'sthis.findAllSymbols×4 andthis.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 twoskipValuecalls to their ownskipString(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 localisTestPath, which the import used to gate to no edged3a9c2a1)App'sthis.getFormFactorto its own method (the TypeScript: this.m() links to an imported function m instead of the class's own m #2954 example); a destructuredMapnamedduplicateElementswhose.keys/.get/.valueslinked the imported functionsrc/vs/base+src/vs/editor(1,871 files)this.dispose×2,this.applyCodeAction×3,this.getCodeActions,this.computeEditKind,StringSHA1.update/digeston a localhash,Color.isTransparenton a local,observableFromEvent.batchEventsGlobally); removed all right ($.filter×4 and$.maponEvent.chain's$parameter,range.indexOfon arange: number[]parameter, each of which linked an imported function); mocha'sthis.timeout()keeps its old target at 0.7 instead of 0.9Index 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
import stream from './streaming',const debug = require('./debug')) keeps today's link fromfn.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.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 oneonAbortmethod, 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