Never return undefined from getExportsOfModule (#17019)

This commit is contained in:
Andy
2017-07-11 07:24:31 -07:00
committed by GitHub
parent 8b2fe136f8
commit 50abee3cd8
2 changed files with 19 additions and 3 deletions

View File

@@ -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 {
@@ -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.

View File

@@ -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");