Skip to content

Commit a9602fa

Browse files
author
Andy Hanson
committed
Reduce nesting
1 parent d443855 commit a9602fa

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

src/compiler/checker.ts

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,39 +2066,34 @@ namespace ts {
20662066
// up front (for example, during checking) could determine if we need to emit the imports
20672067
// and we could then access that data during declaration emit.
20682068
writer.trackSymbol(symbol, enclosingDeclaration, meaning);
2069-
function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void {
2070-
function climbSymbol(symbol: Symbol, meaning: SymbolFlags, endOfChain?: boolean): void {
2071-
if (symbol) {
2072-
const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing));
2073-
2074-
if (!accessibleSymbolChain ||
2075-
needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
2076-
2077-
// Go up and add our parent.
2078-
climbSymbol(
2079-
getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol),
2080-
getQualifiedLeftMeaning(meaning));
2081-
}
2069+
function walkSymbol(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): void {
2070+
const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing));
20822071

2083-
if (accessibleSymbolChain) {
2084-
for (const accessibleSymbol of accessibleSymbolChain) {
2085-
appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
2086-
}
2087-
}
2088-
else if (
2089-
// If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols.
2090-
endOfChain ||
2091-
// If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.)
2092-
!(!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) &&
2093-
// If a parent symbol is an anonymous type, don't write it.
2094-
!(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral))) {
2095-
2096-
appendParentTypeArgumentsAndSymbolName(symbol);
2097-
}
2072+
if (!accessibleSymbolChain ||
2073+
needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
2074+
2075+
// Go up and add our parent.
2076+
const parent = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol);
2077+
if (parent) {
2078+
walkSymbol(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false);
20982079
}
20992080
}
21002081

2101-
climbSymbol(symbol, meaning, /*endOfChain*/ true);
2082+
if (accessibleSymbolChain) {
2083+
for (const accessibleSymbol of accessibleSymbolChain) {
2084+
appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
2085+
}
2086+
}
2087+
else if (
2088+
// If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols.
2089+
endOfChain ||
2090+
// If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.)
2091+
!(!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) &&
2092+
// If a parent symbol is an anonymous type, don't write it.
2093+
!(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral))) {
2094+
2095+
appendParentTypeArgumentsAndSymbolName(symbol);
2096+
}
21022097
}
21032098

21042099
// Get qualified name if the symbol is not a type parameter
@@ -2107,7 +2102,7 @@ namespace ts {
21072102
const isTypeParameter = symbol.flags & SymbolFlags.TypeParameter;
21082103
const typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags;
21092104
if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) {
2110-
walkSymbol(symbol, meaning);
2105+
walkSymbol(symbol, meaning, /*endOfChain*/ true);
21112106
}
21122107
else {
21132108
appendParentTypeArgumentsAndSymbolName(symbol);

0 commit comments

Comments
 (0)