Skip to content

Commit e5675a8

Browse files
author
Andy Hanson
committed
Always output something at the end of walkSymbol
1 parent ddb5a00 commit e5675a8

24 files changed

+77
-65
lines changed

src/compiler/checker.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ namespace ts {
20582058
parentSymbol = symbol;
20592059
}
20602060

2061-
// const the writer know we just wrote out a symbol. The declaration emitter writer uses
2061+
// Let the writer know we just wrote out a symbol. The declaration emitter writer uses
20622062
// this to determine if an import it has previously seen (and not written out) needs
20632063
// to be written to the file once the walk of the tree is complete.
20642064
//
@@ -2067,37 +2067,38 @@ namespace ts {
20672067
// and we could then access that data during declaration emit.
20682068
writer.trackSymbol(symbol, enclosingDeclaration, meaning);
20692069
function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void {
2070-
if (symbol) {
2071-
const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing));
2072-
2073-
if (!accessibleSymbolChain ||
2074-
needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
2070+
function recur(symbol: Symbol, meaning: SymbolFlags, endOfChain?: boolean): void {
2071+
if (symbol) {
2072+
const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing));
20752073

2076-
// Go up and add our parent.
2077-
walkSymbol(
2078-
getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol),
2079-
getQualifiedLeftMeaning(meaning));
2080-
}
2074+
if (!accessibleSymbolChain ||
2075+
needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
20812076

2082-
if (accessibleSymbolChain) {
2083-
for (const accessibleSymbol of accessibleSymbolChain) {
2084-
appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
2085-
}
2086-
}
2087-
else {
2088-
// If we didn't find accessible symbol chain for this symbol, break if this is external module
2089-
if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) {
2090-
return;
2077+
// Go up and add our parent.
2078+
recur(
2079+
getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol),
2080+
getQualifiedLeftMeaning(meaning));
20912081
}
20922082

2093-
// if this is anonymous type break
2094-
if (symbol.flags & SymbolFlags.TypeLiteral || symbol.flags & SymbolFlags.ObjectLiteral) {
2095-
return;
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);
20962097
}
2097-
2098-
appendParentTypeArgumentsAndSymbolName(symbol);
20992098
}
21002099
}
2100+
2101+
recur(symbol, meaning, /*endOfChain*/ true);
21012102
}
21022103

21032104
// Get qualified name if the symbol is not a type parameter

tests/baselines/reference/augmentExportEquals3.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
=== tests/cases/compiler/file1.ts ===
22

33
function foo() {}
4-
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8))
4+
>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8))
55

66
namespace foo {
7-
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8))
7+
>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8))
88

99
export var v = 1;
1010
>v : Symbol(v, Decl(file1.ts, 3, 14))

tests/baselines/reference/augmentExportEquals3.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
=== tests/cases/compiler/file1.ts ===
22

33
function foo() {}
4-
>foo : typeof
4+
>foo : typeof foo
55

66
namespace foo {
7-
>foo : typeof
7+
>foo : typeof foo
88

99
export var v = 1;
1010
>v : number

tests/baselines/reference/augmentExportEquals3_1.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
=== tests/cases/compiler/file1.d.ts ===
22
declare module "file1" {
33
function foo(): void;
4-
>foo : Symbol(, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8))
4+
>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8))
55

66
namespace foo {
7-
>foo : Symbol(, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8))
7+
>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8))
88

99
export var v: number;
1010
>v : Symbol(v, Decl(file1.d.ts, 3, 18))

tests/baselines/reference/augmentExportEquals3_1.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
=== tests/cases/compiler/file1.d.ts ===
22
declare module "file1" {
33
function foo(): void;
4-
>foo : typeof
4+
>foo : typeof foo
55

66
namespace foo {
7-
>foo : typeof
7+
>foo : typeof foo
88

99
export var v: number;
1010
>v : number

tests/baselines/reference/augmentExportEquals4.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
=== tests/cases/compiler/file1.ts ===
22

33
class foo {}
4-
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8))
4+
>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8))
55

66
namespace foo {
7-
>foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8))
7+
>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8))
88

99
export var v = 1;
1010
>v : Symbol(v, Decl(file1.ts, 3, 14))

tests/baselines/reference/augmentExportEquals4.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
=== tests/cases/compiler/file1.ts ===
22

33
class foo {}
4-
>foo :
4+
>foo : foo
55

66
namespace foo {
7-
>foo : typeof
7+
>foo : typeof foo
88

99
export var v = 1;
1010
>v : number

tests/baselines/reference/augmentExportEquals4_1.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
declare module "file1" {
44
class foo {}
5-
>foo : Symbol(, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 2, 8))
5+
>foo : Symbol(foo, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 2, 8))
66

77
namespace foo {
8-
>foo : Symbol(, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 2, 8))
8+
>foo : Symbol(foo, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 2, 8))
99

1010
export var v: number;
1111
>v : Symbol(v, Decl(file1.d.ts, 4, 18))

tests/baselines/reference/augmentExportEquals4_1.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
declare module "file1" {
44
class foo {}
5-
>foo :
5+
>foo : foo
66

77
namespace foo {
8-
>foo : typeof
8+
>foo : typeof foo
99

1010
export var v: number;
1111
>v : number

tests/baselines/reference/augmentExportEquals5.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ declare module Express {
1616

1717
declare module "express" {
1818
function e(): e.Express;
19-
>e : Symbol(, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29))
19+
>e : Symbol(e, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29))
2020
>e : Symbol(e, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28))
2121
>Express : Symbol(Express, Decl(express.d.ts, 54, 9))
2222

2323
namespace e {
24-
>e : Symbol(, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29))
24+
>e : Symbol(e, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29))
2525

2626
interface IRoute {
2727
>IRoute : Symbol(IRoute, Decl(express.d.ts, 10, 17))

0 commit comments

Comments
 (0)