Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0116abd

Browse filesBrowse files
committed
First in UMD global wins
Fixes microsoft#9771
1 parent c72f5e2 commit 0116abd
Copy full SHA for 0116abd

5 files changed

+103-1Lines changed: 103 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+7-1Lines changed: 7 additions & 1 deletion
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

Collapse file
+23Lines 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 = Alpha.x;
Collapse file
+29Lines 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 : 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+
Collapse file
+29Lines 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 : 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+
Collapse file
+15Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.