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