@@ -81,6 +81,7 @@ namespace ts {
81
81
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
82
82
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
83
83
isUnknownSymbol: symbol => symbol === unknownSymbol,
84
+ getMergedSymbol,
84
85
getDiagnostics,
85
86
getGlobalDiagnostics,
86
87
getTypeOfSymbolAtLocation: (symbol, location) => {
@@ -172,6 +173,17 @@ namespace ts {
172
173
node = getParseTreeNode(node, isFunctionLike);
173
174
return node ? isImplementationOfOverload(node) : undefined;
174
175
},
176
+ getImmediateAliasedSymbol: symbol => {
177
+ Debug.assert((symbol.flags & SymbolFlags.Alias) !== 0, "Should only get Alias here.");
178
+ const links = getSymbolLinks(symbol);
179
+ if (!links.immediateTarget) {
180
+ const node = getDeclarationOfAliasSymbol(symbol);
181
+ Debug.assert(!!node);
182
+ links.immediateTarget = getTargetOfAliasDeclaration(node, /*dontRecursivelyResolve*/ true);
183
+ }
184
+
185
+ return links.immediateTarget;
186
+ },
175
187
getAliasedSymbol: resolveAlias,
176
188
getEmitResolver,
177
189
getExportsOfModule: getExportsOfModuleAsArray,
@@ -1272,14 +1284,14 @@ namespace ts {
1272
1284
return find<Declaration>(symbol.declarations, isAliasSymbolDeclaration);
1273
1285
}
1274
1286
1275
- function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
1287
+ function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration, dontResolveAlias: boolean ): Symbol {
1276
1288
if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) {
1277
1289
return resolveExternalModuleSymbol(resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)));
1278
1290
}
1279
- return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference);
1291
+ return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference, dontResolveAlias );
1280
1292
}
1281
1293
1282
- function getTargetOfImportClause(node: ImportClause): Symbol {
1294
+ function getTargetOfImportClause(node: ImportClause, dontResolveAlias: boolean ): Symbol {
1283
1295
const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
1284
1296
1285
1297
if (moduleSymbol) {
@@ -1291,22 +1303,22 @@ namespace ts {
1291
1303
const exportValue = moduleSymbol.exports.get("export=");
1292
1304
exportDefaultSymbol = exportValue
1293
1305
? getPropertyOfType(getTypeOfSymbol(exportValue), "default")
1294
- : resolveSymbol(moduleSymbol.exports.get("default"));
1306
+ : resolveSymbol(moduleSymbol.exports.get("default"), dontResolveAlias );
1295
1307
}
1296
1308
1297
1309
if (!exportDefaultSymbol && !allowSyntheticDefaultImports) {
1298
1310
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
1299
1311
}
1300
1312
else if (!exportDefaultSymbol && allowSyntheticDefaultImports) {
1301
- return resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
1313
+ return resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias ) || resolveSymbol(moduleSymbol, dontResolveAlias );
1302
1314
}
1303
1315
return exportDefaultSymbol;
1304
1316
}
1305
1317
}
1306
1318
1307
- function getTargetOfNamespaceImport(node: NamespaceImport): Symbol {
1319
+ function getTargetOfNamespaceImport(node: NamespaceImport, dontResolveAlias: boolean ): Symbol {
1308
1320
const moduleSpecifier = (<ImportDeclaration>node.parent.parent).moduleSpecifier;
1309
- return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
1321
+ return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias );
1310
1322
}
1311
1323
1312
1324
// This function creates a synthetic symbol that combines the value side of one symbol with the
@@ -1340,12 +1352,9 @@ namespace ts {
1340
1352
return result;
1341
1353
}
1342
1354
1343
- function getExportOfModule(symbol: Symbol, name: string): Symbol {
1355
+ function getExportOfModule(symbol: Symbol, name: string, dontResolveAlias: boolean ): Symbol {
1344
1356
if (symbol.flags & SymbolFlags.Module) {
1345
- const exportedSymbol = getExportsOfSymbol(symbol).get(name);
1346
- if (exportedSymbol) {
1347
- return resolveSymbol(exportedSymbol);
1348
- }
1357
+ return resolveSymbol(getExportsOfSymbol(symbol).get(name), dontResolveAlias);
1349
1358
}
1350
1359
}
1351
1360
@@ -1358,9 +1367,9 @@ namespace ts {
1358
1367
}
1359
1368
}
1360
1369
1361
- function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier): Symbol {
1370
+ function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier, dontResolveAlias?: boolean ): Symbol {
1362
1371
const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
1363
- const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
1372
+ const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier, dontResolveAlias );
1364
1373
if (targetSymbol) {
1365
1374
const name = specifier.propertyName || specifier.name;
1366
1375
if (name.text) {
@@ -1377,11 +1386,11 @@ namespace ts {
1377
1386
symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text);
1378
1387
}
1379
1388
// if symbolFromVariable is export - get its final target
1380
- symbolFromVariable = resolveSymbol(symbolFromVariable);
1381
- let symbolFromModule = getExportOfModule(targetSymbol, name.text);
1389
+ symbolFromVariable = resolveSymbol(symbolFromVariable, dontResolveAlias );
1390
+ let symbolFromModule = getExportOfModule(targetSymbol, name.text, dontResolveAlias );
1382
1391
// 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
1383
1392
if (!symbolFromModule && allowSyntheticDefaultImports && name.text === "default") {
1384
- symbolFromModule = resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
1393
+ symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias ) || resolveSymbol(moduleSymbol, dontResolveAlias );
1385
1394
}
1386
1395
const symbol = symbolFromModule && symbolFromVariable ?
1387
1396
combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
@@ -1394,45 +1403,46 @@ namespace ts {
1394
1403
}
1395
1404
}
1396
1405
1397
- function getTargetOfImportSpecifier(node: ImportSpecifier): Symbol {
1398
- return getExternalModuleMember(<ImportDeclaration>node.parent.parent.parent, node);
1406
+ function getTargetOfImportSpecifier(node: ImportSpecifier, dontResolveAlias: boolean ): Symbol {
1407
+ return getExternalModuleMember(<ImportDeclaration>node.parent.parent.parent, node, dontResolveAlias );
1399
1408
}
1400
1409
1401
- function getTargetOfNamespaceExportDeclaration(node: NamespaceExportDeclaration): Symbol {
1402
- return resolveExternalModuleSymbol(node.parent.symbol);
1410
+ function getTargetOfNamespaceExportDeclaration(node: NamespaceExportDeclaration, dontResolveAlias: boolean ): Symbol {
1411
+ return resolveExternalModuleSymbol(node.parent.symbol, dontResolveAlias );
1403
1412
}
1404
1413
1405
- function getTargetOfExportSpecifier(node: ExportSpecifier): Symbol {
1414
+ function getTargetOfExportSpecifier(node: ExportSpecifier, dontResolveAlias?: boolean ): Symbol {
1406
1415
return (<ExportDeclaration>node.parent.parent).moduleSpecifier ?
1407
- getExternalModuleMember(<ExportDeclaration>node.parent.parent, node) :
1408
- resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
1416
+ getExternalModuleMember(<ExportDeclaration>node.parent.parent, node, dontResolveAlias ) :
1417
+ resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ false, dontResolveAlias );
1409
1418
}
1410
1419
1411
- function getTargetOfExportAssignment(node: ExportAssignment): Symbol {
1412
- return resolveEntityName(<EntityNameExpression>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
1420
+ function getTargetOfExportAssignment(node: ExportAssignment, dontResolveAlias: boolean ): Symbol {
1421
+ return resolveEntityName(<EntityNameExpression>node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ false, dontResolveAlias );
1413
1422
}
1414
1423
1415
- function getTargetOfAliasDeclaration(node: Declaration): Symbol {
1424
+ function getTargetOfAliasDeclaration(node: Declaration, dontRecursivelyResolve?: boolean ): Symbol {
1416
1425
switch (node.kind) {
1417
1426
case SyntaxKind.ImportEqualsDeclaration:
1418
- return getTargetOfImportEqualsDeclaration(<ImportEqualsDeclaration>node);
1427
+ return getTargetOfImportEqualsDeclaration(<ImportEqualsDeclaration>node, dontRecursivelyResolve );
1419
1428
case SyntaxKind.ImportClause:
1420
- return getTargetOfImportClause(<ImportClause>node);
1429
+ return getTargetOfImportClause(<ImportClause>node, dontRecursivelyResolve );
1421
1430
case SyntaxKind.NamespaceImport:
1422
- return getTargetOfNamespaceImport(<NamespaceImport>node);
1431
+ return getTargetOfNamespaceImport(<NamespaceImport>node, dontRecursivelyResolve );
1423
1432
case SyntaxKind.ImportSpecifier:
1424
- return getTargetOfImportSpecifier(<ImportSpecifier>node);
1433
+ return getTargetOfImportSpecifier(<ImportSpecifier>node, dontRecursivelyResolve );
1425
1434
case SyntaxKind.ExportSpecifier:
1426
- return getTargetOfExportSpecifier(<ExportSpecifier>node);
1435
+ return getTargetOfExportSpecifier(<ExportSpecifier>node, dontRecursivelyResolve );
1427
1436
case SyntaxKind.ExportAssignment:
1428
- return getTargetOfExportAssignment(<ExportAssignment>node);
1437
+ return getTargetOfExportAssignment(<ExportAssignment>node, dontRecursivelyResolve );
1429
1438
case SyntaxKind.NamespaceExportDeclaration:
1430
- return getTargetOfNamespaceExportDeclaration(<NamespaceExportDeclaration>node);
1439
+ return getTargetOfNamespaceExportDeclaration(<NamespaceExportDeclaration>node, dontRecursivelyResolve );
1431
1440
}
1432
1441
}
1433
1442
1434
- function resolveSymbol(symbol: Symbol): Symbol {
1435
- return symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace)) ? resolveAlias(symbol) : symbol;
1443
+ function resolveSymbol(symbol: Symbol, dontResolveAlias?: boolean): Symbol {
1444
+ const shouldResolve = !dontResolveAlias && symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace));
1445
+ return shouldResolve ? resolveAlias(symbol) : symbol;
1436
1446
}
1437
1447
1438
1448
function resolveAlias(symbol: Symbol): Symbol {
@@ -1672,16 +1682,16 @@ namespace ts {
1672
1682
1673
1683
// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
1674
1684
// and an external module with no 'export =' declaration resolves to the module itself.
1675
- function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol {
1676
- return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports.get("export="))) || moduleSymbol;
1685
+ function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean ): Symbol {
1686
+ return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports.get("export="), dontResolveAlias )) || moduleSymbol;
1677
1687
}
1678
1688
1679
1689
// An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export ='
1680
1690
// references a symbol that is at least declared as a module or a variable. The target of the 'export =' may
1681
1691
// combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable).
1682
- function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression): Symbol {
1683
- let symbol = resolveExternalModuleSymbol(moduleSymbol);
1684
- if (symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
1692
+ function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression, dontResolveAlias: boolean ): Symbol {
1693
+ let symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias );
1694
+ if (!dontResolveAlias && symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
1685
1695
error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
1686
1696
symbol = undefined;
1687
1697
}
0 commit comments