Skip to content

Commit df7c309

Browse files
committed
Do visibility painting from collectLinkedAliases in checker to remove statefullness in declaration emit
1 parent 06dd3f2 commit df7c309

5 files changed

+84
-5
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4005,25 +4005,30 @@ namespace ts {
40054005
}
40064006
}
40074007

4008-
function collectLinkedAliases(node: Identifier): Node[] {
4008+
function collectLinkedAliases(node: Identifier, setVisibility?: boolean): Node[] | undefined {
40094009
let exportSymbol: Symbol;
40104010
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
4011-
exportSymbol = resolveName(node.parent, node.escapedText, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, Diagnostics.Cannot_find_name_0, node, /*isUse*/ false);
4011+
exportSymbol = resolveName(node, node.escapedText, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, /*nameNotFoundMessage*/ undefined, node, /*isUse*/ false);
40124012
}
40134013
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
40144014
exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
40154015
}
4016-
const result: Node[] = [];
4016+
let result: Node[];
40174017
if (exportSymbol) {
40184018
buildVisibleNodeList(exportSymbol.declarations);
40194019
}
40204020
return result;
40214021

40224022
function buildVisibleNodeList(declarations: Declaration[]) {
40234023
forEach(declarations, declaration => {
4024-
getNodeLinks(declaration).isVisible = true;
40254024
const resultNode = getAnyImportSyntax(declaration) || declaration;
4026-
pushIfUnique(result, resultNode);
4025+
if (setVisibility) {
4026+
getNodeLinks(declaration).isVisible = true;
4027+
}
4028+
else {
4029+
result = result || [];
4030+
pushIfUnique(result, resultNode);
4031+
}
40274032

40284033
if (isInternalModuleImportEqualsDeclaration(declaration)) {
40294034
// Add the referenced top container visible
@@ -22865,6 +22870,7 @@ namespace ts {
2286522870

2286622871
function checkExportSpecifier(node: ExportSpecifier) {
2286722872
checkAliasSymbol(node);
22873+
collectLinkedAliases(node.propertyName || node.name, /*setVisibility*/ true); // Collect linked aliases to set visibility links
2286822874
if (!(<ExportDeclaration>node.parent.parent).moduleSpecifier) {
2286922875
const exportedName = node.propertyName || node.name;
2287022876
// find immediate value referenced by exported name (SymbolFlags.Alias is set so we don't chase down aliases)
@@ -22902,6 +22908,7 @@ namespace ts {
2290222908
}
2290322909
if (node.expression.kind === SyntaxKind.Identifier) {
2290422910
markExportAsReferenced(node);
22911+
collectLinkedAliases(node.expression as Identifier, /*setVisibility*/ true); // Sets visibility flags on refernced nodes
2290522912
}
2290622913
else {
2290722914
checkExpressionCached(node.expression);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [mutuallyRecusiveInterfaceDeclaration.ts]
2+
interface A {
3+
b: B
4+
}
5+
6+
interface B {
7+
a: A
8+
}
9+
export {A, B}
10+
11+
//// [mutuallyRecusiveInterfaceDeclaration.js]
12+
"use strict";
13+
exports.__esModule = true;
14+
15+
16+
//// [mutuallyRecusiveInterfaceDeclaration.d.ts]
17+
interface A {
18+
b: B;
19+
}
20+
interface B {
21+
a: A;
22+
}
23+
export { A, B };
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/mutuallyRecusiveInterfaceDeclaration.ts ===
2+
interface A {
3+
>A : Symbol(A, Decl(mutuallyRecusiveInterfaceDeclaration.ts, 0, 0))
4+
5+
b: B
6+
>b : Symbol(A.b, Decl(mutuallyRecusiveInterfaceDeclaration.ts, 0, 13))
7+
>B : Symbol(B, Decl(mutuallyRecusiveInterfaceDeclaration.ts, 2, 1))
8+
}
9+
10+
interface B {
11+
>B : Symbol(B, Decl(mutuallyRecusiveInterfaceDeclaration.ts, 2, 1))
12+
13+
a: A
14+
>a : Symbol(B.a, Decl(mutuallyRecusiveInterfaceDeclaration.ts, 4, 13))
15+
>A : Symbol(A, Decl(mutuallyRecusiveInterfaceDeclaration.ts, 0, 0))
16+
}
17+
export {A, B}
18+
>A : Symbol(A, Decl(mutuallyRecusiveInterfaceDeclaration.ts, 7, 8))
19+
>B : Symbol(B, Decl(mutuallyRecusiveInterfaceDeclaration.ts, 7, 10))
20+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/mutuallyRecusiveInterfaceDeclaration.ts ===
2+
interface A {
3+
>A : A
4+
5+
b: B
6+
>b : B
7+
>B : B
8+
}
9+
10+
interface B {
11+
>B : B
12+
13+
a: A
14+
>a : A
15+
>A : A
16+
}
17+
export {A, B}
18+
>A : any
19+
>B : any
20+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @declaration: true
2+
interface A {
3+
b: B
4+
}
5+
6+
interface B {
7+
a: A
8+
}
9+
export {A, B}

0 commit comments

Comments
 (0)