Skip to content

Commit 9ef9bb0

Browse files
authored
Fix crash on erroneous enum member merged with exported type alias (microsoft#36429)
1 parent 368db99 commit 9ef9bb0

6 files changed

+105
-0
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29266,6 +29266,7 @@ namespace ts {
2926629266
: DeclarationSpaces.ExportNamespace;
2926729267
case SyntaxKind.ClassDeclaration:
2926829268
case SyntaxKind.EnumDeclaration:
29269+
case SyntaxKind.EnumMember:
2926929270
return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue;
2927029271
case SyntaxKind.SourceFile:
2927129272
return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue | DeclarationSpaces.ExportNamespace;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
tests/cases/compiler/alias.ts(3,1): error TS2440: Import declaration conflicts with local declaration of 'EnumA'.
2+
tests/cases/compiler/alias.ts(3,8): error TS2395: Individual declarations in merged declaration 'EnumA' must be all exported or all local.
3+
tests/cases/compiler/alias.ts(5,13): error TS2395: Individual declarations in merged declaration 'EnumA' must be all exported or all local.
4+
5+
6+
==== tests/cases/compiler/enum.ts (0 errors) ====
7+
export enum Enum {
8+
A,
9+
B
10+
}
11+
==== tests/cases/compiler/alias.ts (3 errors) ====
12+
import {Enum} from "./enum";
13+
14+
import EnumA = Enum.A;
15+
~~~~~~~~~~~~~~~~~~~~~~
16+
!!! error TS2440: Import declaration conflicts with local declaration of 'EnumA'.
17+
~~~~~
18+
!!! error TS2395: Individual declarations in merged declaration 'EnumA' must be all exported or all local.
19+
20+
export type EnumA = [string] | [string, number];
21+
~~~~~
22+
!!! error TS2395: Individual declarations in merged declaration 'EnumA' must be all exported or all local.
23+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [tests/cases/compiler/importedEnumMemberMergedWithExportedAliasIsError.ts] ////
2+
3+
//// [enum.ts]
4+
export enum Enum {
5+
A,
6+
B
7+
}
8+
//// [alias.ts]
9+
import {Enum} from "./enum";
10+
11+
import EnumA = Enum.A;
12+
13+
export type EnumA = [string] | [string, number];
14+
15+
16+
//// [enum.js]
17+
"use strict";
18+
exports.__esModule = true;
19+
var Enum;
20+
(function (Enum) {
21+
Enum[Enum["A"] = 0] = "A";
22+
Enum[Enum["B"] = 1] = "B";
23+
})(Enum = exports.Enum || (exports.Enum = {}));
24+
//// [alias.js]
25+
"use strict";
26+
exports.__esModule = true;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/enum.ts ===
2+
export enum Enum {
3+
>Enum : Symbol(Enum, Decl(enum.ts, 0, 0))
4+
5+
A,
6+
>A : Symbol(Enum.A, Decl(enum.ts, 0, 18))
7+
8+
B
9+
>B : Symbol(Enum.B, Decl(enum.ts, 1, 6))
10+
}
11+
=== tests/cases/compiler/alias.ts ===
12+
import {Enum} from "./enum";
13+
>Enum : Symbol(Enum, Decl(alias.ts, 0, 8))
14+
15+
import EnumA = Enum.A;
16+
>EnumA : Symbol(EnumA, Decl(alias.ts, 0, 28), Decl(alias.ts, 2, 22))
17+
>Enum : Symbol(Enum, Decl(alias.ts, 0, 8))
18+
>A : Symbol(Enum.A, Decl(enum.ts, 0, 18))
19+
20+
export type EnumA = [string] | [string, number];
21+
>EnumA : Symbol(EnumA, Decl(alias.ts, 2, 22))
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/enum.ts ===
2+
export enum Enum {
3+
>Enum : Enum
4+
5+
A,
6+
>A : Enum.A
7+
8+
B
9+
>B : Enum.B
10+
}
11+
=== tests/cases/compiler/alias.ts ===
12+
import {Enum} from "./enum";
13+
>Enum : typeof Enum
14+
15+
import EnumA = Enum.A;
16+
>EnumA : Enum.A
17+
>Enum : Enum
18+
>A : Enum.A
19+
20+
export type EnumA = [string] | [string, number];
21+
>EnumA : import("tests/cases/compiler/alias").EnumA
22+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @filename: enum.ts
2+
export enum Enum {
3+
A,
4+
B
5+
}
6+
// @filename: alias.ts
7+
import {Enum} from "./enum";
8+
9+
import EnumA = Enum.A;
10+
11+
export type EnumA = [string] | [string, number];

0 commit comments

Comments
 (0)