First in UMD global wins

Fixes #9771
This commit is contained in:
Ryan Cavanaugh 2016-08-26 08:49:43 -07:00
parent c72f5e28e8
commit 0116abdcf2
5 changed files with 103 additions and 1 deletions

View File

@ -18763,7 +18763,13 @@ namespace ts {
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
}
if (file.symbol && file.symbol.globalExports) {
mergeSymbolTable(globals, file.symbol.globalExports);
// Merge in UMD exports with first-in-wins semantics (see #9771)
const source = file.symbol.globalExports;
for (const id in source) {
if (!(id in globals)) {
globals[id] = source[id];
}
}
}
});

View File

@ -0,0 +1,23 @@
//// [tests/cases/compiler/umdGlobalConflict.ts] ////
//// [index.d.ts]
export as namespace Alpha;
export var x: string;
//// [index.d.ts]
export as namespace Alpha;
export var y: number;
//// [consumer.ts]
import * as v1 from './v1';
import * as v2 from './v2';
//// [global.ts]
// Should be OK, first in wins
const p: string = Alpha.x;
//// [consumer.js]
"use strict";
//// [global.js]
// Should be OK, first in wins
var p = Alpha.x;

View File

@ -0,0 +1,29 @@
=== tests/cases/compiler/v1/index.d.ts ===
export as namespace Alpha;
>Alpha : Symbol(Alpha, Decl(index.d.ts, 0, 0))
export var x: string;
>x : Symbol(x, Decl(index.d.ts, 1, 10))
=== tests/cases/compiler/v2/index.d.ts ===
export as namespace Alpha;
>Alpha : Symbol(Alpha, Decl(index.d.ts, 0, 0))
export var y: number;
>y : Symbol(y, Decl(index.d.ts, 1, 10))
=== tests/cases/compiler/consumer.ts ===
import * as v1 from './v1';
>v1 : Symbol(v1, Decl(consumer.ts, 0, 6))
import * as v2 from './v2';
>v2 : Symbol(v2, Decl(consumer.ts, 1, 6))
=== tests/cases/compiler/global.ts ===
// Should be OK, first in wins
const p: string = Alpha.x;
>p : Symbol(p, Decl(global.ts, 1, 5))
>Alpha.x : Symbol(Alpha.x, Decl(index.d.ts, 1, 10))
>Alpha : Symbol(Alpha, Decl(index.d.ts, 0, 0))
>x : Symbol(Alpha.x, Decl(index.d.ts, 1, 10))

View File

@ -0,0 +1,29 @@
=== tests/cases/compiler/v1/index.d.ts ===
export as namespace Alpha;
>Alpha : typeof Alpha
export var x: string;
>x : string
=== tests/cases/compiler/v2/index.d.ts ===
export as namespace Alpha;
>Alpha : typeof
export var y: number;
>y : number
=== tests/cases/compiler/consumer.ts ===
import * as v1 from './v1';
>v1 : typeof v1
import * as v2 from './v2';
>v2 : typeof v2
=== tests/cases/compiler/global.ts ===
// Should be OK, first in wins
const p: string = Alpha.x;
>p : string
>Alpha.x : string
>Alpha : typeof Alpha
>x : string

View File

@ -0,0 +1,15 @@
//@filename: v1/index.d.ts
export as namespace Alpha;
export var x: string;
//@filename: v2/index.d.ts
export as namespace Alpha;
export var y: number;
//@filename: consumer.ts
import * as v1 from './v1';
import * as v2 from './v2';
//@filename: global.ts
// Should be OK, first in wins
const p: string = Alpha.x;