Skip to content

Commit 394a777

Browse files
authored
fix(51963): Invalid property read for find-all-references when exporting non-existent binding (#52006)
1 parent f326cbf commit 394a777

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

src/services/importTracker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ export function getImportOrExportSymbol(node: Node, symbol: Symbol, checker: Typ
653653

654654
// Search on the local symbol in the exporting module, not the exported symbol.
655655
importedSymbol = skipExportSpecifierSymbol(importedSymbol, checker);
656+
656657
// Similarly, skip past the symbol for 'export ='
657658
if (importedSymbol.escapedName === "export=") {
658659
importedSymbol = getExportEqualsLocalSymbol(importedSymbol, checker);
@@ -744,7 +745,7 @@ function skipExportSpecifierSymbol(symbol: Symbol, checker: TypeChecker): Symbol
744745
if (symbol.declarations) {
745746
for (const declaration of symbol.declarations) {
746747
if (isExportSpecifier(declaration) && !declaration.propertyName && !declaration.parent.parent.moduleSpecifier) {
747-
return checker.getExportSpecifierLocalTargetSymbol(declaration)!;
748+
return checker.getExportSpecifierLocalTargetSymbol(declaration) || symbol;
748749
}
749750
else if (isPropertyAccessExpression(declaration) && isModuleExportsAccessExpression(declaration.expression) && !isPrivateIdentifier(declaration.name)) {
750751
// Export of form 'module.exports.propName = expr';
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// === /bar.ts ===
2+
// import { [|Foo|]/*FIND ALL REFS*/ } from "./foo";
3+
4+
// === /foo.ts ===
5+
// export { [|Foo|] }
6+
7+
[
8+
{
9+
"definition": {
10+
"containerKind": "",
11+
"containerName": "",
12+
"fileName": "/bar.ts",
13+
"kind": "alias",
14+
"name": "import Foo",
15+
"textSpan": {
16+
"start": 9,
17+
"length": 3
18+
},
19+
"displayParts": [
20+
{
21+
"text": "import",
22+
"kind": "keyword"
23+
},
24+
{
25+
"text": " ",
26+
"kind": "space"
27+
},
28+
{
29+
"text": "Foo",
30+
"kind": "aliasName"
31+
}
32+
],
33+
"contextSpan": {
34+
"start": 0,
35+
"length": 28
36+
}
37+
},
38+
"references": [
39+
{
40+
"textSpan": {
41+
"start": 9,
42+
"length": 3
43+
},
44+
"fileName": "/bar.ts",
45+
"contextSpan": {
46+
"start": 0,
47+
"length": 28
48+
},
49+
"isWriteAccess": true,
50+
"isDefinition": true
51+
}
52+
]
53+
},
54+
{
55+
"definition": {
56+
"containerKind": "",
57+
"containerName": "",
58+
"fileName": "/foo.ts",
59+
"kind": "alias",
60+
"name": "export Foo",
61+
"textSpan": {
62+
"start": 9,
63+
"length": 3
64+
},
65+
"displayParts": [
66+
{
67+
"text": "export",
68+
"kind": "keyword"
69+
},
70+
{
71+
"text": " ",
72+
"kind": "space"
73+
},
74+
{
75+
"text": "Foo",
76+
"kind": "aliasName"
77+
}
78+
],
79+
"contextSpan": {
80+
"start": 0,
81+
"length": 14
82+
}
83+
},
84+
"references": [
85+
{
86+
"textSpan": {
87+
"start": 9,
88+
"length": 3
89+
},
90+
"fileName": "/foo.ts",
91+
"contextSpan": {
92+
"start": 0,
93+
"length": 14
94+
},
95+
"isWriteAccess": true,
96+
"isDefinition": false
97+
}
98+
]
99+
}
100+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /tsconfig.json
4+
//// { "compilerOptions": { "module": "commonjs" } }
5+
6+
// @filename: /bar.ts
7+
////import { Foo/**/ } from "./foo";
8+
9+
// @filename: /foo.ts
10+
////export { Foo }
11+
12+
verify.baselineFindAllReferences('');

0 commit comments

Comments
 (0)