Skip to content

Commit 50abee3

Browse files
author
Andy
authored
Never return undefined from getExportsOfModule (#17019)
1 parent 8b2fe13 commit 50abee3

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ namespace ts {
17701770

17711771
function getExportsOfModule(moduleSymbol: Symbol): SymbolTable {
17721772
const links = getSymbolLinks(moduleSymbol);
1773-
return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol));
1773+
return links.resolvedExports || (links.resolvedExports = getExportsOfModuleWorker(moduleSymbol));
17741774
}
17751775

17761776
interface ExportCollisionTracker {
@@ -1807,13 +1807,13 @@ namespace ts {
18071807
});
18081808
}
18091809

1810-
function getExportsForModule(moduleSymbol: Symbol): SymbolTable {
1810+
function getExportsOfModuleWorker(moduleSymbol: Symbol): SymbolTable {
18111811
const visitedSymbols: Symbol[] = [];
18121812

18131813
// A module defined by an 'export=' consists on one export that needs to be resolved
18141814
moduleSymbol = resolveExternalModuleSymbol(moduleSymbol);
18151815

1816-
return visit(moduleSymbol) || moduleSymbol.exports;
1816+
return visit(moduleSymbol) || emptySymbols;
18171817

18181818
// The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example,
18191819
// module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// This used to cause a crash because we would ask for exports on `"x"`,
4+
// which would return undefined and cause a NPE. Now we return emptySymbol instead.
5+
// See GH#16610.
6+
7+
////declare module "x" {
8+
//// declare var x: number;
9+
//// export = x;
10+
////}
11+
////
12+
////let y: /**/
13+
14+
goTo.marker();
15+
// This is just a dummy test to cause `getCompletionsAtPosition` to be called.
16+
verify.not.completionListContains("x");

0 commit comments

Comments
 (0)