mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-25 14:44:00 -05:00
Fix enums and namespace merge (#47059)
* Fix enums and namespace merge * Remove unused comment
This commit is contained in:
@@ -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);
|
||||
|
||||
12
tests/baselines/reference/enumWithExport.errors.txt
Normal file
12
tests/baselines/reference/enumWithExport.errors.txt
Normal 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.
|
||||
}
|
||||
16
tests/baselines/reference/enumWithExport.js
Normal file
16
tests/baselines/reference/enumWithExport.js
Normal 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 = {}));
|
||||
13
tests/baselines/reference/enumWithExport.symbols
Normal file
13
tests/baselines/reference/enumWithExport.symbols
Normal 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))
|
||||
}
|
||||
15
tests/baselines/reference/enumWithExport.types
Normal file
15
tests/baselines/reference/enumWithExport.types
Normal 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
|
||||
}
|
||||
6
tests/cases/compiler/enumWithExport.ts
Normal file
6
tests/cases/compiler/enumWithExport.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace x {
|
||||
export let y = 123
|
||||
}
|
||||
enum x {
|
||||
z = y
|
||||
}
|
||||
Reference in New Issue
Block a user