mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
treat modules that are merged with values as non-const-enum
This commit is contained in:
parent
96b02a83ca
commit
43347c79ec
@ -518,15 +518,21 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
|
||||
|
||||
let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
|
||||
if (node.symbol.constEnumOnlyModule === undefined) {
|
||||
// non-merged case - use the current state
|
||||
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
|
||||
if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) {
|
||||
// if module was already merged with some function, class or non-const enum
|
||||
// treat is a non-const-enum-only
|
||||
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;
|
||||
let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly;
|
||||
if (node.symbol.constEnumOnlyModule === undefined) {
|
||||
// non-merged case - use the current state
|
||||
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1056,4 +1062,4 @@ namespace ts {
|
||||
: declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14028,7 +14028,11 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
// const enums and modules that contain only const enums are not considered values from the emit perespective
|
||||
return target !== unknownSymbol && target && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target);
|
||||
// unless 'preserveConstEnums' option is set to true
|
||||
return target !== unknownSymbol &&
|
||||
target &&
|
||||
target.flags & SymbolFlags.Value &&
|
||||
(compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target));
|
||||
}
|
||||
|
||||
function isConstEnumOrConstEnumOnlyModule(s: Symbol): boolean {
|
||||
|
||||
14
tests/baselines/reference/constEnumMergingWithValues1.js
Normal file
14
tests/baselines/reference/constEnumMergingWithValues1.js
Normal file
@ -0,0 +1,14 @@
|
||||
//// [constEnumMergingWithValues1.ts]
|
||||
|
||||
function foo() {}
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
export = foo
|
||||
|
||||
//// [constEnumMergingWithValues1.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
function foo() { }
|
||||
return foo;
|
||||
});
|
||||
@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues1.ts ===
|
||||
|
||||
function foo() {}
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues1.ts, 0, 0), Decl(constEnumMergingWithValues1.ts, 1, 17))
|
||||
|
||||
module foo {
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues1.ts, 0, 0), Decl(constEnumMergingWithValues1.ts, 1, 17))
|
||||
|
||||
const enum E { X }
|
||||
>E : Symbol(E, Decl(constEnumMergingWithValues1.ts, 2, 12))
|
||||
>X : Symbol(E.X, Decl(constEnumMergingWithValues1.ts, 3, 18))
|
||||
}
|
||||
|
||||
export = foo
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues1.ts, 0, 0), Decl(constEnumMergingWithValues1.ts, 1, 17))
|
||||
|
||||
16
tests/baselines/reference/constEnumMergingWithValues1.types
Normal file
16
tests/baselines/reference/constEnumMergingWithValues1.types
Normal file
@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues1.ts ===
|
||||
|
||||
function foo() {}
|
||||
>foo : typeof foo
|
||||
|
||||
module foo {
|
||||
>foo : typeof foo
|
||||
|
||||
const enum E { X }
|
||||
>E : E
|
||||
>X : E
|
||||
}
|
||||
|
||||
export = foo
|
||||
>foo : typeof foo
|
||||
|
||||
18
tests/baselines/reference/constEnumMergingWithValues2.js
Normal file
18
tests/baselines/reference/constEnumMergingWithValues2.js
Normal file
@ -0,0 +1,18 @@
|
||||
//// [constEnumMergingWithValues2.ts]
|
||||
|
||||
class foo {}
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
export = foo
|
||||
|
||||
//// [constEnumMergingWithValues2.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
var foo = (function () {
|
||||
function foo() {
|
||||
}
|
||||
return foo;
|
||||
})();
|
||||
return foo;
|
||||
});
|
||||
@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues2.ts ===
|
||||
|
||||
class foo {}
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues2.ts, 0, 0), Decl(constEnumMergingWithValues2.ts, 1, 12))
|
||||
|
||||
module foo {
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues2.ts, 0, 0), Decl(constEnumMergingWithValues2.ts, 1, 12))
|
||||
|
||||
const enum E { X }
|
||||
>E : Symbol(E, Decl(constEnumMergingWithValues2.ts, 2, 12))
|
||||
>X : Symbol(E.X, Decl(constEnumMergingWithValues2.ts, 3, 18))
|
||||
}
|
||||
|
||||
export = foo
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues2.ts, 0, 0), Decl(constEnumMergingWithValues2.ts, 1, 12))
|
||||
|
||||
16
tests/baselines/reference/constEnumMergingWithValues2.types
Normal file
16
tests/baselines/reference/constEnumMergingWithValues2.types
Normal file
@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues2.ts ===
|
||||
|
||||
class foo {}
|
||||
>foo : foo
|
||||
|
||||
module foo {
|
||||
>foo : typeof foo
|
||||
|
||||
const enum E { X }
|
||||
>E : E
|
||||
>X : E
|
||||
}
|
||||
|
||||
export = foo
|
||||
>foo : foo
|
||||
|
||||
17
tests/baselines/reference/constEnumMergingWithValues3.js
Normal file
17
tests/baselines/reference/constEnumMergingWithValues3.js
Normal file
@ -0,0 +1,17 @@
|
||||
//// [constEnumMergingWithValues3.ts]
|
||||
|
||||
enum foo { A }
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
export = foo
|
||||
|
||||
//// [constEnumMergingWithValues3.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
var foo;
|
||||
(function (foo) {
|
||||
foo[foo["A"] = 0] = "A";
|
||||
})(foo || (foo = {}));
|
||||
return foo;
|
||||
});
|
||||
@ -0,0 +1,17 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues3.ts ===
|
||||
|
||||
enum foo { A }
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues3.ts, 0, 0), Decl(constEnumMergingWithValues3.ts, 1, 14))
|
||||
>A : Symbol(foo.A, Decl(constEnumMergingWithValues3.ts, 1, 10))
|
||||
|
||||
module foo {
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues3.ts, 0, 0), Decl(constEnumMergingWithValues3.ts, 1, 14))
|
||||
|
||||
const enum E { X }
|
||||
>E : Symbol(E, Decl(constEnumMergingWithValues3.ts, 2, 12))
|
||||
>X : Symbol(E.X, Decl(constEnumMergingWithValues3.ts, 3, 18))
|
||||
}
|
||||
|
||||
export = foo
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues3.ts, 0, 0), Decl(constEnumMergingWithValues3.ts, 1, 14))
|
||||
|
||||
17
tests/baselines/reference/constEnumMergingWithValues3.types
Normal file
17
tests/baselines/reference/constEnumMergingWithValues3.types
Normal file
@ -0,0 +1,17 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues3.ts ===
|
||||
|
||||
enum foo { A }
|
||||
>foo : foo
|
||||
>A : foo
|
||||
|
||||
module foo {
|
||||
>foo : typeof foo
|
||||
|
||||
const enum E { X }
|
||||
>E : E
|
||||
>X : E
|
||||
}
|
||||
|
||||
export = foo
|
||||
>foo : foo
|
||||
|
||||
21
tests/baselines/reference/constEnumMergingWithValues4.js
Normal file
21
tests/baselines/reference/constEnumMergingWithValues4.js
Normal file
@ -0,0 +1,21 @@
|
||||
//// [constEnumMergingWithValues4.ts]
|
||||
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
module foo {
|
||||
var x = 1;
|
||||
}
|
||||
|
||||
|
||||
export = foo
|
||||
|
||||
//// [constEnumMergingWithValues4.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
var foo;
|
||||
(function (foo) {
|
||||
var x = 1;
|
||||
})(foo || (foo = {}));
|
||||
return foo;
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues4.ts ===
|
||||
|
||||
module foo {
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues4.ts, 0, 0), Decl(constEnumMergingWithValues4.ts, 3, 1))
|
||||
|
||||
const enum E { X }
|
||||
>E : Symbol(E, Decl(constEnumMergingWithValues4.ts, 1, 12))
|
||||
>X : Symbol(E.X, Decl(constEnumMergingWithValues4.ts, 2, 18))
|
||||
}
|
||||
|
||||
module foo {
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues4.ts, 0, 0), Decl(constEnumMergingWithValues4.ts, 3, 1))
|
||||
|
||||
var x = 1;
|
||||
>x : Symbol(x, Decl(constEnumMergingWithValues4.ts, 6, 7))
|
||||
}
|
||||
|
||||
|
||||
export = foo
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues4.ts, 0, 0), Decl(constEnumMergingWithValues4.ts, 3, 1))
|
||||
|
||||
22
tests/baselines/reference/constEnumMergingWithValues4.types
Normal file
22
tests/baselines/reference/constEnumMergingWithValues4.types
Normal file
@ -0,0 +1,22 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues4.ts ===
|
||||
|
||||
module foo {
|
||||
>foo : typeof foo
|
||||
|
||||
const enum E { X }
|
||||
>E : E
|
||||
>X : E
|
||||
}
|
||||
|
||||
module foo {
|
||||
>foo : typeof foo
|
||||
|
||||
var x = 1;
|
||||
>x : number
|
||||
>1 : number
|
||||
}
|
||||
|
||||
|
||||
export = foo
|
||||
>foo : typeof foo
|
||||
|
||||
19
tests/baselines/reference/constEnumMergingWithValues5.js
Normal file
19
tests/baselines/reference/constEnumMergingWithValues5.js
Normal file
@ -0,0 +1,19 @@
|
||||
//// [constEnumMergingWithValues5.ts]
|
||||
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
export = foo
|
||||
|
||||
//// [constEnumMergingWithValues5.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
var foo;
|
||||
(function (foo) {
|
||||
var E;
|
||||
(function (E) {
|
||||
E[E["X"] = 0] = "X";
|
||||
})(E || (E = {}));
|
||||
})(foo || (foo = {}));
|
||||
return foo;
|
||||
});
|
||||
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues5.ts ===
|
||||
|
||||
module foo {
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues5.ts, 0, 0))
|
||||
|
||||
const enum E { X }
|
||||
>E : Symbol(E, Decl(constEnumMergingWithValues5.ts, 1, 12))
|
||||
>X : Symbol(E.X, Decl(constEnumMergingWithValues5.ts, 2, 18))
|
||||
}
|
||||
|
||||
export = foo
|
||||
>foo : Symbol(foo, Decl(constEnumMergingWithValues5.ts, 0, 0))
|
||||
|
||||
13
tests/baselines/reference/constEnumMergingWithValues5.types
Normal file
13
tests/baselines/reference/constEnumMergingWithValues5.types
Normal file
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/constEnumMergingWithValues5.ts ===
|
||||
|
||||
module foo {
|
||||
>foo : typeof foo
|
||||
|
||||
const enum E { X }
|
||||
>E : E
|
||||
>X : E
|
||||
}
|
||||
|
||||
export = foo
|
||||
>foo : typeof foo
|
||||
|
||||
9
tests/cases/compiler/constEnumMergingWithValues1.ts
Normal file
9
tests/cases/compiler/constEnumMergingWithValues1.ts
Normal file
@ -0,0 +1,9 @@
|
||||
//@module: amd
|
||||
//@filename: m1.ts
|
||||
|
||||
function foo() {}
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
export = foo
|
||||
9
tests/cases/compiler/constEnumMergingWithValues2.ts
Normal file
9
tests/cases/compiler/constEnumMergingWithValues2.ts
Normal file
@ -0,0 +1,9 @@
|
||||
//@module: amd
|
||||
//@filename: m1.ts
|
||||
|
||||
class foo {}
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
export = foo
|
||||
9
tests/cases/compiler/constEnumMergingWithValues3.ts
Normal file
9
tests/cases/compiler/constEnumMergingWithValues3.ts
Normal file
@ -0,0 +1,9 @@
|
||||
//@module: amd
|
||||
//@filename: m1.ts
|
||||
|
||||
enum foo { A }
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
export = foo
|
||||
13
tests/cases/compiler/constEnumMergingWithValues4.ts
Normal file
13
tests/cases/compiler/constEnumMergingWithValues4.ts
Normal file
@ -0,0 +1,13 @@
|
||||
//@module: amd
|
||||
//@filename: m1.ts
|
||||
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
module foo {
|
||||
var x = 1;
|
||||
}
|
||||
|
||||
|
||||
export = foo
|
||||
9
tests/cases/compiler/constEnumMergingWithValues5.ts
Normal file
9
tests/cases/compiler/constEnumMergingWithValues5.ts
Normal file
@ -0,0 +1,9 @@
|
||||
//@module: amd
|
||||
//@filename: m1.ts
|
||||
//@preserveConstEnums: true
|
||||
|
||||
module foo {
|
||||
const enum E { X }
|
||||
}
|
||||
|
||||
export = foo
|
||||
Loading…
x
Reference in New Issue
Block a user