@@ -365,21 +365,38 @@ namespace ts {
365365 case SyntaxKind.SourceFile:
366366 if (!isExternalModule(<SourceFile>location)) break;
367367 case SyntaxKind.ModuleDeclaration:
368- if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.ModuleMember)) {
369- if (result.flags & meaning || !(result.flags & SymbolFlags.Alias && getDeclarationOfAliasSymbol(result).kind === SyntaxKind.ExportSpecifier)) {
370- break loop;
371- }
372- result = undefined;
373- }
374- else if (location.kind === SyntaxKind.SourceFile ||
368+ let moduleExports = getSymbolOfNode(location).exports;
369+ if (location.kind === SyntaxKind.SourceFile ||
375370 (location.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>location).name.kind === SyntaxKind.StringLiteral)) {
376- result = getSymbolOfNode(location).exports["default"];
371+
372+ // It's an external module. Because of module/namespace merging, a module's exports are in scope,
373+ // yet we never want to treat an export specifier as putting a member in scope. Therefore,
374+ // if the name we find is purely an export specifier, it is not actually considered in scope.
375+ // Two things to note about this:
376+ // 1. We have to check this without calling getSymbol. The problem with calling getSymbol
377+ // on an export specifier is that it might find the export specifier itself, and try to
378+ // resolve it as an alias. This will cause the checker to consider the export specifier
379+ // a circular alias reference when it might not be.
380+ // 2. We check === SymbolFlags.Alias in order to check that the symbol is *purely*
381+ // an alias. If we used &, we'd be throwing out symbols that have non alias aspects,
382+ // which is not the desired behavior.
383+ if (hasProperty(moduleExports, name) &&
384+ moduleExports[name].flags === SymbolFlags.Alias &&
385+ getDeclarationOfKind(moduleExports[name], SyntaxKind.ExportSpecifier)) {
386+ break;
387+ }
388+
389+ result = moduleExports["default"];
377390 let localSymbol = getLocalSymbolForExportDefault(result);
378391 if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) {
379392 break loop;
380393 }
381394 result = undefined;
382395 }
396+
397+ if (result = getSymbol(moduleExports, name, meaning & SymbolFlags.ModuleMember)) {
398+ break loop;
399+ }
383400 break;
384401 case SyntaxKind.EnumDeclaration:
385402 if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.EnumMember)) {
0 commit comments