@@ -72,6 +72,7 @@ namespace ts {
72
72
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
73
73
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
74
74
isUnknownSymbol: symbol => symbol === unknownSymbol,
75
+ getMergedSymbol,
75
76
getDiagnostics,
76
77
getGlobalDiagnostics,
77
78
getTypeOfSymbolAtLocation,
@@ -106,6 +107,7 @@ namespace ts {
106
107
isValidPropertyAccess,
107
108
getSignatureFromDeclaration,
108
109
isImplementationOfOverload,
110
+ getImmediateAliasedSymbol,
109
111
getAliasedSymbol: resolveAlias,
110
112
getEmitResolver,
111
113
getExportsOfModule: getExportsOfModuleAsArray,
@@ -1161,14 +1163,14 @@ namespace ts {
1161
1163
return find<Declaration>(symbol.declarations, isAliasSymbolDeclaration);
1162
1164
}
1163
1165
1164
- function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
1166
+ function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration, dontResolveAlias: boolean ): Symbol {
1165
1167
if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) {
1166
1168
return resolveExternalModuleSymbol(resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)));
1167
1169
}
1168
- return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference);
1170
+ return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference, dontResolveAlias );
1169
1171
}
1170
1172
1171
- function getTargetOfImportClause(node: ImportClause): Symbol {
1173
+ function getTargetOfImportClause(node: ImportClause, dontResolveAlias: boolean ): Symbol {
1172
1174
const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
1173
1175
1174
1176
if (moduleSymbol) {
@@ -1180,22 +1182,22 @@ namespace ts {
1180
1182
const exportValue = moduleSymbol.exports.get("export=");
1181
1183
exportDefaultSymbol = exportValue
1182
1184
? getPropertyOfType(getTypeOfSymbol(exportValue), "default")
1183
- : resolveSymbol(moduleSymbol.exports.get("default"));
1185
+ : resolveSymbol(moduleSymbol.exports.get("default"), dontResolveAlias );
1184
1186
}
1185
1187
1186
1188
if (!exportDefaultSymbol && !allowSyntheticDefaultImports) {
1187
1189
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
1188
1190
}
1189
1191
else if (!exportDefaultSymbol && allowSyntheticDefaultImports) {
1190
- return resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
1192
+ return resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias ) || resolveSymbol(moduleSymbol, dontResolveAlias );
1191
1193
}
1192
1194
return exportDefaultSymbol;
1193
1195
}
1194
1196
}
1195
1197
1196
- function getTargetOfNamespaceImport(node: NamespaceImport): Symbol {
1198
+ function getTargetOfNamespaceImport(node: NamespaceImport, dontResolveAlias: boolean ): Symbol {
1197
1199
const moduleSpecifier = (<ImportDeclaration>node.parent.parent).moduleSpecifier;
1198
- return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
1200
+ return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias );
1199
1201
}
1200
1202
1201
1203
// This function creates a synthetic symbol that combines the value side of one symbol with the
@@ -1229,12 +1231,9 @@ namespace ts {
1229
1231
return result;
1230
1232
}
1231
1233
1232
- function getExportOfModule(symbol: Symbol, name: string): Symbol {
1234
+ function getExportOfModule(symbol: Symbol, name: string, dontResolveAlias: boolean ): Symbol {
1233
1235
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);
1238
1237
}
1239
1238
}
1240
1239
@@ -1247,9 +1246,9 @@ namespace ts {
1247
1246
}
1248
1247
}
1249
1248
1250
- function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier): Symbol {
1249
+ function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier, dontResolveAlias?: boolean ): Symbol {
1251
1250
const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
1252
- const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
1251
+ const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier, dontResolveAlias );
1253
1252
if (targetSymbol) {
1254
1253
const name = specifier.propertyName || specifier.name;
1255
1254
if (name.text) {
@@ -1266,11 +1265,11 @@ namespace ts {
1266
1265
symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text);
1267
1266
}
1268
1267
// 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 );
1271
1270
// 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
1272
1271
if (!symbolFromModule && allowSyntheticDefaultImports && name.text === "default") {
1273
- symbolFromModule = resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
1272
+ symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias ) || resolveSymbol(moduleSymbol, dontResolveAlias );
1274
1273
}
1275
1274
const symbol = symbolFromModule && symbolFromVariable ?
1276
1275
combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
@@ -1283,45 +1282,58 @@ namespace ts {
1283
1282
}
1284
1283
}
1285
1284
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 );
1288
1287
}
1289
1288
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 );
1292
1291
}
1293
1292
1294
- function getTargetOfExportSpecifier(node: ExportSpecifier): Symbol {
1293
+ function getTargetOfExportSpecifier(node: ExportSpecifier, dontResolveAlias?: boolean ): Symbol {
1295
1294
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 );
1298
1297
}
1299
1298
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 );
1302
1301
}
1303
1302
1304
- function getTargetOfAliasDeclaration(node: Declaration): Symbol {
1303
+ function getTargetOfAliasDeclaration(node: Declaration, dontRecursivelyResolve?: boolean ): Symbol {
1305
1304
switch (node.kind) {
1306
1305
case SyntaxKind.ImportEqualsDeclaration:
1307
- return getTargetOfImportEqualsDeclaration(<ImportEqualsDeclaration>node);
1306
+ return getTargetOfImportEqualsDeclaration(<ImportEqualsDeclaration>node, dontRecursivelyResolve );
1308
1307
case SyntaxKind.ImportClause:
1309
- return getTargetOfImportClause(<ImportClause>node);
1308
+ return getTargetOfImportClause(<ImportClause>node, dontRecursivelyResolve );
1310
1309
case SyntaxKind.NamespaceImport:
1311
- return getTargetOfNamespaceImport(<NamespaceImport>node);
1310
+ return getTargetOfNamespaceImport(<NamespaceImport>node, dontRecursivelyResolve );
1312
1311
case SyntaxKind.ImportSpecifier:
1313
- return getTargetOfImportSpecifier(<ImportSpecifier>node);
1312
+ return getTargetOfImportSpecifier(<ImportSpecifier>node, dontRecursivelyResolve );
1314
1313
case SyntaxKind.ExportSpecifier:
1315
- return getTargetOfExportSpecifier(<ExportSpecifier>node);
1314
+ return getTargetOfExportSpecifier(<ExportSpecifier>node, dontRecursivelyResolve );
1316
1315
case SyntaxKind.ExportAssignment:
1317
- return getTargetOfExportAssignment(<ExportAssignment>node);
1316
+ return getTargetOfExportAssignment(<ExportAssignment>node, dontRecursivelyResolve );
1318
1317
case SyntaxKind.NamespaceExportDeclaration:
1319
- return getTargetOfNamespaceExportDeclaration(<NamespaceExportDeclaration>node);
1318
+ return getTargetOfNamespaceExportDeclaration(<NamespaceExportDeclaration>node, dontRecursivelyResolve );
1320
1319
}
1321
1320
}
1322
1321
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;
1325
1337
}
1326
1338
1327
1339
function resolveAlias(symbol: Symbol): Symbol {
@@ -1538,16 +1550,16 @@ namespace ts {
1538
1550
1539
1551
// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
1540
1552
// 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;
1543
1555
}
1544
1556
1545
1557
// An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export ='
1546
1558
// references a symbol that is at least declared as a module or a variable. The target of the 'export =' may
1547
1559
// 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))) {
1551
1563
error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
1552
1564
symbol = undefined;
1553
1565
}
0 commit comments