mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
correctly merge const enum only and instantiated modules
This commit is contained in:
parent
c4cb3e3483
commit
74eb96a5b9
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
tests/baselines/reference/constEnumOnlyModuleMerging.js
Normal file
26
tests/baselines/reference/constEnumOnlyModuleMerging.js
Normal 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 = {}));
|
||||
37
tests/baselines/reference/constEnumOnlyModuleMerging.types
Normal file
37
tests/baselines/reference/constEnumOnlyModuleMerging.types
Normal 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
|
||||
}
|
||||
13
tests/cases/compiler/constEnumOnlyModuleMerging.ts
Normal file
13
tests/cases/compiler/constEnumOnlyModuleMerging.ts
Normal 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user