correctly merge const enum only and instantiated modules

This commit is contained in:
Vladimir Matveev 2015-03-16 19:51:22 -07:00
parent c4cb3e3483
commit 74eb96a5b9
4 changed files with 83 additions and 6 deletions

View File

@ -322,13 +322,14 @@ module ts {
}
else {
bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true);
if (state === ModuleInstanceState.ConstEnumOnly) {
// mark value module as module that contains only enums
node.symbol.constEnumOnlyModule = true;
let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
if (node.symbol.constEnumOnlyModule === undefined) {
// non-merged case - use the current state
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
}
else if (node.symbol.constEnumOnlyModule) {
// const only value module was merged with instantiated module - reset flag
node.symbol.constEnumOnlyModule = false;
else {
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
}
}
}

View File

@ -0,0 +1,26 @@
//// [constEnumOnlyModuleMerging.ts]
module Outer {
export var x = 1;
}
module Outer {
export const enum A { X }
}
module B {
import O = Outer;
var x = O.A.X;
var y = O.x;
}
//// [constEnumOnlyModuleMerging.js]
var Outer;
(function (Outer) {
Outer.x = 1;
})(Outer || (Outer = {}));
var B;
(function (B) {
var O = Outer;
var x = 0 /* X */;
var y = O.x;
})(B || (B = {}));

View File

@ -0,0 +1,37 @@
=== tests/cases/compiler/constEnumOnlyModuleMerging.ts ===
module Outer {
>Outer : typeof Outer
export var x = 1;
>x : number
}
module Outer {
>Outer : typeof Outer
export const enum A { X }
>A : A
>X : A
}
module B {
>B : typeof B
import O = Outer;
>O : typeof O
>Outer : typeof O
var x = O.A.X;
>x : O.A
>O.A.X : O.A
>O.A : typeof O.A
>O : typeof O
>A : typeof O.A
>X : O.A
var y = O.x;
>y : number
>O.x : number
>O : typeof O
>x : number
}

View File

@ -0,0 +1,13 @@
module Outer {
export var x = 1;
}
module Outer {
export const enum A { X }
}
module B {
import O = Outer;
var x = O.A.X;
var y = O.x;
}