Skip to content

Commit f405731

Browse files
gwklineclaude
andcommitted
Add test for export * name collisions
Covers the cases the export * merge distinguishes: colliding names from two and three declarations, the same symbol reached twice, a module's own export silencing the collision, a single export *, export type * on either side, and a chain of re-exporting modules. Baselines were generated before the merge was rewritten and are unchanged by it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f3fdfce commit f405731

5 files changed

Lines changed: 645 additions & 0 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
consumer.ts(9,58): error TS1362: 'a5' cannot be used as a value because it was exported using 'export type'.
2+
consumer.ts(9,70): error TS1362: 'b6' cannot be used as a value because it was exported using 'export type'.
3+
localShadows.ts(3,1): error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
4+
threeStarsCollide.ts(3,1): error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
5+
threeStarsCollide.ts(3,1): error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
6+
threeStarsCollide.ts(4,1): error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
7+
twoStarsCollide.ts(3,1): error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
8+
twoStarsCollide.ts(3,1): error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
9+
typeOnlyThenValue.ts(2,1): error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
10+
typeOnlyThenValue.ts(2,1): error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
11+
valueThenTypeOnly.ts(2,1): error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
12+
valueThenTypeOnly.ts(2,1): error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
13+
14+
15+
==== a.ts (0 errors) ====
16+
export const onlyA = 1;
17+
export const shared = "a";
18+
export interface SharedType { fromA: true }
19+
export default "a";
20+
21+
==== b.ts (0 errors) ====
22+
export const onlyB = 2;
23+
export const shared = "b";
24+
export interface SharedType { fromB: true }
25+
export default "b";
26+
27+
==== b2.ts (0 errors) ====
28+
export const shared = "b2";
29+
30+
==== sameSymbol.ts (0 errors) ====
31+
export { shared } from "./a";
32+
33+
==== twoStarsCollide.ts (2 errors) ====
34+
// 'shared' and 'SharedType' come from both modules with different meanings.
35+
export * from "./a";
36+
export * from "./b";
37+
~~~~~~~~~~~~~~~~~~~~
38+
!!! error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
39+
~~~~~~~~~~~~~~~~~~~~
40+
!!! error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
41+
42+
==== threeStarsCollide.ts (3 errors) ====
43+
// Both later declarations are reported against the first one.
44+
export * from "./a";
45+
export * from "./b";
46+
~~~~~~~~~~~~~~~~~~~~
47+
!!! error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
48+
~~~~~~~~~~~~~~~~~~~~
49+
!!! error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
50+
export * from "./b2";
51+
~~~~~~~~~~~~~~~~~~~~~
52+
!!! error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
53+
54+
==== sameSymbolTwice.ts (0 errors) ====
55+
// Reaching the same symbol through two declarations is not a collision.
56+
export * from "./a";
57+
export * from "./sameSymbol";
58+
59+
==== localShadows.ts (1 errors) ====
60+
// A module's own export takes precedence and silences the collision.
61+
export * from "./a";
62+
export * from "./b";
63+
~~~~~~~~~~~~~~~~~~~~
64+
!!! error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
65+
export const shared = "local";
66+
67+
==== singleStar.ts (0 errors) ====
68+
export * from "./a";
69+
70+
==== typeOnlyThenValue.ts (2 errors) ====
71+
export type * from "./a";
72+
export * from "./b";
73+
~~~~~~~~~~~~~~~~~~~~
74+
!!! error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
75+
~~~~~~~~~~~~~~~~~~~~
76+
!!! error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
77+
78+
==== valueThenTypeOnly.ts (2 errors) ====
79+
export * from "./a";
80+
export type * from "./b";
81+
~~~~~~~~~~~~~~~~~~~~~~~~~
82+
!!! error TS2308: Module "./a" has already exported a member named 'SharedType'. Consider explicitly re-exporting to resolve the ambiguity.
83+
~~~~~~~~~~~~~~~~~~~~~~~~~
84+
!!! error TS2308: Module "./a" has already exported a member named 'shared'. Consider explicitly re-exporting to resolve the ambiguity.
85+
86+
==== chained.ts (0 errors) ====
87+
export * from "./twoStarsCollide";
88+
export * from "./singleStar";
89+
90+
==== consumer.ts (2 errors) ====
91+
import { onlyA, onlyB, shared as s1 } from "./twoStarsCollide";
92+
import { shared as s2 } from "./sameSymbolTwice";
93+
import { shared as s3 } from "./localShadows";
94+
import { shared as s4, onlyA as a4 } from "./singleStar";
95+
import { onlyA as a5, onlyB as b5 } from "./typeOnlyThenValue";
96+
import { onlyA as a6, onlyB as b6 } from "./valueThenTypeOnly";
97+
import { onlyA as a7, onlyB as b7, shared as s7 } from "./chained";
98+
import type { SharedType } from "./twoStarsCollide";
99+
export const values = [onlyA, onlyB, s1, s2, s3, s4, a4, a5, b5, a6, b6, a7, b7, s7];
100+
~~
101+
!!! error TS1362: 'a5' cannot be used as a value because it was exported using 'export type'.
102+
!!! related TS1377 typeOnlyThenValue.ts:1:1: 'a5' was exported here.
103+
~~
104+
!!! error TS1362: 'b6' cannot be used as a value because it was exported using 'export type'.
105+
!!! related TS1377 valueThenTypeOnly.ts:2:1: 'b6' was exported here.
106+
export let t: SharedType | undefined;
107+
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
//// [tests/cases/compiler/exportStarNameCollisions.ts] ////
2+
3+
//// [a.ts]
4+
export const onlyA = 1;
5+
export const shared = "a";
6+
export interface SharedType { fromA: true }
7+
export default "a";
8+
9+
//// [b.ts]
10+
export const onlyB = 2;
11+
export const shared = "b";
12+
export interface SharedType { fromB: true }
13+
export default "b";
14+
15+
//// [b2.ts]
16+
export const shared = "b2";
17+
18+
//// [sameSymbol.ts]
19+
export { shared } from "./a";
20+
21+
//// [twoStarsCollide.ts]
22+
// 'shared' and 'SharedType' come from both modules with different meanings.
23+
export * from "./a";
24+
export * from "./b";
25+
26+
//// [threeStarsCollide.ts]
27+
// Both later declarations are reported against the first one.
28+
export * from "./a";
29+
export * from "./b";
30+
export * from "./b2";
31+
32+
//// [sameSymbolTwice.ts]
33+
// Reaching the same symbol through two declarations is not a collision.
34+
export * from "./a";
35+
export * from "./sameSymbol";
36+
37+
//// [localShadows.ts]
38+
// A module's own export takes precedence and silences the collision.
39+
export * from "./a";
40+
export * from "./b";
41+
export const shared = "local";
42+
43+
//// [singleStar.ts]
44+
export * from "./a";
45+
46+
//// [typeOnlyThenValue.ts]
47+
export type * from "./a";
48+
export * from "./b";
49+
50+
//// [valueThenTypeOnly.ts]
51+
export * from "./a";
52+
export type * from "./b";
53+
54+
//// [chained.ts]
55+
export * from "./twoStarsCollide";
56+
export * from "./singleStar";
57+
58+
//// [consumer.ts]
59+
import { onlyA, onlyB, shared as s1 } from "./twoStarsCollide";
60+
import { shared as s2 } from "./sameSymbolTwice";
61+
import { shared as s3 } from "./localShadows";
62+
import { shared as s4, onlyA as a4 } from "./singleStar";
63+
import { onlyA as a5, onlyB as b5 } from "./typeOnlyThenValue";
64+
import { onlyA as a6, onlyB as b6 } from "./valueThenTypeOnly";
65+
import { onlyA as a7, onlyB as b7, shared as s7 } from "./chained";
66+
import type { SharedType } from "./twoStarsCollide";
67+
export const values = [onlyA, onlyB, s1, s2, s3, s4, a4, a5, b5, a6, b6, a7, b7, s7];
68+
export let t: SharedType | undefined;
69+
70+
71+
//// [a.js]
72+
export const onlyA = 1;
73+
export const shared = "a";
74+
export default "a";
75+
//// [b.js]
76+
export const onlyB = 2;
77+
export const shared = "b";
78+
export default "b";
79+
//// [b2.js]
80+
export const shared = "b2";
81+
//// [sameSymbol.js]
82+
export { shared } from "./a";
83+
//// [twoStarsCollide.js]
84+
// 'shared' and 'SharedType' come from both modules with different meanings.
85+
export * from "./a";
86+
export * from "./b";
87+
//// [threeStarsCollide.js]
88+
// Both later declarations are reported against the first one.
89+
export * from "./a";
90+
export * from "./b";
91+
export * from "./b2";
92+
//// [sameSymbolTwice.js]
93+
// Reaching the same symbol through two declarations is not a collision.
94+
export * from "./a";
95+
export * from "./sameSymbol";
96+
//// [localShadows.js]
97+
// A module's own export takes precedence and silences the collision.
98+
export * from "./a";
99+
export * from "./b";
100+
export const shared = "local";
101+
//// [singleStar.js]
102+
export * from "./a";
103+
//// [typeOnlyThenValue.js]
104+
export * from "./b";
105+
//// [valueThenTypeOnly.js]
106+
export * from "./a";
107+
//// [chained.js]
108+
export * from "./twoStarsCollide";
109+
export * from "./singleStar";
110+
//// [consumer.js]
111+
import { onlyA, onlyB, shared as s1 } from "./twoStarsCollide";
112+
import { shared as s2 } from "./sameSymbolTwice";
113+
import { shared as s3 } from "./localShadows";
114+
import { shared as s4, onlyA as a4 } from "./singleStar";
115+
import { onlyB as b5 } from "./typeOnlyThenValue";
116+
import { onlyA as a6 } from "./valueThenTypeOnly";
117+
import { onlyA as a7, onlyB as b7, shared as s7 } from "./chained";
118+
export const values = [onlyA, onlyB, s1, s2, s3, s4, a4, a5, b5, a6, b6, a7, b7, s7];
119+
export let t;
120+
121+
122+
//// [a.d.ts]
123+
export declare const onlyA = 1;
124+
export declare const shared = "a";
125+
export interface SharedType {
126+
fromA: true;
127+
}
128+
declare const _default = "a";
129+
export default _default;
130+
//// [b.d.ts]
131+
export declare const onlyB = 2;
132+
export declare const shared = "b";
133+
export interface SharedType {
134+
fromB: true;
135+
}
136+
declare const _default = "b";
137+
export default _default;
138+
//// [b2.d.ts]
139+
export declare const shared = "b2";
140+
//// [sameSymbol.d.ts]
141+
export { shared } from "./a";
142+
//// [twoStarsCollide.d.ts]
143+
export * from "./a";
144+
export * from "./b";
145+
//// [threeStarsCollide.d.ts]
146+
export * from "./a";
147+
export * from "./b";
148+
export * from "./b2";
149+
//// [sameSymbolTwice.d.ts]
150+
export * from "./a";
151+
export * from "./sameSymbol";
152+
//// [localShadows.d.ts]
153+
export * from "./a";
154+
export * from "./b";
155+
export declare const shared = "local";
156+
//// [singleStar.d.ts]
157+
export * from "./a";
158+
//// [typeOnlyThenValue.d.ts]
159+
export type * from "./a";
160+
export * from "./b";
161+
//// [valueThenTypeOnly.d.ts]
162+
export * from "./a";
163+
export type * from "./b";
164+
//// [chained.d.ts]
165+
export * from "./twoStarsCollide";
166+
export * from "./singleStar";
167+
//// [consumer.d.ts]
168+
import type { SharedType } from "./twoStarsCollide";
169+
export declare const values: (string | number)[];
170+
export declare let t: SharedType | undefined;

0 commit comments

Comments
 (0)