@@ -72,6 +72,7 @@ namespace ts {
7272 isUndefinedSymbol: symbol => symbol === undefinedSymbol,
7373 isArgumentsSymbol: symbol => symbol === argumentsSymbol,
7474 isUnknownSymbol: symbol => symbol === unknownSymbol,
75+ getMergedSymbol,
7576 getDiagnostics,
7677 getGlobalDiagnostics,
7778 getTypeOfSymbolAtLocation,
@@ -106,6 +107,7 @@ namespace ts {
106107 isValidPropertyAccess,
107108 getSignatureFromDeclaration,
108109 isImplementationOfOverload,
110+ getImmediateAliasedSymbol,
109111 getAliasedSymbol: resolveAlias,
110112 getEmitResolver,
111113 getExportsOfModule: getExportsOfModuleAsArray,
@@ -1161,14 +1163,14 @@ namespace ts {
11611163 return find<Declaration>(symbol.declarations, isAliasSymbolDeclaration);
11621164 }
11631165
1164- function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
1166+ function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration, dontResolveAlias: boolean ): Symbol {
11651167 if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) {
11661168 return resolveExternalModuleSymbol(resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)));
11671169 }
1168- return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference);
1170+ return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference, dontResolveAlias );
11691171 }
11701172
1171- function getTargetOfImportClause(node: ImportClause): Symbol {
1173+ function getTargetOfImportClause(node: ImportClause, dontResolveAlias: boolean ): Symbol {
11721174 const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
11731175
11741176 if (moduleSymbol) {
@@ -1180,22 +1182,22 @@ namespace ts {
11801182 const exportValue = moduleSymbol.exports.get("export=");
11811183 exportDefaultSymbol = exportValue
11821184 ? getPropertyOfType(getTypeOfSymbol(exportValue), "default")
1183- : resolveSymbol(moduleSymbol.exports.get("default"));
1185+ : resolveSymbol(moduleSymbol.exports.get("default"), dontResolveAlias );
11841186 }
11851187
11861188 if (!exportDefaultSymbol && !allowSyntheticDefaultImports) {
11871189 error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
11881190 }
11891191 else if (!exportDefaultSymbol && allowSyntheticDefaultImports) {
1190- return resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
1192+ return resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias ) || resolveSymbol(moduleSymbol, dontResolveAlias );
11911193 }
11921194 return exportDefaultSymbol;
11931195 }
11941196 }
11951197
1196- function getTargetOfNamespaceImport(node: NamespaceImport): Symbol {
1198+ function getTargetOfNamespaceImport(node: NamespaceImport, dontResolveAlias: boolean ): Symbol {
11971199 const moduleSpecifier = (<ImportDeclaration>node.parent.parent).moduleSpecifier;
1198- return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
1200+ return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias );
11991201 }
12001202
12011203 // This function creates a synthetic symbol that combines the value side of one symbol with the
@@ -1229,12 +1231,9 @@ namespace ts {
12291231 return result;
12301232 }
12311233
1232- function getExportOfModule(symbol: Symbol, name: string): Symbol {
1234+ function getExportOfModule(symbol: Symbol, name: string, dontResolveAlias: boolean ): Symbol {
12331235 if (symbol.flags & SymbolFlags.Module) {
1234- const exportedSymbol = getExportsOfSymbol(symbol).get(name);
1235- if (exportedSymbol) {
1236- return resolveSymbol(exportedSymbol);
1237- }
1236+ return resolveSymbol(getExportsOfSymbol(symbol).get(name), dontResolveAlias);
12381237 }
12391238 }
12401239
@@ -1247,9 +1246,9 @@ namespace ts {
12471246 }
12481247 }
12491248
1250- function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier): Symbol {
1249+ function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier, dontResolveAlias?: boolean ): Symbol {
12511250 const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
1252- const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
1251+ const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier, dontResolveAlias );
12531252 if (targetSymbol) {
12541253 const name = specifier.propertyName || specifier.name;
12551254 if (name.text) {
@@ -1266,11 +1265,11 @@ namespace ts {
12661265 symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text);
12671266 }
12681267 // if symbolFromVariable is export - get its final target
1269- symbolFromVariable = resolveSymbol(symbolFromVariable);
1270- let symbolFromModule = getExportOfModule(targetSymbol, name.text);
1268+ symbolFromVariable = resolveSymbol(symbolFromVariable, dontResolveAlias );
1269+ let symbolFromModule = getExportOfModule(targetSymbol, name.text, dontResolveAlias );
12711270 // If the export member we're looking for is default, and there is no real default but allowSyntheticDefaultImports is on, return the entire module as the default
12721271 if (!symbolFromModule && allowSyntheticDefaultImports && name.text === "default") {
1273- symbolFromModule = resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
1272+ symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias ) || resolveSymbol(moduleSymbol, dontResolveAlias );
12741273 }
12751274 const symbol = symbolFromModule && symbolFromVariable ?
12761275 combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
@@ -1283,45 +1282,58 @@ namespace ts {
12831282 }
12841283 }
12851284
1286- function getTargetOfImportSpecifier(node: ImportSpecifier): Symbol {
1287- return getExternalModuleMember(<ImportDeclaration>node.parent.parent.parent, node);
1285+ function getTargetOfImportSpecifier(node: ImportSpecifier, dontResolveAlias: boolean ): Symbol {
1286+ return getExternalModuleMember(<ImportDeclaration>node.parent.parent.parent, node, dontResolveAlias );
12881287 }
12891288
1290- function getTargetOfNamespaceExportDeclaration(node: NamespaceExportDeclaration): Symbol {
1291- return resolveExternalModuleSymbol(node.parent.symbol);
1289+ function getTargetOfNamespaceExportDeclaration(node: NamespaceExportDeclaration, dontResolveAlias: boolean ): Symbol {
1290+ return resolveExternalModuleSymbol(node.parent.symbol, dontResolveAlias );
12921291 }
12931292
1294- function getTargetOfExportSpecifier(node: ExportSpecifier): Symbol {
1293+ function getTargetOfExportSpecifier(node: ExportSpecifier, dontResolveAlias?: boolean ): Symbol {
12951294 return (<ExportDeclaration>node.parent.parent).moduleSpecifier ?
1296- getExternalModuleMember(<ExportDeclaration>node.parent.parent, node) :
1297- resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
1295+ getExternalModuleMember(<ExportDeclaration>node.parent.parent, node, dontResolveAlias ) :
1296+ resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/false, dontResolveAlias );
12981297 }
12991298
1300- function getTargetOfExportAssignment(node: ExportAssignment): Symbol {
1301- return resolveEntityName(<EntityNameExpression>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
1299+ function getTargetOfExportAssignment(node: ExportAssignment, dontResolveAlias: boolean ): Symbol {
1300+ return resolveEntityName(<EntityNameExpression>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/false, dontResolveAlias );
13021301 }
13031302
1304- function getTargetOfAliasDeclaration(node: Declaration): Symbol {
1303+ function getTargetOfAliasDeclaration(node: Declaration, dontRecursivelyResolve?: boolean ): Symbol {
13051304 switch (node.kind) {
13061305 case SyntaxKind.ImportEqualsDeclaration:
1307- return getTargetOfImportEqualsDeclaration(<ImportEqualsDeclaration>node);
1306+ return getTargetOfImportEqualsDeclaration(<ImportEqualsDeclaration>node, dontRecursivelyResolve );
13081307 case SyntaxKind.ImportClause:
1309- return getTargetOfImportClause(<ImportClause>node);
1308+ return getTargetOfImportClause(<ImportClause>node, dontRecursivelyResolve );
13101309 case SyntaxKind.NamespaceImport:
1311- return getTargetOfNamespaceImport(<NamespaceImport>node);
1310+ return getTargetOfNamespaceImport(<NamespaceImport>node, dontRecursivelyResolve );
13121311 case SyntaxKind.ImportSpecifier:
1313- return getTargetOfImportSpecifier(<ImportSpecifier>node);
1312+ return getTargetOfImportSpecifier(<ImportSpecifier>node, dontRecursivelyResolve );
13141313 case SyntaxKind.ExportSpecifier:
1315- return getTargetOfExportSpecifier(<ExportSpecifier>node);
1314+ return getTargetOfExportSpecifier(<ExportSpecifier>node, dontRecursivelyResolve );
13161315 case SyntaxKind.ExportAssignment:
1317- return getTargetOfExportAssignment(<ExportAssignment>node);
1316+ return getTargetOfExportAssignment(<ExportAssignment>node, dontRecursivelyResolve );
13181317 case SyntaxKind.NamespaceExportDeclaration:
1319- return getTargetOfNamespaceExportDeclaration(<NamespaceExportDeclaration>node);
1318+ return getTargetOfNamespaceExportDeclaration(<NamespaceExportDeclaration>node, dontRecursivelyResolve );
13201319 }
13211320 }
13221321
1323- function resolveSymbol(symbol: Symbol): Symbol {
1324- return symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace)) ? resolveAlias(symbol) : symbol;
1322+ function resolveSymbol(symbol: Symbol, dontResolveAlias?: boolean): Symbol {
1323+ const shouldResolve = !dontResolveAlias && symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace));
1324+ return shouldResolve ? resolveAlias(symbol) : symbol;
1325+ }
1326+
1327+ function getImmediateAliasedSymbol(symbol: Symbol): Symbol {
1328+ Debug.assert((symbol.flags & SymbolFlags.Alias) !== 0, "Should only get Alias here.");
1329+ const links = getSymbolLinks(symbol);
1330+ if (!links.immediateTarget) {
1331+ const node = getDeclarationOfAliasSymbol(symbol);
1332+ Debug.assert(!!node);
1333+ links.immediateTarget = getTargetOfAliasDeclaration(node, /*dontRecursivelyResolve*/true);
1334+ }
1335+
1336+ return links.immediateTarget;
13251337 }
13261338
13271339 function resolveAlias(symbol: Symbol): Symbol {
@@ -1538,16 +1550,16 @@ namespace ts {
15381550
15391551 // An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
15401552 // and an external module with no 'export =' declaration resolves to the module itself.
1541- function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol {
1542- return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports.get("export="))) || moduleSymbol;
1553+ function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean ): Symbol {
1554+ return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports.get("export="), dontResolveAlias )) || moduleSymbol;
15431555 }
15441556
15451557 // An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export ='
15461558 // references a symbol that is at least declared as a module or a variable. The target of the 'export =' may
15471559 // combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable).
1548- function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression): Symbol {
1549- let symbol = resolveExternalModuleSymbol(moduleSymbol);
1550- if (symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
1560+ function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression, dontResolveAlias: boolean ): Symbol {
1561+ let symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias );
1562+ if (!dontResolveAlias && symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
15511563 error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
15521564 symbol = undefined;
15531565 }
0 commit comments