@@ -2182,7 +2182,12 @@ namespace ts {
2182
2182
2183
2183
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration, dontResolveAlias: boolean): Symbol | undefined {
2184
2184
if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) {
2185
- return resolveExternalModuleSymbol(resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)));
2185
+ const immediate = resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node));
2186
+ const resolved = resolveExternalModuleSymbol(immediate);
2187
+ if (!markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, immediate)) {
2188
+ markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, resolved);
2189
+ }
2190
+ return resolved;
2186
2191
}
2187
2192
return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, dontResolveAlias);
2188
2193
}
@@ -2278,7 +2283,9 @@ namespace ts {
2278
2283
else if (hasSyntheticDefault) {
2279
2284
// per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present
2280
2285
const resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
2281
- if (!isTypeOnly) markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, resolved);
2286
+ if (!isTypeOnly && !markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, moduleSymbol)) {
2287
+ markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, resolved);
2288
+ }
2282
2289
return resolved;
2283
2290
}
2284
2291
if (!isTypeOnly) markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, exportDefaultSymbol);
@@ -2289,8 +2296,11 @@ namespace ts {
2289
2296
function getTargetOfNamespaceImport(node: NamespaceImport, dontResolveAlias: boolean): Symbol | undefined {
2290
2297
const moduleSpecifier = node.parent.parent.moduleSpecifier;
2291
2298
const isTypeOnly = markSymbolOfAliasDeclarationIfTypeOnly(node);
2292
- const resolved = resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias, /*suppressUsageError*/ false);
2293
- if (!isTypeOnly) markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, resolved);
2299
+ const immediate = resolveExternalModuleName(node, moduleSpecifier);
2300
+ const resolved = resolveESModuleSymbol(immediate, moduleSpecifier, dontResolveAlias, /*suppressUsageError*/ false);
2301
+ if (!isTypeOnly && !markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, immediate)) {
2302
+ markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, resolved);
2303
+ }
2294
2304
return resolved;
2295
2305
}
2296
2306
@@ -2459,7 +2469,9 @@ namespace ts {
2459
2469
2460
2470
function getTargetOfExportAssignment(node: ExportAssignment | BinaryExpression, dontResolveAlias: boolean): Symbol | undefined {
2461
2471
const expression = (isExportAssignment(node) ? node.expression : node.right) as EntityNameExpression | ClassExpression;
2462
- return getTargetOfAliasLikeExpression(expression, dontResolveAlias);
2472
+ const resolved = getTargetOfAliasLikeExpression(expression, dontResolveAlias);
2473
+ markSymbolOfAliasDeclarationIfResolvesToTypeOnly(node, resolved);
2474
+ return resolved;
2463
2475
}
2464
2476
2465
2477
function getTargetOfAliasLikeExpression(expression: Expression, dontResolveAlias: boolean) {
@@ -2556,14 +2568,18 @@ namespace ts {
2556
2568
return links.target;
2557
2569
}
2558
2570
2559
- function markSymbolOfAliasDeclarationIfResolvesToTypeOnly(aliasDeclaration: TypeOnlyCompatibleAliasDeclaration | undefined, resolvesToSymbol: Symbol | undefined) {
2560
- if (!aliasDeclaration || !resolvesToSymbol) return;
2571
+ function markSymbolOfAliasDeclarationIfResolvesToTypeOnly(aliasDeclaration: Declaration | undefined, resolvesToSymbol: Symbol | undefined): boolean {
2572
+ if (!aliasDeclaration || !resolvesToSymbol) return false ;
2561
2573
const sourceSymbol = getSymbolOfNode(aliasDeclaration);
2562
2574
const links = getSymbolLinks(sourceSymbol);
2563
2575
if (links.typeOnlyDeclaration === undefined) {
2576
+ resolvesToSymbol = resolvesToSymbol.exports?.get(InternalSymbolName.ExportEquals) ?? resolvesToSymbol;
2564
2577
const typeOnly = find(resolvesToSymbol.declarations, isTypeOnlyImportOrExportDeclaration);
2565
- links.typeOnlyDeclaration = typeOnly ?? getSymbolLinks(resolvesToSymbol).typeOnlyDeclaration ?? false;
2578
+ const decl = typeOnly ?? getSymbolLinks(resolvesToSymbol).typeOnlyDeclaration ?? false;
2579
+ links.typeOnlyDeclaration = decl;
2580
+ return !!decl;
2566
2581
}
2582
+ return false;
2567
2583
}
2568
2584
2569
2585
function markSymbolOfAliasDeclarationIfTypeOnly(aliasDeclaration: TypeOnlyCompatibleAliasDeclaration): boolean {
@@ -2711,8 +2727,8 @@ namespace ts {
2711
2727
throw Debug.assertNever(name, "Unknown entity name kind.");
2712
2728
}
2713
2729
Debug.assert((getCheckFlags(symbol) & CheckFlags.Instantiated) === 0, "Should never get an instantiated symbol here.");
2714
- if (isIdentifier(name) && symbol.flags & SymbolFlags.Alias) {
2715
- markSymbolOfAliasDeclarationIfResolvesToTypeOnly(getTypeOnlyCompatibleAliasDeclarationFromName (name), symbol);
2730
+ if (isIdentifier(name) && ( symbol.flags & SymbolFlags.Alias || name.parent.kind === SyntaxKind.ExportAssignment) ) {
2731
+ markSymbolOfAliasDeclarationIfResolvesToTypeOnly(getAliasDeclarationFromName (name), symbol);
2716
2732
}
2717
2733
return (symbol.flags & meaning) || dontResolveAlias ? symbol : resolveAlias(symbol);
2718
2734
}
0 commit comments