Skip to content

Commit

Permalink
Never return undefined from getExportsOfModule (#17019)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy committed Jul 11, 2017
1 parent 8b2fe13 commit 50abee3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ namespace ts {

function getExportsOfModule(moduleSymbol: Symbol): SymbolTable {
const links = getSymbolLinks(moduleSymbol);
return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol));
return links.resolvedExports || (links.resolvedExports = getExportsOfModuleWorker(moduleSymbol));
}

interface ExportCollisionTracker {
Expand Down Expand Up @@ -1807,13 +1807,13 @@ namespace ts {
});
}

function getExportsForModule(moduleSymbol: Symbol): SymbolTable {
function getExportsOfModuleWorker(moduleSymbol: Symbol): SymbolTable {
const visitedSymbols: Symbol[] = [];

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

return visit(moduleSymbol) || moduleSymbol.exports;
return visit(moduleSymbol) || emptySymbols;

// The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example,
// module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error.
Expand Down
16 changes: 16 additions & 0 deletions tests/cases/fourslash/completionList_getExportsOfModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path='fourslash.ts'/>

// This used to cause a crash because we would ask for exports on `"x"`,
// which would return undefined and cause a NPE. Now we return emptySymbol instead.
// See GH#16610.

////declare module "x" {
//// declare var x: number;
//// export = x;
////}
////
////let y: /**/

goTo.marker();
// This is just a dummy test to cause `getCompletionsAtPosition` to be called.
verify.not.completionListContains("x");

0 comments on commit 50abee3

Please sign in to comment.