Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/transformation/visitors/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ts from "typescript";
import * as lua from "../../LuaAST";
import { FunctionVisitor, TransformationContext } from "../context";
import { AnnotationKind, getTypeAnnotations } from "../utils/annotations";
import { getSymbolExportScope } from "../utils/export";
import { addExportToIdentifier, getSymbolExportScope } from "../utils/export";
import { createLocalOrExportedOrGlobalDeclaration } from "../utils/lua-ast";
import { isFirstDeclaration } from "../utils/typescript";
import { transformIdentifier } from "./identifier";
Expand Down Expand Up @@ -32,7 +32,7 @@ export const transformEnumDeclaration: FunctionVisitor<ts.EnumDeclaration> = (no
if (!membersOnly && isFirstDeclaration(context, node)) {
const name = transformIdentifier(context, node.name);
const table = lua.createBinaryExpression(
lua.cloneIdentifier(name),
addExportToIdentifier(context, name),
lua.createTableExpression(),
lua.SyntaxKind.OrOperator
);
Expand Down
12 changes: 12 additions & 0 deletions test/unit/__snapshots__/enum.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`enum nested in namespace 1`] = `
"A = A or ({})
do
A.TestEnum = A.TestEnum or ({})
A.TestEnum.B = 0
A.TestEnum[A.TestEnum.B] = "B"
A.TestEnum.C = 1
A.TestEnum[A.TestEnum.C] = "C"
end"
`;
11 changes: 11 additions & 0 deletions test/unit/enum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,14 @@ test("enum merging multiple files", () => {
)
.expectToMatchJsResult();
});

test("enum nested in namespace", () => {
util.testModule`
namespace A {
export enum TestEnum {
B,
C
}
}
`.expectLuaToMatchSnapshot();
});
Loading