Skip to content

Commit e1f5d4f

Browse files
authored
Fix enum nested in namespace (#1682)
* fix enum nested in namespace * use snapshot to test
1 parent 6fa24e8 commit e1f5d4f

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/transformation/visitors/enum.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as ts from "typescript";
22
import * as lua from "../../LuaAST";
33
import { FunctionVisitor, TransformationContext } from "../context";
44
import { AnnotationKind, getTypeAnnotations } from "../utils/annotations";
5-
import { getSymbolExportScope } from "../utils/export";
5+
import { addExportToIdentifier, getSymbolExportScope } from "../utils/export";
66
import { createLocalOrExportedOrGlobalDeclaration } from "../utils/lua-ast";
77
import { isFirstDeclaration } from "../utils/typescript";
88
import { transformIdentifier } from "./identifier";
@@ -32,7 +32,7 @@ export const transformEnumDeclaration: FunctionVisitor<ts.EnumDeclaration> = (no
3232
if (!membersOnly && isFirstDeclaration(context, node)) {
3333
const name = transformIdentifier(context, node.name);
3434
const table = lua.createBinaryExpression(
35-
lua.cloneIdentifier(name),
35+
addExportToIdentifier(context, name),
3636
lua.createTableExpression(),
3737
lua.SyntaxKind.OrOperator
3838
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`enum nested in namespace 1`] = `
4+
"A = A or ({})
5+
do
6+
A.TestEnum = A.TestEnum or ({})
7+
A.TestEnum.B = 0
8+
A.TestEnum[A.TestEnum.B] = "B"
9+
A.TestEnum.C = 1
10+
A.TestEnum[A.TestEnum.C] = "C"
11+
end"
12+
`;

test/unit/enum.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,14 @@ test("enum merging multiple files", () => {
203203
)
204204
.expectToMatchJsResult();
205205
});
206+
207+
test("enum nested in namespace", () => {
208+
util.testModule`
209+
namespace A {
210+
export enum TestEnum {
211+
B,
212+
C
213+
}
214+
}
215+
`.expectLuaToMatchSnapshot();
216+
});

0 commit comments

Comments
 (0)