Skip to content

Commit

Permalink
Merge pull request #10354 from RyanCavanaugh/fix9771
Browse files Browse the repository at this point in the history
First in UMD global wins
  • Loading branch information
RyanCavanaugh authored Aug 26, 2016
2 parents c72f5e2 + 0116abd commit b0f7f2f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
});

Expand Down
23 changes: 23 additions & 0 deletions tests/baselines/reference/umdGlobalConflict.js
Original file line number Diff line number Diff line change
@@ -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;
29 changes: 29 additions & 0 deletions tests/baselines/reference/umdGlobalConflict.symbols
Original file line number Diff line number Diff line change
@@ -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))

29 changes: 29 additions & 0 deletions tests/baselines/reference/umdGlobalConflict.types
Original file line number Diff line number Diff line change
@@ -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

15 changes: 15 additions & 0 deletions tests/cases/compiler/umdGlobalConflict.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit b0f7f2f

Please sign in to comment.