Skip to content

Commit af36d53

Browse files
authored
Fix export= class visibility alongside top-level export type (#64573)
1 parent 15dee00 commit af36d53

60 files changed

Lines changed: 2494 additions & 36 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎tsc/internal/checker/symbolaccessibility.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"slices"
55

66
"github.com/microsoft/TypeScript/tsc/internal/ast"
7+
"github.com/microsoft/TypeScript/tsc/internal/collections"
78
"github.com/microsoft/TypeScript/tsc/internal/core"
89
"github.com/microsoft/TypeScript/tsc/internal/printer"
910
)
@@ -664,6 +665,17 @@ func (c *Checker) isAccessible(
664665
if symbol == c.getMergedSymbol(symbolFromSymbolTable) {
665666
likeSymbols = true
666667
}
668+
if !likeSymbols && resolvedAliasSymbol != nil && resolvedAliasSymbol.Flags&ast.SymbolFlagsAlias != 0 {
669+
var seenAliases collections.Set[*ast.Symbol]
670+
for resolvedAliasSymbol.Flags&ast.SymbolFlagsAlias != 0 && !seenAliases.Has(resolvedAliasSymbol) {
671+
seenAliases.Add(resolvedAliasSymbol)
672+
resolvedAliasSymbol = c.getMergedSymbol(c.resolveAlias(resolvedAliasSymbol))
673+
if symbol == resolvedAliasSymbol {
674+
likeSymbols = true
675+
break
676+
}
677+
}
678+
}
667679
if !likeSymbols {
668680
return false
669681
}

‎tsc/testdata/baselines/reference/compiler/cjsExportGenericTypes.types‎

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

33
=== index.js ===
44
const Set = require("./set");
5-
>Set : typeof SomeGenericClass
6-
>require("./set") : typeof SomeGenericClass
5+
>Set : typeof Set
6+
>require("./set") : typeof Set
77
>require : any
88
>"./set" : "./set"
99

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
a.ts(1,10): error TS2484: Export declaration conflicts with exported declaration of 'A'.
2+
b.ts(1,10): error TS2484: Export declaration conflicts with exported declaration of 'B'.
3+
4+
5+
==== a.ts (1 errors) ====
6+
export { B as A } from "./b";
7+
~~~~~~
8+
!!! error TS2484: Export declaration conflicts with exported declaration of 'A'.
9+
export declare namespace A {
10+
export type FromA = number;
11+
}
12+
export class Route {
13+
private parts = 0;
14+
}
15+
export function create() { return new Route(); }
16+
17+
==== b.ts (1 errors) ====
18+
export { A as B } from "./a";
19+
~~~~~~
20+
!!! error TS2484: Export declaration conflicts with exported declaration of 'B'.
21+
export declare namespace B {
22+
export type FromB = string;
23+
}
24+
25+
==== index.ts (0 errors) ====
26+
import { A } from "./a";
27+
import { create } from "./a";
28+
export type Label = A.FromA;
29+
export const route = create();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [tests/cases/compiler/declarationEmitCircularMergedExportAliases.ts] ////
2+
3+
//// [a.ts]
4+
export { B as A } from "./b";
5+
export declare namespace A {
6+
export type FromA = number;
7+
}
8+
export class Route {
9+
private parts = 0;
10+
}
11+
export function create() { return new Route(); }
12+
13+
//// [b.ts]
14+
export { A as B } from "./a";
15+
export declare namespace B {
16+
export type FromB = string;
17+
}
18+
19+
//// [index.ts]
20+
import { A } from "./a";
21+
import { create } from "./a";
22+
export type Label = A.FromA;
23+
export const route = create();
24+
25+
26+
27+
//// [b.d.ts]
28+
export { A as B } from "./a";
29+
export declare namespace B {
30+
type FromB = string;
31+
}
32+
//// [a.d.ts]
33+
export { B as A } from "./b";
34+
export declare namespace A {
35+
type FromA = number;
36+
}
37+
export declare class Route {
38+
private parts;
39+
}
40+
export declare function create(): Route;
41+
//// [index.d.ts]
42+
import { A } from "./a";
43+
export type Label = A.FromA;
44+
export declare const route: import("./a").Route;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//// [tests/cases/compiler/declarationEmitCircularMergedExportAliases.ts] ////
2+
3+
=== a.ts ===
4+
export { B as A } from "./b";
5+
>B : Symbol(B, Decl(b.ts, 0, 8), Decl(b.ts, 0, 29))
6+
>A : Symbol(A, Decl(a.ts, 0, 8), Decl(a.ts, 0, 29))
7+
8+
export declare namespace A {
9+
>A : Symbol(A, Decl(a.ts, 0, 8), Decl(a.ts, 0, 29))
10+
11+
export type FromA = number;
12+
>FromA : Symbol(FromA, Decl(a.ts, 1, 28))
13+
}
14+
export class Route {
15+
>Route : Symbol(Route, Decl(a.ts, 3, 1))
16+
17+
private parts = 0;
18+
>parts : Symbol(Route.parts, Decl(a.ts, 4, 20))
19+
}
20+
export function create() { return new Route(); }
21+
>create : Symbol(create, Decl(a.ts, 6, 1))
22+
>Route : Symbol(Route, Decl(a.ts, 3, 1))
23+
24+
=== b.ts ===
25+
export { A as B } from "./a";
26+
>A : Symbol(A, Decl(a.ts, 0, 8), Decl(a.ts, 0, 29))
27+
>B : Symbol(B, Decl(b.ts, 0, 8), Decl(b.ts, 0, 29))
28+
29+
export declare namespace B {
30+
>B : Symbol(B, Decl(b.ts, 0, 8), Decl(b.ts, 0, 29))
31+
32+
export type FromB = string;
33+
>FromB : Symbol(FromB, Decl(b.ts, 1, 28))
34+
}
35+
36+
=== index.ts ===
37+
import { A } from "./a";
38+
>A : Symbol(A, Decl(index.ts, 0, 8))
39+
40+
import { create } from "./a";
41+
>create : Symbol(create, Decl(index.ts, 1, 8))
42+
43+
export type Label = A.FromA;
44+
>Label : Symbol(Label, Decl(index.ts, 1, 29))
45+
>A : Symbol(A, Decl(index.ts, 0, 8))
46+
>FromA : Symbol(A.FromA, Decl(a.ts, 1, 28))
47+
48+
export const route = create();
49+
>route : Symbol(route, Decl(index.ts, 3, 12))
50+
>create : Symbol(create, Decl(index.ts, 1, 8))
51+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//// [tests/cases/compiler/declarationEmitCircularMergedExportAliases.ts] ////
2+
3+
=== a.ts ===
4+
export { B as A } from "./b";
5+
>B : any
6+
>A : any
7+
8+
export declare namespace A {
9+
export type FromA = number;
10+
>FromA : number
11+
}
12+
export class Route {
13+
>Route : Route
14+
15+
private parts = 0;
16+
>parts : number
17+
>0 : 0
18+
}
19+
export function create() { return new Route(); }
20+
>create : () => Route
21+
>new Route() : Route
22+
>Route : typeof Route
23+
24+
=== b.ts ===
25+
export { A as B } from "./a";
26+
>A : any
27+
>B : any
28+
29+
export declare namespace B {
30+
export type FromB = string;
31+
>FromB : string
32+
}
33+
34+
=== index.ts ===
35+
import { A } from "./a";
36+
>A : any
37+
38+
import { create } from "./a";
39+
>create : () => import("./a").Route
40+
41+
export type Label = A.FromA;
42+
>Label : number
43+
>A : any
44+
45+
export const route = create();
46+
>route : import("./a").Route
47+
>create() : import("./a").Route
48+
>create : () => import("./a").Route
49+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/declarationEmitDefaultImportPrivateClass.ts] ////
2+
3+
//// [route.d.ts]
4+
export type Schema = unknown;
5+
declare class Route {
6+
private parts;
7+
}
8+
export = Route;
9+
10+
//// [index.ts]
11+
import Route from "./route";
12+
export const route = new Route();
13+
14+
15+
16+
//// [index.d.ts]
17+
import Route from "./route";
18+
export declare const route: Route;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [tests/cases/compiler/declarationEmitDefaultImportPrivateClass.ts] ////
2+
3+
=== route.d.ts ===
4+
export type Schema = unknown;
5+
>Schema : Symbol(Schema, Decl(route.d.ts, 0, 0))
6+
7+
declare class Route {
8+
>Route : Symbol(Route, Decl(route.d.ts, 0, 29))
9+
10+
private parts;
11+
>parts : Symbol(Route.parts, Decl(route.d.ts, 1, 21))
12+
}
13+
export = Route;
14+
>Route : Symbol(Route, Decl(route.d.ts, 0, 29))
15+
16+
=== index.ts ===
17+
import Route from "./route";
18+
>Route : Symbol(Route, Decl(index.ts, 0, 6))
19+
20+
export const route = new Route();
21+
>route : Symbol(route, Decl(index.ts, 1, 12))
22+
>Route : Symbol(Route, Decl(index.ts, 0, 6))
23+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/compiler/declarationEmitDefaultImportPrivateClass.ts] ////
2+
3+
=== route.d.ts ===
4+
export type Schema = unknown;
5+
>Schema : unknown
6+
7+
declare class Route {
8+
>Route : Route
9+
10+
private parts;
11+
>parts : any
12+
}
13+
export = Route;
14+
>Route : Route
15+
16+
=== index.ts ===
17+
import Route from "./route";
18+
>Route : typeof Route
19+
20+
export const route = new Route();
21+
>route : Route
22+
>new Route() : Route
23+
>Route : typeof Route
24+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/declarationEmitDefaultImportPrivateClass.ts] ////
2+
3+
//// [route.d.ts]
4+
export type Schema = unknown;
5+
declare class Route {
6+
private parts;
7+
}
8+
export = Route;
9+
10+
//// [index.ts]
11+
import Route from "./route";
12+
export const route = new Route();
13+
14+
15+
16+
//// [index.d.ts]
17+
import Route from "./route";
18+
export declare const route: Route;

0 commit comments

Comments
 (0)