Skip to content

Commit 72ff9e5

Browse files
committed
Just make getAllSymbolFlags default to All
1 parent fcefb22 commit 72ff9e5

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed

src/compiler/checker.ts

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,8 +1537,8 @@ namespace ts {
15371537
}
15381538
if (symbol.flags & SymbolFlags.Alias) {
15391539
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) {
15421542
return symbol;
15431543
}
15441544
}
@@ -3254,35 +3254,35 @@ namespace ts {
32543254
* from b.ts, even though there is still more alias to resolve. Consequently, if we were
32553255
* trying to determine if the `a` in c.ts has a value meaning, looking at the flags on
32563256
* 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`;
32583258
* combined flags of all alias targets otherwise.
32593259
*/
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;
32863286
}
32873287

32883288
/**
@@ -3346,7 +3346,7 @@ namespace ts {
33463346
return links.typeOnlyDeclaration || undefined;
33473347
}
33483348
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;
33503350
}
33513351
return undefined;
33523352
}
@@ -3356,7 +3356,7 @@ namespace ts {
33563356
const target = resolveAlias(symbol);
33573357
if (target) {
33583358
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));
33603360

33613361
if (markAlias) {
33623362
markAliasSymbolAsReferenced(symbol);
@@ -3377,8 +3377,7 @@ namespace ts {
33773377
// This way a chain of imports can be elided if ultimately the final input is only used in a type
33783378
// position.
33793379
if (isInternalModuleImportEqualsDeclaration(node)) {
3380-
const targetFlags = getAllSymbolFlags(resolveSymbol(symbol));
3381-
if (targetFlags === undefined || targetFlags & SymbolFlags.Value) {
3380+
if (getAllSymbolFlags(resolveSymbol(symbol)) & SymbolFlags.Value) {
33823381
// import foo = <symbol>
33833382
checkExpressionCached(node.moduleReference as Expression);
33843383
}
@@ -4304,7 +4303,7 @@ namespace ts {
43044303
function symbolIsValue(symbol: Symbol, includeTypeOnlyMembers?: boolean): boolean {
43054304
return !!(
43064305
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)));
43084307
}
43094308

43104309
function findConstructorDeclaration(node: ClassLikeDeclaration): ConstructorDeclaration | undefined {
@@ -4600,7 +4599,7 @@ namespace ts {
46004599
// Qualify if the symbol from symbol table has same meaning as expected
46014600
const shouldResolveAlias = (symbolFromSymbolTable.flags & SymbolFlags.Alias && !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier));
46024601
symbolFromSymbolTable = shouldResolveAlias ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
4603-
const flags = shouldResolveAlias ? (getAllSymbolFlags(symbolFromSymbolTable) ?? unknownSymbol.flags) : symbolFromSymbolTable.flags;
4602+
const flags = shouldResolveAlias ? getAllSymbolFlags(symbolFromSymbolTable) : symbolFromSymbolTable.flags;
46044603
if (flags & meaning) {
46054604
qualify = true;
46064605
return true;
@@ -7574,7 +7573,7 @@ namespace ts {
75747573
}
75757574

75767575
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));
75787577
}
75797578

75807579
function serializeModule(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) {
@@ -10072,7 +10071,7 @@ namespace ts {
1007210071
links.type = exportSymbol?.declarations && isDuplicatedCommonJSExport(exportSymbol.declarations) && symbol.declarations!.length ? getFlowTypeFromCommonJSExport(exportSymbol)
1007310072
: isDuplicatedCommonJSExport(symbol.declarations) ? autoType
1007410073
: declaredType ? declaredType
10075-
: (getAllSymbolFlags(targetSymbol) ?? -1) & SymbolFlags.Value ? getTypeOfSymbol(targetSymbol)
10074+
: getAllSymbolFlags(targetSymbol) & SymbolFlags.Value ? getTypeOfSymbol(targetSymbol)
1007610075
: errorType;
1007710076
}
1007810077
return links.type;
@@ -25974,7 +25973,7 @@ namespace ts {
2597425973
function markAliasReferenced(symbol: Symbol, location: Node) {
2597525974
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol, SymbolFlags.Value)) {
2597625975
const target = resolveAlias(symbol);
25977-
if ((getAllSymbolFlags(target) ?? -1) & SymbolFlags.Value) {
25976+
if (getAllSymbolFlags(target) & SymbolFlags.Value) {
2597825977
// An alias resolving to a const enum cannot be elided if (1) 'isolatedModules' is enabled
2597925978
// (because the const enum value will not be inlined), or if (2) the alias is an export
2598025979
// of a const enum declaration that will be preserved.
@@ -32521,7 +32520,7 @@ namespace ts {
3252132520
if (symbol && symbol.flags & SymbolFlags.Alias) {
3252232521
symbol = resolveAlias(symbol);
3252332522
}
32524-
return !!(symbol && ((getAllSymbolFlags(symbol) ?? unknownSymbol.flags) & SymbolFlags.Enum) && getEnumKind(symbol) === EnumKind.Literal);
32523+
return !!(symbol && (getAllSymbolFlags(symbol) & SymbolFlags.Enum) && getEnumKind(symbol) === EnumKind.Literal);
3252532524
}
3252632525
return false;
3252732526
}
@@ -41427,7 +41426,7 @@ namespace ts {
4142741426
return;
4142841427
}
4142941428

41430-
const targetFlags = getAllSymbolFlags(target) ?? target.flags;
41429+
const targetFlags = getAllSymbolFlags(target);
4143141430
const excludedMeanings =
4143241431
(symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue) ? SymbolFlags.Value : 0) |
4143341432
(symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) |
@@ -41621,7 +41620,7 @@ namespace ts {
4162141620
if (node.moduleReference.kind !== SyntaxKind.ExternalModuleReference) {
4162241621
const target = resolveAlias(getSymbolOfNode(node));
4162341622
if (target !== unknownSymbol) {
41624-
const targetFlags = getAllSymbolFlags(target) ?? unknownSymbol.flags;
41623+
const targetFlags = getAllSymbolFlags(target);
4162541624
if (targetFlags & SymbolFlags.Value) {
4162641625
// Target is a value symbol, check that it is not hidden by a local declaration with the same name
4162741626
const moduleName = getFirstIdentifier(node.moduleReference);
@@ -41780,7 +41779,7 @@ namespace ts {
4178041779
markExportAsReferenced(node);
4178141780
}
4178241781
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) {
4178441783
checkExpressionCached(node.propertyName || node.name);
4178541784
}
4178641785
}
@@ -41832,7 +41831,7 @@ namespace ts {
4183241831
markAliasReferenced(sym, id);
4183341832
// If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`)
4183441833
const target = sym.flags & SymbolFlags.Alias ? resolveAlias(sym) : sym;
41835-
if ((getAllSymbolFlags(target) ?? -1) & SymbolFlags.Value) {
41834+
if (getAllSymbolFlags(target) & SymbolFlags.Value) {
4183641835
// However if it is a value, we need to check it's being used correctly
4183741836
checkExpressionCached(node.expression);
4183841837
}
@@ -43290,7 +43289,7 @@ namespace ts {
4329043289

4329143290
function isValue(s: Symbol): boolean {
4329243291
s = resolveSymbol(s);
43293-
return s && !!((getAllSymbolFlags(s) ?? unknownSymbol.flags) & SymbolFlags.Value);
43292+
return s && !!(getAllSymbolFlags(s) & SymbolFlags.Value);
4329443293
}
4329543294
}
4329643295

@@ -43496,7 +43495,7 @@ namespace ts {
4349643495
}
4349743496
const target = getSymbolLinks(symbol!).aliasTarget; // TODO: GH#18217
4349843497
if (target && getEffectiveModifierFlags(node) & ModifierFlags.Export &&
43499-
(getAllSymbolFlags(target) ?? -1) & SymbolFlags.Value &&
43498+
getAllSymbolFlags(target) & SymbolFlags.Value &&
4350043499
(shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target))) {
4350143500
// An `export import ... =` of a value symbol is always considered referenced
4350243501
return true;

0 commit comments

Comments
 (0)