Skip to content

Commit a301ee3

Browse files
committed
Merge pull request #2382 from Microsoft/mergingConstEnumOnlyModules
correctly merge const enum only and instantiated modules irregardless of order
2 parents 42b711b + 74eb96a commit a301ee3

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
lines changed

src/compiler/binder.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,14 @@ module ts {
322322
}
323323
else {
324324
bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true);
325-
if (state === ModuleInstanceState.ConstEnumOnly) {
326-
// mark value module as module that contains only enums
327-
node.symbol.constEnumOnlyModule = true;
325+
let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
326+
if (node.symbol.constEnumOnlyModule === undefined) {
327+
// non-merged case - use the current state
328+
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
328329
}
329-
else if (node.symbol.constEnumOnlyModule) {
330-
// const only value module was merged with instantiated module - reset flag
331-
node.symbol.constEnumOnlyModule = false;
330+
else {
331+
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
332+
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
332333
}
333334
}
334335
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [constEnumOnlyModuleMerging.ts]
2+
module Outer {
3+
export var x = 1;
4+
}
5+
6+
module Outer {
7+
export const enum A { X }
8+
}
9+
10+
module B {
11+
import O = Outer;
12+
var x = O.A.X;
13+
var y = O.x;
14+
}
15+
16+
//// [constEnumOnlyModuleMerging.js]
17+
var Outer;
18+
(function (Outer) {
19+
Outer.x = 1;
20+
})(Outer || (Outer = {}));
21+
var B;
22+
(function (B) {
23+
var O = Outer;
24+
var x = 0 /* X */;
25+
var y = O.x;
26+
})(B || (B = {}));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/constEnumOnlyModuleMerging.ts ===
2+
module Outer {
3+
>Outer : typeof Outer
4+
5+
export var x = 1;
6+
>x : number
7+
}
8+
9+
module Outer {
10+
>Outer : typeof Outer
11+
12+
export const enum A { X }
13+
>A : A
14+
>X : A
15+
}
16+
17+
module B {
18+
>B : typeof B
19+
20+
import O = Outer;
21+
>O : typeof O
22+
>Outer : typeof O
23+
24+
var x = O.A.X;
25+
>x : O.A
26+
>O.A.X : O.A
27+
>O.A : typeof O.A
28+
>O : typeof O
29+
>A : typeof O.A
30+
>X : O.A
31+
32+
var y = O.x;
33+
>y : number
34+
>O.x : number
35+
>O : typeof O
36+
>x : number
37+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Outer {
2+
export var x = 1;
3+
}
4+
5+
module Outer {
6+
export const enum A { X }
7+
}
8+
9+
module B {
10+
import O = Outer;
11+
var x = O.A.X;
12+
var y = O.x;
13+
}

0 commit comments

Comments
 (0)