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
10 changes: 7 additions & 3 deletions src/transformation/visitors/class/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ import { createMethodDecoratingExpression, transformMethodDeclaration } from "./
import { getExtendedNode, getExtendedType, isStaticNode } from "./utils";
import { createClassSetup } from "./setup";
import { LuaTarget } from "../../../CompilerOptions";
import { transformInPrecedingStatementScope } from "../../utils/preceding-statements";

export const transformClassDeclaration: FunctionVisitor<ts.ClassLikeDeclaration> = (declaration, context) => {
// If declaration is a default export, transform to export variable assignment instead
if (hasDefaultExportModifier(declaration)) {
const left = createDefaultExportExpression(declaration);
const right = transformClassAsExpression(declaration, context);
return [lua.createAssignmentStatement(left, right, declaration)];
// Class declaration including assignment to ____exports.default are in preceding statements
const [precedingStatements] = transformInPrecedingStatementScope(context, () => {
transformClassAsExpression(declaration, context);
return [];
});
return precedingStatements;
}

const { statements } = transformClassLikeDeclaration(declaration, context);
Expand Down
32 changes: 32 additions & 0 deletions test/unit/identifiers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,38 @@ describe("unicode identifiers in supporting environments (luajit)", () => {
});
});

test("unicode export class", () => {
util.testModule`
import { 你好 } from "./utfclass";
export const result = new 你好().hello();
`
.addExtraFile(
"utfclass.ts",
`export class 你好 {
hello() {
return "你好";
}
}`
)
.expectToEqual({ result: "你好" });
});

test("unicode export default class", () => {
util.testModule`
import c from "./utfclass";
export const result = new c().hello();
`
.addExtraFile(
"utfclass.ts",
`export default class 你好 {
hello() {
return "你好";
}
}`
)
.expectToEqual({ result: "你好" });
});

describe("lua keyword as identifier doesn't interfere with lua's value", () => {
test("variable (nil)", () => {
util.testFunction`
Expand Down