Skip to content

Commit 97ef321

Browse files
authored
Fix export of enum with same-named member (#55070)
1 parent 8f96638 commit 97ef321

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,8 +3040,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
30403040
// (it refers to the constant type of the expression instead)
30413041
return undefined;
30423042
}
3043-
if (isModuleDeclaration(location) && lastLocation && location.name === lastLocation) {
3044-
// If this is the name of a namespace, skip the parent since it will have is own locals that could
3043+
if (isModuleOrEnumDeclaration(location) && lastLocation && location.name === lastLocation) {
3044+
// If lastLocation is the name of a namespace or enum, skip the parent since it will have is own locals that could
30453045
// conflict.
30463046
lastLocation = location;
30473047
location = location.parent;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/compiler/exportDeclarationForModuleOrEnumWithMemberOfSameName.ts] ////
2+
3+
//// [exportDeclarationForModuleOrEnumWithMemberOfSameName.ts]
4+
// https://github.com/microsoft/TypeScript/issues/55038
5+
6+
namespace A {
7+
export const A = 0;
8+
}
9+
10+
export { A }
11+
12+
enum B {
13+
B
14+
}
15+
16+
export { B }
17+
18+
19+
//// [exportDeclarationForModuleOrEnumWithMemberOfSameName.js]
20+
"use strict";
21+
// https://github.com/microsoft/TypeScript/issues/55038
22+
Object.defineProperty(exports, "__esModule", { value: true });
23+
exports.B = exports.A = void 0;
24+
var A;
25+
(function (A_1) {
26+
A_1.A = 0;
27+
})(A || (exports.A = A = {}));
28+
var B;
29+
(function (B) {
30+
B[B["B"] = 0] = "B";
31+
})(B || (exports.B = B = {}));
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [tests/cases/compiler/exportDeclarationForModuleOrEnumWithMemberOfSameName.ts] ////
2+
3+
//// [exportDeclarationForModuleOrEnumWithMemberOfSameName.ts]
4+
// https://github.com/microsoft/TypeScript/issues/55038
5+
6+
namespace A {
7+
export const A = 0;
8+
}
9+
10+
export { A }
11+
12+
enum B {
13+
B
14+
}
15+
16+
export { B }
17+
18+
19+
//// [exportDeclarationForModuleOrEnumWithMemberOfSameName.js]
20+
// https://github.com/microsoft/TypeScript/issues/55038
21+
System.register([], function (exports_1, context_1) {
22+
"use strict";
23+
var A, B;
24+
var __moduleName = context_1 && context_1.id;
25+
return {
26+
setters: [],
27+
execute: function () {// https://github.com/microsoft/TypeScript/issues/55038
28+
(function (A_1) {
29+
A_1.A = 0;
30+
})(A || (exports_1("A", A = {})));
31+
(function (B) {
32+
B[B["B"] = 0] = "B";
33+
})(B || (exports_1("B", B = {})));
34+
}
35+
};
36+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @target: esnext
2+
// @module: commonjs,system
3+
// @noTypesAndSymbols: true
4+
// https://github.com/microsoft/TypeScript/issues/55038
5+
6+
namespace A {
7+
export const A = 0;
8+
}
9+
10+
export { A }
11+
12+
enum B {
13+
B
14+
}
15+
16+
export { B }

0 commit comments

Comments
 (0)