Skip to content

Commit 58c5fd7

Browse files
authored
Merge pull request #12 from timocov/enums
2 parents c38f3e7 + ca0b78b commit 58c5fd7

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/transformer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
113113
return handleClassMember(node);
114114
}
115115

116+
// enum Enum { node }
117+
if (ts.isEnumMember(node.parent) && node.parent.name === node) {
118+
return handleEnumMember(node);
119+
}
120+
116121
// const a = { node: 123 }
117122
if (ts.isPropertyAssignment(node.parent) && node.parent.name === node) {
118123
return handlePropertyAssignment(node);
@@ -181,6 +186,11 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
181186
return createNewIdentifier(node);
182187
}
183188

189+
// enum Enum { node }
190+
function handleEnumMember(node: ts.Identifier): ts.Identifier {
191+
return createNewIdentifier(node);
192+
}
193+
184194
// const { node: localName } = obj;
185195
function handleBindingElement(node: ts.Identifier): ts.Identifier {
186196
return createNewIdentifier(node);

tests/test-cases/enums/input.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
enum TestEnum {
2+
Test1,
3+
Test2,
4+
Test3,
5+
}
6+
7+
console.log(TestEnum.Test1);
8+
console.log(TestEnum['Test2']);
9+
10+
export enum ExportedEnum {
11+
Foo,
12+
}

tests/test-cases/enums/output.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.ExportedEnum = void 0;
4+
var TestEnum;
5+
(function (TestEnum) {
6+
TestEnum[TestEnum["_internal_Test1"] = 0] = "_internal_Test1";
7+
TestEnum[TestEnum["_internal_Test2"] = 1] = "_internal_Test2";
8+
TestEnum[TestEnum["_internal_Test3"] = 2] = "_internal_Test3";
9+
})(TestEnum || (TestEnum = {}));
10+
console.log(TestEnum._internal_Test1);
11+
console.log(TestEnum["_internal_Test2"]);
12+
var ExportedEnum;
13+
(function (ExportedEnum) {
14+
ExportedEnum[ExportedEnum["Foo"] = 0] = "Foo";
15+
})(ExportedEnum = exports.ExportedEnum || (exports.ExportedEnum = {}));

0 commit comments

Comments
 (0)