Skip to content

Commit 67872a5

Browse files
authored
Fix enums and namespace merge (microsoft#47059)
* Fix enums and namespace merge * Remove unused comment
1 parent 4305997 commit 67872a5

File tree

6 files changed

+63
-1
lines changed

6 files changed

+63
-1
lines changed

Diff for: src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39397,7 +39397,7 @@ namespace ts {
3939739397
if (memberSymbol) {
3939839398
const declaration = memberSymbol.valueDeclaration;
3939939399
if (declaration !== member) {
39400-
if (declaration && isBlockScopedNameDeclaredBeforeUse(declaration, member)) {
39400+
if (declaration && isBlockScopedNameDeclaredBeforeUse(declaration, member) && isEnumDeclaration(declaration.parent)) {
3940139401
return getEnumMemberValue(declaration as EnumMember);
3940239402
}
3940339403
error(expr, Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);

Diff for: tests/baselines/reference/enumWithExport.errors.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
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.
2+
3+
4+
==== tests/cases/compiler/enumWithExport.ts (1 errors) ====
5+
namespace x {
6+
export let y = 123
7+
}
8+
enum x {
9+
z = y
10+
~
11+
!!! error TS2651: A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums.
12+
}

Diff for: tests/baselines/reference/enumWithExport.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [enumWithExport.ts]
2+
namespace x {
3+
export let y = 123
4+
}
5+
enum x {
6+
z = y
7+
}
8+
9+
//// [enumWithExport.js]
10+
var x;
11+
(function (x) {
12+
x.y = 123;
13+
})(x || (x = {}));
14+
(function (x) {
15+
x[x["z"] = 0] = "z";
16+
})(x || (x = {}));

Diff for: tests/baselines/reference/enumWithExport.symbols

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/enumWithExport.ts ===
2+
namespace x {
3+
>x : Symbol(x, Decl(enumWithExport.ts, 0, 0), Decl(enumWithExport.ts, 2, 1))
4+
5+
export let y = 123
6+
>y : Symbol(y, Decl(enumWithExport.ts, 1, 12))
7+
}
8+
enum x {
9+
>x : Symbol(x, Decl(enumWithExport.ts, 0, 0), Decl(enumWithExport.ts, 2, 1))
10+
11+
z = y
12+
>z : Symbol(x.z, Decl(enumWithExport.ts, 3, 8))
13+
}

Diff for: tests/baselines/reference/enumWithExport.types

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/enumWithExport.ts ===
2+
namespace x {
3+
>x : typeof x
4+
5+
export let y = 123
6+
>y : number
7+
>123 : 123
8+
}
9+
enum x {
10+
>x : x
11+
12+
z = y
13+
>z : x.z
14+
>y : any
15+
}

Diff for: tests/cases/compiler/enumWithExport.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace x {
2+
export let y = 123
3+
}
4+
enum x {
5+
z = y
6+
}

0 commit comments

Comments
 (0)