Skip to content

Commit ba8e5a7

Browse files
author
Andy
authored
Never return undefined from getExportsOfModule (microsoft#17013)
1 parent d4c11bf commit ba8e5a7

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/compiler/checker.ts

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

17831783
function getExportsOfModule(moduleSymbol: Symbol): SymbolTable {
17841784
const links = getSymbolLinks(moduleSymbol);
1785-
return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol));
1785+
return links.resolvedExports || (links.resolvedExports = getExportsOfModuleWorker(moduleSymbol));
17861786
}
17871787

17881788
interface ExportCollisionTracker {
@@ -1821,13 +1821,13 @@ namespace ts {
18211821
});
18221822
}
18231823

1824-
function getExportsForModule(moduleSymbol: Symbol): SymbolTable {
1824+
function getExportsOfModuleWorker(moduleSymbol: Symbol): SymbolTable {
18251825
const visitedSymbols: Symbol[] = [];
18261826

18271827
// A module defined by an 'export=' consists on one export that needs to be resolved
18281828
moduleSymbol = resolveExternalModuleSymbol(moduleSymbol);
18291829

1830-
return visit(moduleSymbol) || moduleSymbol.exports;
1830+
return visit(moduleSymbol) || emptySymbols;
18311831

18321832
// The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example,
18331833
// 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)