@@ -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,
@@ -1140,14 +1142,14 @@ namespace ts {
1140
1142
return find<Declaration>(symbol.declarations, isAliasSymbolDeclaration);
1141
1143
}
1142
1144
1143
- function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
1145
+ function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration, dontResolveAlias: boolean ): Symbol {
1144
1146
if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) {
1145
1147
return resolveExternalModuleSymbol(resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)));
1146
1148
}
1147
- return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference);
1149
+ return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference, dontResolveAlias );
1148
1150
}
1149
1151
1150
- function getTargetOfImportClause(node: ImportClause): Symbol {
1152
+ function getTargetOfImportClause(node: ImportClause, dontResolveAlias: boolean ): Symbol {
1151
1153
const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
1152
1154
1153
1155
if (moduleSymbol) {
@@ -1159,22 +1161,22 @@ namespace ts {
1159
1161
const exportValue = moduleSymbol.exports.get("export=");
1160
1162
exportDefaultSymbol = exportValue
1161
1163
? getPropertyOfType(getTypeOfSymbol(exportValue), "default")
1162
- : resolveSymbol(moduleSymbol.exports.get("default"));
1164
+ : resolveSymbol(moduleSymbol.exports.get("default"), dontResolveAlias );
1163
1165
}
1164
1166
1165
1167
if (!exportDefaultSymbol && !allowSyntheticDefaultImports) {
1166
1168
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
1167
1169
}
1168
1170
else if (!exportDefaultSymbol && allowSyntheticDefaultImports) {
1169
- return resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
1171
+ return resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias ) || resolveSymbol(moduleSymbol, dontResolveAlias );
1170
1172
}
1171
1173
return exportDefaultSymbol;
1172
1174
}
1173
1175
}
1174
1176
1175
- function getTargetOfNamespaceImport(node: NamespaceImport): Symbol {
1177
+ function getTargetOfNamespaceImport(node: NamespaceImport, dontResolveAlias: boolean ): Symbol {
1176
1178
const moduleSpecifier = (<ImportDeclaration>node.parent.parent).moduleSpecifier;
1177
- return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
1179
+ return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias );
1178
1180
}
1179
1181
1180
1182
// This function creates a synthetic symbol that combines the value side of one symbol with the
@@ -1208,12 +1210,9 @@ namespace ts {
1208
1210
return result;
1209
1211
}
1210
1212
1211
- function getExportOfModule(symbol: Symbol, name: string): Symbol {
1213
+ function getExportOfModule(symbol: Symbol, name: string, dontResolveAlias: boolean ): Symbol {
1212
1214
if (symbol.flags & SymbolFlags.Module) {
1213
- const exportedSymbol = getExportsOfSymbol(symbol).get(name);
1214
- if (exportedSymbol) {
1215
- return resolveSymbol(exportedSymbol);
1216
- }
1215
+ return resolveSymbol(getExportsOfSymbol(symbol).get(name), dontResolveAlias);
1217
1216
}
1218
1217
}
1219
1218
@@ -1226,9 +1225,9 @@ namespace ts {
1226
1225
}
1227
1226
}
1228
1227
1229
- function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier): Symbol {
1228
+ function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier, dontResolveAlias?: boolean ): Symbol {
1230
1229
const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
1231
- const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
1230
+ const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier, dontResolveAlias );
1232
1231
if (targetSymbol) {
1233
1232
const name = specifier.propertyName || specifier.name;
1234
1233
if (name.text) {
@@ -1245,11 +1244,11 @@ namespace ts {
1245
1244
symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text);
1246
1245
}
1247
1246
// if symbolFromVariable is export - get its final target
1248
- symbolFromVariable = resolveSymbol(symbolFromVariable);
1249
- let symbolFromModule = getExportOfModule(targetSymbol, name.text);
1247
+ symbolFromVariable = resolveSymbol(symbolFromVariable, dontResolveAlias );
1248
+ let symbolFromModule = getExportOfModule(targetSymbol, name.text, dontResolveAlias );
1250
1249
// 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
1251
1250
if (!symbolFromModule && allowSyntheticDefaultImports && name.text === "default") {
1252
- symbolFromModule = resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
1251
+ symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias ) || resolveSymbol(moduleSymbol, dontResolveAlias );
1253
1252
}
1254
1253
const symbol = symbolFromModule && symbolFromVariable ?
1255
1254
combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
@@ -1262,45 +1261,58 @@ namespace ts {
1262
1261
}
1263
1262
}
1264
1263
1265
- function getTargetOfImportSpecifier(node: ImportSpecifier): Symbol {
1266
- return getExternalModuleMember(<ImportDeclaration>node.parent.parent.parent, node);
1264
+ function getTargetOfImportSpecifier(node: ImportSpecifier, dontResolveAlias: boolean ): Symbol {
1265
+ return getExternalModuleMember(<ImportDeclaration>node.parent.parent.parent, node, dontResolveAlias );
1267
1266
}
1268
1267
1269
- function getTargetOfNamespaceExportDeclaration(node: NamespaceExportDeclaration): Symbol {
1270
- return resolveExternalModuleSymbol(node.parent.symbol);
1268
+ function getTargetOfNamespaceExportDeclaration(node: NamespaceExportDeclaration, dontResolveAlias: boolean ): Symbol {
1269
+ return resolveExternalModuleSymbol(node.parent.symbol, dontResolveAlias );
1271
1270
}
1272
1271
1273
- function getTargetOfExportSpecifier(node: ExportSpecifier): Symbol {
1272
+ function getTargetOfExportSpecifier(node: ExportSpecifier, dontResolveAlias?: boolean ): Symbol {
1274
1273
return (<ExportDeclaration>node.parent.parent).moduleSpecifier ?
1275
- getExternalModuleMember(<ExportDeclaration>node.parent.parent, node) :
1276
- resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
1274
+ getExternalModuleMember(<ExportDeclaration>node.parent.parent, node, dontResolveAlias ) :
1275
+ resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/false, dontResolveAlias );
1277
1276
}
1278
1277
1279
- function getTargetOfExportAssignment(node: ExportAssignment): Symbol {
1280
- return resolveEntityName(<EntityNameExpression>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
1278
+ function getTargetOfExportAssignment(node: ExportAssignment, dontResolveAlias: boolean ): Symbol {
1279
+ return resolveEntityName(<EntityNameExpression>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/false, dontResolveAlias );
1281
1280
}
1282
1281
1283
- function getTargetOfAliasDeclaration(node: Declaration): Symbol {
1282
+ function getTargetOfAliasDeclaration(node: Declaration, dontRecursivelyResolve?: boolean ): Symbol {
1284
1283
switch (node.kind) {
1285
1284
case SyntaxKind.ImportEqualsDeclaration:
1286
- return getTargetOfImportEqualsDeclaration(<ImportEqualsDeclaration>node);
1285
+ return getTargetOfImportEqualsDeclaration(<ImportEqualsDeclaration>node, dontRecursivelyResolve );
1287
1286
case SyntaxKind.ImportClause:
1288
- return getTargetOfImportClause(<ImportClause>node);
1287
+ return getTargetOfImportClause(<ImportClause>node, dontRecursivelyResolve );
1289
1288
case SyntaxKind.NamespaceImport:
1290
- return getTargetOfNamespaceImport(<NamespaceImport>node);
1289
+ return getTargetOfNamespaceImport(<NamespaceImport>node, dontRecursivelyResolve );
1291
1290
case SyntaxKind.ImportSpecifier:
1292
- return getTargetOfImportSpecifier(<ImportSpecifier>node);
1291
+ return getTargetOfImportSpecifier(<ImportSpecifier>node, dontRecursivelyResolve );
1293
1292
case SyntaxKind.ExportSpecifier:
1294
- return getTargetOfExportSpecifier(<ExportSpecifier>node);
1293
+ return getTargetOfExportSpecifier(<ExportSpecifier>node, dontRecursivelyResolve );
1295
1294
case SyntaxKind.ExportAssignment:
1296
- return getTargetOfExportAssignment(<ExportAssignment>node);
1295
+ return getTargetOfExportAssignment(<ExportAssignment>node, dontRecursivelyResolve );
1297
1296
case SyntaxKind.NamespaceExportDeclaration:
1298
- return getTargetOfNamespaceExportDeclaration(<NamespaceExportDeclaration>node);
1297
+ return getTargetOfNamespaceExportDeclaration(<NamespaceExportDeclaration>node, dontRecursivelyResolve );
1299
1298
}
1300
1299
}
1301
1300
1302
- function resolveSymbol(symbol: Symbol): Symbol {
1303
- return symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace)) ? resolveAlias(symbol) : symbol;
1301
+ function resolveSymbol(symbol: Symbol, dontResolveAlias?: boolean): Symbol {
1302
+ const shouldResolve = !dontResolveAlias && symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace));
1303
+ return shouldResolve ? resolveAlias(symbol) : symbol;
1304
+ }
1305
+
1306
+ function getImmediateAliasedSymbol(symbol: Symbol): Symbol {
1307
+ Debug.assert((symbol.flags & SymbolFlags.Alias) !== 0, "Should only get Alias here.");
1308
+ const links = getSymbolLinks(symbol);
1309
+ if (!links.immediateTarget) {
1310
+ const node = getDeclarationOfAliasSymbol(symbol);
1311
+ Debug.assert(!!node);
1312
+ links.immediateTarget = getTargetOfAliasDeclaration(node, /*dontRecursivelyResolve*/true);
1313
+ }
1314
+
1315
+ return links.immediateTarget;
1304
1316
}
1305
1317
1306
1318
function resolveAlias(symbol: Symbol): Symbol {
@@ -1517,16 +1529,16 @@ namespace ts {
1517
1529
1518
1530
// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
1519
1531
// and an external module with no 'export =' declaration resolves to the module itself.
1520
- function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol {
1521
- return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports.get("export="))) || moduleSymbol;
1532
+ function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean ): Symbol {
1533
+ return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports.get("export="), dontResolveAlias )) || moduleSymbol;
1522
1534
}
1523
1535
1524
1536
// An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export ='
1525
1537
// references a symbol that is at least declared as a module or a variable. The target of the 'export =' may
1526
1538
// combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable).
1527
- function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression): Symbol {
1528
- let symbol = resolveExternalModuleSymbol(moduleSymbol);
1529
- if (symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
1539
+ function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression, dontResolveAlias: boolean ): Symbol {
1540
+ let symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias );
1541
+ if (!dontResolveAlias && symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
1530
1542
error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
1531
1543
symbol = undefined;
1532
1544
}
0 commit comments