Skip to content

Commit 9b37e3e

Browse files
committed
First UMD global in wins
1 parent cccf70b commit 9b37e3e

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17860,7 +17860,13 @@ namespace ts {
1786017860
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
1786117861
}
1786217862
if (file.symbol && file.symbol.globalExports) {
17863-
mergeSymbolTable(globals, file.symbol.globalExports);
17863+
// Merge in UMD exports with first-in-wins semantics (see #9771)
17864+
const source = file.symbol.globalExports;
17865+
for (const id in source) {
17866+
if (!hasProperty(globals, id)) {
17867+
globals[id] = source[id];
17868+
}
17869+
}
1786417870
}
1786517871
});
1786617872

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [tests/cases/compiler/umdGlobalConflict.ts] ////
2+
3+
//// [index.d.ts]
4+
export as namespace Alpha;
5+
export var x: string;
6+
7+
//// [index.d.ts]
8+
export as namespace Alpha;
9+
export var y: number;
10+
11+
//// [consumer.ts]
12+
import * as v1 from './v1';
13+
import * as v2 from './v2';
14+
15+
//// [global.ts]
16+
// Should be OK, first in wins
17+
const p: string = Alpha.x;
18+
19+
//// [consumer.js]
20+
"use strict";
21+
//// [global.js]
22+
// Should be OK, first in wins
23+
var p = exports.Alpha.x;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/compiler/v1/index.d.ts ===
2+
export as namespace Alpha;
3+
export var x: string;
4+
>x : Symbol(x, Decl(index.d.ts, 1, 10))
5+
6+
=== tests/cases/compiler/v2/index.d.ts ===
7+
export as namespace Alpha;
8+
export var y: number;
9+
>y : Symbol(y, Decl(index.d.ts, 1, 10))
10+
11+
=== tests/cases/compiler/consumer.ts ===
12+
import * as v1 from './v1';
13+
>v1 : Symbol(v1, Decl(consumer.ts, 0, 6))
14+
15+
import * as v2 from './v2';
16+
>v2 : Symbol(v2, Decl(consumer.ts, 1, 6))
17+
18+
=== tests/cases/compiler/global.ts ===
19+
// Should be OK, first in wins
20+
const p: string = Alpha.x;
21+
>p : Symbol(p, Decl(global.ts, 1, 5))
22+
>Alpha.x : Symbol(Alpha.x, Decl(index.d.ts, 1, 10))
23+
>Alpha : Symbol(Alpha, Decl(index.d.ts, 0, 0))
24+
>x : Symbol(Alpha.x, Decl(index.d.ts, 1, 10))
25+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/v1/index.d.ts ===
2+
export as namespace Alpha;
3+
>Alpha : any
4+
5+
export var x: string;
6+
>x : string
7+
8+
=== tests/cases/compiler/v2/index.d.ts ===
9+
export as namespace Alpha;
10+
>Alpha : any
11+
12+
export var y: number;
13+
>y : number
14+
15+
=== tests/cases/compiler/consumer.ts ===
16+
import * as v1 from './v1';
17+
>v1 : typeof v1
18+
19+
import * as v2 from './v2';
20+
>v2 : typeof v2
21+
22+
=== tests/cases/compiler/global.ts ===
23+
// Should be OK, first in wins
24+
const p: string = Alpha.x;
25+
>p : string
26+
>Alpha.x : string
27+
>Alpha : typeof Alpha
28+
>x : string
29+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@filename: v1/index.d.ts
2+
export as namespace Alpha;
3+
export var x: string;
4+
5+
//@filename: v2/index.d.ts
6+
export as namespace Alpha;
7+
export var y: number;
8+
9+
//@filename: consumer.ts
10+
import * as v1 from './v1';
11+
import * as v2 from './v2';
12+
13+
//@filename: global.ts
14+
// Should be OK, first in wins
15+
const p: string = Alpha.x;

0 commit comments

Comments
 (0)