Skip to content

Commit a97c18f

Browse files
authored
Ignore identifier declarations when calculating symbol visibility (#31974)
1 parent f2735b5 commit a97c18f

File tree

5 files changed

+155
-1
lines changed

5 files changed

+155
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3265,7 +3265,7 @@ namespace ts {
32653265

32663266
function hasVisibleDeclarations(symbol: Symbol, shouldComputeAliasToMakeVisible: boolean): SymbolVisibilityResult | undefined {
32673267
let aliasesToMakeVisible: LateVisibilityPaintedStatement[] | undefined;
3268-
if (!every(symbol.declarations, getIsDeclarationVisible)) {
3268+
if (!every(filter(symbol.declarations, d => d.kind !== SyntaxKind.Identifier), getIsDeclarationVisible)) {
32693269
return undefined;
32703270
}
32713271
return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible };
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [declarationEmitExpandoWithGenericConstraint.ts]
2+
export interface Point {
3+
readonly x: number;
4+
readonly y: number;
5+
}
6+
7+
export interface Rect<p extends Point> {
8+
readonly a: p;
9+
readonly b: p;
10+
}
11+
12+
export const Point = (x: number, y: number): Point => ({ x, y });
13+
export const Rect = <p extends Point>(a: p, b: p): Rect<p> => ({ a, b });
14+
15+
Point.zero = (): Point => Point(0, 0);
16+
17+
//// [declarationEmitExpandoWithGenericConstraint.js]
18+
"use strict";
19+
exports.__esModule = true;
20+
exports.Point = function (x, y) { return ({ x: x, y: y }); };
21+
exports.Rect = function (a, b) { return ({ a: a, b: b }); };
22+
exports.Point.zero = function () { return exports.Point(0, 0); };
23+
24+
25+
//// [declarationEmitExpandoWithGenericConstraint.d.ts]
26+
export interface Point {
27+
readonly x: number;
28+
readonly y: number;
29+
}
30+
export interface Rect<p extends Point> {
31+
readonly a: p;
32+
readonly b: p;
33+
}
34+
export declare const Point: {
35+
(x: number, y: number): Point;
36+
zero(): Point;
37+
};
38+
export declare const Rect: <p extends Point>(a: p, b: p) => Rect<p>;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
=== tests/cases/compiler/declarationEmitExpandoWithGenericConstraint.ts ===
2+
export interface Point {
3+
>Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
4+
5+
readonly x: number;
6+
>x : Symbol(Point.x, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 24))
7+
8+
readonly y: number;
9+
>y : Symbol(Point.y, Decl(declarationEmitExpandoWithGenericConstraint.ts, 1, 23))
10+
}
11+
12+
export interface Rect<p extends Point> {
13+
>Rect : Symbol(Rect, Decl(declarationEmitExpandoWithGenericConstraint.ts, 3, 1), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 12))
14+
>p : Symbol(p, Decl(declarationEmitExpandoWithGenericConstraint.ts, 5, 22))
15+
>Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
16+
17+
readonly a: p;
18+
>a : Symbol(Rect.a, Decl(declarationEmitExpandoWithGenericConstraint.ts, 5, 40))
19+
>p : Symbol(p, Decl(declarationEmitExpandoWithGenericConstraint.ts, 5, 22))
20+
21+
readonly b: p;
22+
>b : Symbol(Rect.b, Decl(declarationEmitExpandoWithGenericConstraint.ts, 6, 18))
23+
>p : Symbol(p, Decl(declarationEmitExpandoWithGenericConstraint.ts, 5, 22))
24+
}
25+
26+
export const Point = (x: number, y: number): Point => ({ x, y });
27+
>Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
28+
>x : Symbol(x, Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 22))
29+
>y : Symbol(y, Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 32))
30+
>Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
31+
>x : Symbol(x, Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 56))
32+
>y : Symbol(y, Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 59))
33+
34+
export const Rect = <p extends Point>(a: p, b: p): Rect<p> => ({ a, b });
35+
>Rect : Symbol(Rect, Decl(declarationEmitExpandoWithGenericConstraint.ts, 3, 1), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 12))
36+
>p : Symbol(p, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 21))
37+
>Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
38+
>a : Symbol(a, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 38))
39+
>p : Symbol(p, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 21))
40+
>b : Symbol(b, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 43))
41+
>p : Symbol(p, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 21))
42+
>Rect : Symbol(Rect, Decl(declarationEmitExpandoWithGenericConstraint.ts, 3, 1), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 12))
43+
>p : Symbol(p, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 21))
44+
>a : Symbol(a, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 64))
45+
>b : Symbol(b, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 67))
46+
47+
Point.zero = (): Point => Point(0, 0);
48+
>Point.zero : Symbol(Point.zero, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
49+
>Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
50+
>zero : Symbol(Point.zero, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
51+
>Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
52+
>Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73))
53+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
=== tests/cases/compiler/declarationEmitExpandoWithGenericConstraint.ts ===
2+
export interface Point {
3+
readonly x: number;
4+
>x : number
5+
6+
readonly y: number;
7+
>y : number
8+
}
9+
10+
export interface Rect<p extends Point> {
11+
readonly a: p;
12+
>a : p
13+
14+
readonly b: p;
15+
>b : p
16+
}
17+
18+
export const Point = (x: number, y: number): Point => ({ x, y });
19+
>Point : { (x: number, y: number): Point; zero(): Point; }
20+
>(x: number, y: number): Point => ({ x, y }) : { (x: number, y: number): Point; zero(): Point; }
21+
>x : number
22+
>y : number
23+
>({ x, y }) : { x: number; y: number; }
24+
>{ x, y } : { x: number; y: number; }
25+
>x : number
26+
>y : number
27+
28+
export const Rect = <p extends Point>(a: p, b: p): Rect<p> => ({ a, b });
29+
>Rect : <p extends Point>(a: p, b: p) => Rect<p>
30+
><p extends Point>(a: p, b: p): Rect<p> => ({ a, b }) : <p extends Point>(a: p, b: p) => Rect<p>
31+
>a : p
32+
>b : p
33+
>({ a, b }) : { a: p; b: p; }
34+
>{ a, b } : { a: p; b: p; }
35+
>a : p
36+
>b : p
37+
38+
Point.zero = (): Point => Point(0, 0);
39+
>Point.zero = (): Point => Point(0, 0) : () => Point
40+
>Point.zero : () => Point
41+
>Point : { (x: number, y: number): Point; zero(): Point; }
42+
>zero : () => Point
43+
>(): Point => Point(0, 0) : () => Point
44+
>Point(0, 0) : Point
45+
>Point : { (x: number, y: number): Point; zero(): Point; }
46+
>0 : 0
47+
>0 : 0
48+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @declaration: true
2+
export interface Point {
3+
readonly x: number;
4+
readonly y: number;
5+
}
6+
7+
export interface Rect<p extends Point> {
8+
readonly a: p;
9+
readonly b: p;
10+
}
11+
12+
export const Point = (x: number, y: number): Point => ({ x, y });
13+
export const Rect = <p extends Point>(a: p, b: p): Rect<p> => ({ a, b });
14+
15+
Point.zero = (): Point => Point(0, 0);

0 commit comments

Comments
 (0)