Fix enums and namespace merge (#47059)

* Fix enums and namespace merge

* Remove unused comment
This commit is contained in:
Armando Aguirre
2021-12-13 14:03:19 -08:00
committed by GitHub
parent 430599722e
commit 67872a50d0
6 changed files with 63 additions and 1 deletions

View File

@@ -39397,7 +39397,7 @@ namespace ts {
if (memberSymbol) {
const declaration = memberSymbol.valueDeclaration;
if (declaration !== member) {
if (declaration && isBlockScopedNameDeclaredBeforeUse(declaration, member)) {
if (declaration && isBlockScopedNameDeclaredBeforeUse(declaration, member) && isEnumDeclaration(declaration.parent)) {
return getEnumMemberValue(declaration as EnumMember);
}
error(expr, Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);

View File

@@ -0,0 +1,12 @@
tests/cases/compiler/enumWithExport.ts(5,7): error TS2651: A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums.
==== tests/cases/compiler/enumWithExport.ts (1 errors) ====
namespace x {
export let y = 123
}
enum x {
z = y
~
!!! error TS2651: A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums.
}

View File

@@ -0,0 +1,16 @@
//// [enumWithExport.ts]
namespace x {
export let y = 123
}
enum x {
z = y
}
//// [enumWithExport.js]
var x;
(function (x) {
x.y = 123;
})(x || (x = {}));
(function (x) {
x[x["z"] = 0] = "z";
})(x || (x = {}));

View File

@@ -0,0 +1,13 @@
=== tests/cases/compiler/enumWithExport.ts ===
namespace x {
>x : Symbol(x, Decl(enumWithExport.ts, 0, 0), Decl(enumWithExport.ts, 2, 1))
export let y = 123
>y : Symbol(y, Decl(enumWithExport.ts, 1, 12))
}
enum x {
>x : Symbol(x, Decl(enumWithExport.ts, 0, 0), Decl(enumWithExport.ts, 2, 1))
z = y
>z : Symbol(x.z, Decl(enumWithExport.ts, 3, 8))
}

View File

@@ -0,0 +1,15 @@
=== tests/cases/compiler/enumWithExport.ts ===
namespace x {
>x : typeof x
export let y = 123
>y : number
>123 : 123
}
enum x {
>x : x
z = y
>z : x.z
>y : any
}

View File

@@ -0,0 +1,6 @@
namespace x {
export let y = 123
}
enum x {
z = y
}