microsoft / microsoft/TypeScript

Find all references doesn't find all results and crashes tsserver if `type S = import().S` syntax is used

オープン
#34,908 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Domain: LS: Symbol Navigation
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

TypeScript Version: 3.9.0-dev.20200223, 3.8.2

Search Terms: Find all references crash tsserver reexport

Code

Reproduction repo

file1.ts

export class Foo {}
export class Bar {}

file2.ts

import * as f1 from './file1';

export class Container {
    readonly classes = f1;
}

declare const c: Container;
c.classes.Foo;

// Uncommenting this line make 'Find all references' work again
// export { f1 };

file3.ts

import { Container } from './file2';

declare const c: Container;
// 'Go to definition' works from here but 'Find all references' doesn't show this line
c.classes.Foo;

Expected behavior:
All three references to Foo are shown, in file1.ts, file2.ts and file3.ts.

Actual behavior:

Reference in file3.ts is not shown.

Workaround?:

Uncommenting // export { f1 }; in file2.ts makes all references to be found, even if no other file imports f1.


EDITED (2020-02-23): I tested this section with TS 3.8.2 and doesn't crash tsserver anymore

In the same repo, but another branch it is shown that with a new file:

file4.ts

type S = import('./file3').S;

find all references on Foo crashes tsserver. Changing file4 to:

import { S } from './file3';

avoid the crash. The tsserver.log shows:

    {"seq":11,"type":"request","command":"references","arguments":{"file":"/tmp/find-references-ts-bug/file3.ts","line":5,"offset":12}}
Err 109   [19:9:26.28] Exception on executing command {"seq":11,"type":"request","command":"references","arguments":{"file":"/tmp/find-references-ts-bug/file3.ts","line":5,"offset":12}}:

    Debug Failure. False expression.

    Error: Debug Failure. False expression.
        at getSourceFileLikeForImportDeclaration (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:109406:22)
        at addIndirectUsers (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:108990:42)
        at addIndirectUsers (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:108990:25)
        at handleNamespaceImport (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:108964:25)
        at handleDirectImports (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:108929:37)
        at getImportersForExport (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:108878:13)
        at State.importTracker (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:108854:26)
        at State.getImportSearches (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:110199:33)
        at searchForImportsOfExport (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:110248:32)
        at getImportOrExportReferences (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:110672:21)
        at getReferencesAtLocation (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:110592:17)
        at getReferencesInContainer (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:110536:21)
        at getReferencesInContainerOrFiles (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:110095:21)
        at getReferencedSymbolsForSymbol (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:110086:21)
        at Object.getReferencedSymbolsForNode (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:109889:34)
        at Object.findReferencedSymbols (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:109567:60)
        at Proxy.findReferences (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:130935:41)
        at /tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:139099:68
        at callbackProjectAndLocation (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:139180:13)
        at /tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:139127:24
        at forEachProjectInProjects (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:139109:17)
        at combineProjectOutputWorker (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:139124:13)
        at combineProjectOutputForReferences (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:139080:13)
        at IOSession.Session.getReferences (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:140208:34)
        at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:139339:61)
        at /tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:140942:88
        at IOSession.Session.executeWithRequestId (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:140933:28)
        at IOSession.Session.executeCommand (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:140942:33)
        at IOSession.Session.onMessage (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:140965:35)
        at Interface.<anonymous> (/tmp/find-references-ts-bug/node_modules/typescript/lib/tsserver.js:142280:27)
        at Interface.emit (events.js:182:13)
        at Interface._onLine (readline.js:290:10)
        at Interface._normalWrite (readline.js:433:12)
        at Socket.ondata (readline.js:149:10)
        at Socket.emit (events.js:182:13)
        at addChunk (_stream_readable.js:283:12)
        at readableAddChunk (_stream_readable.js:264:11)
        at Socket.Readable.push (_stream_readable.js:219:10)
        at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

File text of /tmp/find-references-ts-bug/file3.ts:
    import { Container } from './file2';
    
    declare const c: Container;
    // 'Go to definition' works from here but 'Find all references' doesn't
    c.classes.Foo;
    
    export type S = {};

Related Issues:

Maybe #28680

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされている find-references-ts-bug リポジトリの問題を、file1.ts から file4.ts までの例を使って再現し、その後、tsserver references コマンドと提供された tsserver.log を調査します。type S = import('./file3').S が存在する場合でも、Find all references がクラッシュせずに file1.ts、file2.ts、file3.ts にある Foo の使用箇所をすべて見つけられれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
developer-experience, tooling
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。