Skip to content

Commit ba317ff

Browse files
committed
fix enum nested in namespace
1 parent 6fa24e8 commit ba317ff

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-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
);

test/unit/enum.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,19 @@ 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+
C,
212+
D
213+
}
214+
}
215+
`.tap(builder => {
216+
const lua = builder.getMainLuaCodeChunk();
217+
expect(lua).toMatch(
218+
'A = A or ({})\ndo\n A.TestEnum = A.TestEnum or ({})\n A.TestEnum.C = 0\n A.TestEnum[A.TestEnum.C] = "C"\n A.TestEnum.D = 1\n A.TestEnum[A.TestEnum.D] = "D"\nend'
219+
);
220+
});
221+
});

0 commit comments

Comments
 (0)