@@ -344,21 +344,38 @@ module ts {
344
344
case SyntaxKind.SourceFile:
345
345
if (!isExternalModule(<SourceFile>location)) break;
346
346
case SyntaxKind.ModuleDeclaration:
347
- if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.ModuleMember)) {
348
- if (result.flags & meaning || !(result.flags & SymbolFlags.Alias && getDeclarationOfAliasSymbol(result).kind === SyntaxKind.ExportSpecifier)) {
349
- break loop;
350
- }
351
- result = undefined;
352
- }
353
- else if (location.kind === SyntaxKind.SourceFile ||
347
+ let moduleExports = getSymbolOfNode(location).exports;
348
+ if (location.kind === SyntaxKind.SourceFile ||
354
349
(location.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>location).name.kind === SyntaxKind.StringLiteral)) {
355
- result = getSymbolOfNode(location).exports["default"];
350
+
351
+ // It's an external module. Because of module/namespace merging, a module's exports are in scope,
352
+ // yet we never want to treat an export specifier as putting a member in scope. Therefore,
353
+ // if the name we find is purely an export specifier, it is not actually considered in scope.
354
+ // Two things to note about this:
355
+ // 1. We have to check this without calling getSymbol. The problem with calling getSymbol
356
+ // on an export specifier is that it might find the export specifier itself, and try to
357
+ // resolve it as an alias. This will cause the checker to consider the export specifier
358
+ // a circular alias reference when it might not be.
359
+ // 2. We check === SymbolFlags.Alias in order to check that the symbol is *purely*
360
+ // an alias. If we used &, we'd be throwing out symbols that have non alias aspects,
361
+ // which is not the desired behavior.
362
+ if (hasProperty(moduleExports, name) &&
363
+ moduleExports[name].flags === SymbolFlags.Alias &&
364
+ getDeclarationOfKind(moduleExports[name], SyntaxKind.ExportSpecifier)) {
365
+ break;
366
+ }
367
+
368
+ result = moduleExports["default"];
356
369
let localSymbol = getLocalSymbolForExportDefault(result);
357
370
if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) {
358
371
break loop;
359
372
}
360
373
result = undefined;
361
374
}
375
+
376
+ if (result = getSymbol(moduleExports, name, meaning & SymbolFlags.ModuleMember)) {
377
+ break loop;
378
+ }
362
379
break;
363
380
case SyntaxKind.EnumDeclaration:
364
381
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.EnumMember)) {
0 commit comments