Skip to content

Commit 0116abd

Browse files
committed
First in UMD global wins
Fixes microsoft#9771
1 parent c72f5e2 commit 0116abd

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

src/compiler/checker.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -18763,7 +18763,13 @@ namespace ts {
1876318763
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
1876418764
}
1876518765
if (file.symbol && file.symbol.globalExports) {
18766-
mergeSymbolTable(globals, file.symbol.globalExports);
18766+
// Merge in UMD exports with first-in-wins semantics (see #9771)
18767+
const source = file.symbol.globalExports;
18768+
for (const id in source) {
18769+
if (!(id in globals)) {
18770+
globals[id] = source[id];
18771+
}
18772+
}
1876718773
}
1876818774
});
1876918775

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 = Alpha.x;
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 : Symbol(Alpha, Decl(index.d.ts, 0, 0))
4+
5+
export var x: string;
6+
>x : Symbol(x, Decl(index.d.ts, 1, 10))
7+
8+
=== tests/cases/compiler/v2/index.d.ts ===
9+
export as namespace Alpha;
10+
>Alpha : Symbol(Alpha, Decl(index.d.ts, 0, 0))
11+
12+
export var y: number;
13+
>y : Symbol(y, Decl(index.d.ts, 1, 10))
14+
15+
=== tests/cases/compiler/consumer.ts ===
16+
import * as v1 from './v1';
17+
>v1 : Symbol(v1, Decl(consumer.ts, 0, 6))
18+
19+
import * as v2 from './v2';
20+
>v2 : Symbol(v2, Decl(consumer.ts, 1, 6))
21+
22+
=== tests/cases/compiler/global.ts ===
23+
// Should be OK, first in wins
24+
const p: string = Alpha.x;
25+
>p : Symbol(p, Decl(global.ts, 1, 5))
26+
>Alpha.x : Symbol(Alpha.x, Decl(index.d.ts, 1, 10))
27+
>Alpha : Symbol(Alpha, Decl(index.d.ts, 0, 0))
28+
>x : Symbol(Alpha.x, Decl(index.d.ts, 1, 10))
29+
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 : typeof Alpha
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 : typeof
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+
+15
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)