@@ -1537,8 +1537,8 @@ namespace ts {
1537
1537
}
1538
1538
if (symbol.flags & SymbolFlags.Alias) {
1539
1539
const targetFlags = getAllSymbolFlags(symbol);
1540
- // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors
1541
- if (targetFlags === undefined || targetFlags & meaning) {
1540
+ // `targetFlags` will be `SymbolFlags.All` if an error occurred in alias resolution; this avoids cascading errors
1541
+ if (targetFlags & meaning) {
1542
1542
return symbol;
1543
1543
}
1544
1544
}
@@ -3254,35 +3254,35 @@ namespace ts {
3254
3254
* from b.ts, even though there is still more alias to resolve. Consequently, if we were
3255
3255
* trying to determine if the `a` in c.ts has a value meaning, looking at the flags on
3256
3256
* the local symbol and on the symbol returned by `resolveAlias` is not enough.
3257
- * @returns undefined if `symbol` is an alias that ultimately resolves to `unknown`;
3257
+ * @returns SymbolFlags.All if `symbol` is an alias that ultimately resolves to `unknown`;
3258
3258
* combined flags of all alias targets otherwise.
3259
3259
*/
3260
- function getAllSymbolFlags(symbol: Symbol): SymbolFlags | undefined {
3261
- let flags = symbol.flags;
3262
- let seenSymbols;
3263
- while (symbol.flags & SymbolFlags.Alias) {
3264
- const target = resolveAlias(symbol);
3265
- if (target === unknownSymbol) {
3266
- return undefined ;
3267
- }
3268
-
3269
- // Optimizations - try to avoid creating or adding to
3270
- // `seenSymbols` if possible
3271
- if (target === symbol || seenSymbols?.has(target)) {
3272
- break;
3273
- }
3274
- if (target.flags & SymbolFlags.Alias) {
3275
- if (seenSymbols) {
3276
- seenSymbols.add(target);
3277
- }
3278
- else {
3279
- seenSymbols = new Set([symbol, target]);
3280
- }
3281
- }
3282
- flags |= target.flags;
3283
- symbol = target;
3284
- }
3285
- return flags;
3260
+ function getAllSymbolFlags(symbol: Symbol): SymbolFlags {
3261
+ let flags = symbol.flags;
3262
+ let seenSymbols;
3263
+ while (symbol.flags & SymbolFlags.Alias) {
3264
+ const target = resolveAlias(symbol);
3265
+ if (target === unknownSymbol) {
3266
+ return SymbolFlags.All ;
3267
+ }
3268
+
3269
+ // Optimizations - try to avoid creating or adding to
3270
+ // `seenSymbols` if possible
3271
+ if (target === symbol || seenSymbols?.has(target)) {
3272
+ break;
3273
+ }
3274
+ if (target.flags & SymbolFlags.Alias) {
3275
+ if (seenSymbols) {
3276
+ seenSymbols.add(target);
3277
+ }
3278
+ else {
3279
+ seenSymbols = new Set([symbol, target]);
3280
+ }
3281
+ }
3282
+ flags |= target.flags;
3283
+ symbol = target;
3284
+ }
3285
+ return flags;
3286
3286
}
3287
3287
3288
3288
/**
@@ -3346,7 +3346,7 @@ namespace ts {
3346
3346
return links.typeOnlyDeclaration || undefined;
3347
3347
}
3348
3348
if (links.typeOnlyDeclaration) {
3349
- return ( getAllSymbolFlags(resolveAlias(links.typeOnlyDeclaration.symbol)) ?? -1 ) & include ? links.typeOnlyDeclaration : undefined;
3349
+ return getAllSymbolFlags(resolveAlias(links.typeOnlyDeclaration.symbol)) & include ? links.typeOnlyDeclaration : undefined;
3350
3350
}
3351
3351
return undefined;
3352
3352
}
@@ -3356,7 +3356,7 @@ namespace ts {
3356
3356
const target = resolveAlias(symbol);
3357
3357
if (target) {
3358
3358
const markAlias = target === unknownSymbol ||
3359
- ((( getAllSymbolFlags(target) ?? -1 ) & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target) && !getTypeOnlyAliasDeclaration(symbol, SymbolFlags.Value));
3359
+ ((getAllSymbolFlags(target) & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target) && !getTypeOnlyAliasDeclaration(symbol, SymbolFlags.Value));
3360
3360
3361
3361
if (markAlias) {
3362
3362
markAliasSymbolAsReferenced(symbol);
@@ -3377,8 +3377,7 @@ namespace ts {
3377
3377
// This way a chain of imports can be elided if ultimately the final input is only used in a type
3378
3378
// position.
3379
3379
if (isInternalModuleImportEqualsDeclaration(node)) {
3380
- const targetFlags = getAllSymbolFlags(resolveSymbol(symbol));
3381
- if (targetFlags === undefined || targetFlags & SymbolFlags.Value) {
3380
+ if (getAllSymbolFlags(resolveSymbol(symbol)) & SymbolFlags.Value) {
3382
3381
// import foo = <symbol>
3383
3382
checkExpressionCached(node.moduleReference as Expression);
3384
3383
}
@@ -4304,7 +4303,7 @@ namespace ts {
4304
4303
function symbolIsValue(symbol: Symbol, includeTypeOnlyMembers?: boolean): boolean {
4305
4304
return !!(
4306
4305
symbol.flags & SymbolFlags.Value ||
4307
- symbol.flags & SymbolFlags.Alias && ( getAllSymbolFlags(symbol) ?? -1 ) & SymbolFlags.Value && (includeTypeOnlyMembers || !getTypeOnlyAliasDeclaration(symbol)));
4306
+ symbol.flags & SymbolFlags.Alias && getAllSymbolFlags(symbol) & SymbolFlags.Value && (includeTypeOnlyMembers || !getTypeOnlyAliasDeclaration(symbol)));
4308
4307
}
4309
4308
4310
4309
function findConstructorDeclaration(node: ClassLikeDeclaration): ConstructorDeclaration | undefined {
@@ -4600,7 +4599,7 @@ namespace ts {
4600
4599
// Qualify if the symbol from symbol table has same meaning as expected
4601
4600
const shouldResolveAlias = (symbolFromSymbolTable.flags & SymbolFlags.Alias && !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier));
4602
4601
symbolFromSymbolTable = shouldResolveAlias ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
4603
- const flags = shouldResolveAlias ? ( getAllSymbolFlags(symbolFromSymbolTable) ?? unknownSymbol.flags ) : symbolFromSymbolTable.flags;
4602
+ const flags = shouldResolveAlias ? getAllSymbolFlags(symbolFromSymbolTable) : symbolFromSymbolTable.flags;
4604
4603
if (flags & meaning) {
4605
4604
qualify = true;
4606
4605
return true;
@@ -7574,7 +7573,7 @@ namespace ts {
7574
7573
}
7575
7574
7576
7575
function isTypeOnlyNamespace(symbol: Symbol) {
7577
- return every(getNamespaceMembersForSerialization(symbol), m => !(( getAllSymbolFlags(resolveSymbol(m)) ?? unknownSymbol.flags ) & SymbolFlags.Value));
7576
+ return every(getNamespaceMembersForSerialization(symbol), m => !(getAllSymbolFlags(resolveSymbol(m)) & SymbolFlags.Value));
7578
7577
}
7579
7578
7580
7579
function serializeModule(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) {
@@ -10072,7 +10071,7 @@ namespace ts {
10072
10071
links.type = exportSymbol?.declarations && isDuplicatedCommonJSExport(exportSymbol.declarations) && symbol.declarations!.length ? getFlowTypeFromCommonJSExport(exportSymbol)
10073
10072
: isDuplicatedCommonJSExport(symbol.declarations) ? autoType
10074
10073
: declaredType ? declaredType
10075
- : ( getAllSymbolFlags(targetSymbol) ?? -1 ) & SymbolFlags.Value ? getTypeOfSymbol(targetSymbol)
10074
+ : getAllSymbolFlags(targetSymbol) & SymbolFlags.Value ? getTypeOfSymbol(targetSymbol)
10076
10075
: errorType;
10077
10076
}
10078
10077
return links.type;
@@ -25974,7 +25973,7 @@ namespace ts {
25974
25973
function markAliasReferenced(symbol: Symbol, location: Node) {
25975
25974
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol, SymbolFlags.Value)) {
25976
25975
const target = resolveAlias(symbol);
25977
- if (( getAllSymbolFlags(target) ?? -1 ) & SymbolFlags.Value) {
25976
+ if (getAllSymbolFlags(target) & SymbolFlags.Value) {
25978
25977
// An alias resolving to a const enum cannot be elided if (1) 'isolatedModules' is enabled
25979
25978
// (because the const enum value will not be inlined), or if (2) the alias is an export
25980
25979
// of a const enum declaration that will be preserved.
@@ -32521,7 +32520,7 @@ namespace ts {
32521
32520
if (symbol && symbol.flags & SymbolFlags.Alias) {
32522
32521
symbol = resolveAlias(symbol);
32523
32522
}
32524
- return !!(symbol && (( getAllSymbolFlags(symbol) ?? unknownSymbol.flags ) & SymbolFlags.Enum) && getEnumKind(symbol) === EnumKind.Literal);
32523
+ return !!(symbol && (getAllSymbolFlags(symbol) & SymbolFlags.Enum) && getEnumKind(symbol) === EnumKind.Literal);
32525
32524
}
32526
32525
return false;
32527
32526
}
@@ -41427,7 +41426,7 @@ namespace ts {
41427
41426
return;
41428
41427
}
41429
41428
41430
- const targetFlags = getAllSymbolFlags(target) ?? target.flags ;
41429
+ const targetFlags = getAllSymbolFlags(target);
41431
41430
const excludedMeanings =
41432
41431
(symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue) ? SymbolFlags.Value : 0) |
41433
41432
(symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) |
@@ -41621,7 +41620,7 @@ namespace ts {
41621
41620
if (node.moduleReference.kind !== SyntaxKind.ExternalModuleReference) {
41622
41621
const target = resolveAlias(getSymbolOfNode(node));
41623
41622
if (target !== unknownSymbol) {
41624
- const targetFlags = getAllSymbolFlags(target) ?? unknownSymbol.flags ;
41623
+ const targetFlags = getAllSymbolFlags(target);
41625
41624
if (targetFlags & SymbolFlags.Value) {
41626
41625
// Target is a value symbol, check that it is not hidden by a local declaration with the same name
41627
41626
const moduleName = getFirstIdentifier(node.moduleReference);
@@ -41780,7 +41779,7 @@ namespace ts {
41780
41779
markExportAsReferenced(node);
41781
41780
}
41782
41781
const target = symbol && (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol);
41783
- if (!target || ( getAllSymbolFlags(target) ?? -1 ) & SymbolFlags.Value) {
41782
+ if (!target || getAllSymbolFlags(target) & SymbolFlags.Value) {
41784
41783
checkExpressionCached(node.propertyName || node.name);
41785
41784
}
41786
41785
}
@@ -41832,7 +41831,7 @@ namespace ts {
41832
41831
markAliasReferenced(sym, id);
41833
41832
// If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`)
41834
41833
const target = sym.flags & SymbolFlags.Alias ? resolveAlias(sym) : sym;
41835
- if (( getAllSymbolFlags(target) ?? -1 ) & SymbolFlags.Value) {
41834
+ if (getAllSymbolFlags(target) & SymbolFlags.Value) {
41836
41835
// However if it is a value, we need to check it's being used correctly
41837
41836
checkExpressionCached(node.expression);
41838
41837
}
@@ -43290,7 +43289,7 @@ namespace ts {
43290
43289
43291
43290
function isValue(s: Symbol): boolean {
43292
43291
s = resolveSymbol(s);
43293
- return s && !!(( getAllSymbolFlags(s) ?? unknownSymbol.flags ) & SymbolFlags.Value);
43292
+ return s && !!(getAllSymbolFlags(s) & SymbolFlags.Value);
43294
43293
}
43295
43294
}
43296
43295
@@ -43496,7 +43495,7 @@ namespace ts {
43496
43495
}
43497
43496
const target = getSymbolLinks(symbol!).aliasTarget; // TODO: GH#18217
43498
43497
if (target && getEffectiveModifierFlags(node) & ModifierFlags.Export &&
43499
- ( getAllSymbolFlags(target) ?? -1 ) & SymbolFlags.Value &&
43498
+ getAllSymbolFlags(target) & SymbolFlags.Value &&
43500
43499
(shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target))) {
43501
43500
// An `export import ... =` of a value symbol is always considered referenced
43502
43501
return true;
0 commit comments