TypeScript版本: 3.9.0-dev.20200223, 3.8.2
搜索词: 查找所有引用crash tsserver reexport
代码
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;
预期行为:
所有三个对 Foo
的引用都会显示,分别在 file1.ts
、 file2.ts
和 file3.ts
中。
实际行为:
在 file3.ts
中的引用没有显示。
解决方法?:
取消注解 // export { f1 };
在 file2.ts
中,使得所有引用都能被找到,即使没有其他文件导入 f1
。
编辑(2020-02-23):我在同一个仓库中测试了这部分内容,使用 TS 3.8.2 时不再导致 tsserver 崩溃。但是在同一个仓库中,当使用新文件 file4.ts 时,发现在 Foo
上查找所有引用会导致 tsserver 崩溃。将 file4 更改为:
import { S } from './file3';
可以避免崩溃。在 tsserver.log 中显示:
{"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 = {};
相关问题:
也许与 #28680 有关
1条答案
按热度按时间qnyhuwrf1#
我使用TS 3.8.2测试了这个问题,崩溃(问题的一部分)没有发生()。我编辑了问题信息以隐藏这一部分。
然而,在TS 3.9.0-dev.20200223中,第一部分仍然发生了。除非我取消注解导出,否则引用将无法正确找到。我已经更新了复现仓库(bug1分支)的依赖项以证明这一点。