Fix export of enum with same-named member (#55070)

This commit is contained in:
Ron Buckton 2023-07-19 15:52:19 -04:00 committed by GitHub
parent 8f96638692
commit 97ef321fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 2 deletions

View File

@ -3040,8 +3040,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// (it refers to the constant type of the expression instead)
return undefined;
}
if (isModuleDeclaration(location) && lastLocation && location.name === lastLocation) {
// If this is the name of a namespace, skip the parent since it will have is own locals that could
if (isModuleOrEnumDeclaration(location) && lastLocation && location.name === lastLocation) {
// If lastLocation is the name of a namespace or enum, skip the parent since it will have is own locals that could
// conflict.
lastLocation = location;
location = location.parent;

View File

@ -0,0 +1,31 @@
//// [tests/cases/compiler/exportDeclarationForModuleOrEnumWithMemberOfSameName.ts] ////
//// [exportDeclarationForModuleOrEnumWithMemberOfSameName.ts]
// https://github.com/microsoft/TypeScript/issues/55038
namespace A {
export const A = 0;
}
export { A }
enum B {
B
}
export { B }
//// [exportDeclarationForModuleOrEnumWithMemberOfSameName.js]
"use strict";
// https://github.com/microsoft/TypeScript/issues/55038
Object.defineProperty(exports, "__esModule", { value: true });
exports.B = exports.A = void 0;
var A;
(function (A_1) {
A_1.A = 0;
})(A || (exports.A = A = {}));
var B;
(function (B) {
B[B["B"] = 0] = "B";
})(B || (exports.B = B = {}));

View File

@ -0,0 +1,36 @@
//// [tests/cases/compiler/exportDeclarationForModuleOrEnumWithMemberOfSameName.ts] ////
//// [exportDeclarationForModuleOrEnumWithMemberOfSameName.ts]
// https://github.com/microsoft/TypeScript/issues/55038
namespace A {
export const A = 0;
}
export { A }
enum B {
B
}
export { B }
//// [exportDeclarationForModuleOrEnumWithMemberOfSameName.js]
// https://github.com/microsoft/TypeScript/issues/55038
System.register([], function (exports_1, context_1) {
"use strict";
var A, B;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {// https://github.com/microsoft/TypeScript/issues/55038
(function (A_1) {
A_1.A = 0;
})(A || (exports_1("A", A = {})));
(function (B) {
B[B["B"] = 0] = "B";
})(B || (exports_1("B", B = {})));
}
};
});

View File

@ -0,0 +1,16 @@
// @target: esnext
// @module: commonjs,system
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/55038
namespace A {
export const A = 0;
}
export { A }
enum B {
B
}
export { B }