Skip to content

Commit e9215bc

Browse files
2 parents 7d77a1e + 14ca7a7 commit e9215bc

5 files changed

Lines changed: 49 additions & 20 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-to-lua",
3-
"version": "1.16.0",
3+
"version": "1.16.1",
44
"description": "A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!",
55
"repository": "https://github.com/TypeScriptToLua/TypeScriptToLua",
66
"homepage": "https://typescripttolua.github.io/",

src/transformation/visitors/class/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ function transformClassLikeDeclaration(
172172
}
173173
} else if (ts.isMethodDeclaration(member)) {
174174
// Methods
175-
const statement = transformMethodDeclaration(context, member, localClassName);
176-
if (statement) result.push(statement);
175+
const statements = transformMethodDeclaration(context, member, localClassName);
176+
result.push(...statements);
177177
} else if (ts.isPropertyDeclaration(member)) {
178178
// Properties
179179
if (isStaticNode(member)) {

src/transformation/visitors/class/members/method.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export function transformMethodDeclaration(
2626
context: TransformationContext,
2727
node: ts.MethodDeclaration,
2828
className: lua.Identifier
29-
): lua.Statement | undefined {
29+
): lua.Statement[] {
3030
// Don't transform methods without body (overload declarations)
31-
if (!node.body) return;
31+
if (!node.body) return [];
3232

3333
const methodTable = transformMemberExpressionOwnerName(node, className);
3434
const methodName = transformMethodName(context, node);
@@ -40,21 +40,31 @@ export function transformMethodDeclaration(
4040
if (methodHasDecorators || methodHasParameterDecorators) {
4141
if (context.options.experimentalDecorators) {
4242
// Legacy decorator statement
43-
return lua.createExpressionStatement(
44-
createClassMethodDecoratingExpression(context, node, functionExpression, className)
45-
);
43+
return [
44+
lua.createAssignmentStatement(
45+
lua.createTableIndexExpression(methodTable, methodName),
46+
functionExpression
47+
),
48+
lua.createExpressionStatement(
49+
createClassMethodDecoratingExpression(context, node, functionExpression, className)
50+
),
51+
];
4652
} else {
47-
return lua.createAssignmentStatement(
48-
lua.createTableIndexExpression(methodTable, methodName),
49-
createClassMethodDecoratingExpression(context, node, functionExpression, className),
50-
node
51-
);
53+
return [
54+
lua.createAssignmentStatement(
55+
lua.createTableIndexExpression(methodTable, methodName),
56+
createClassMethodDecoratingExpression(context, node, functionExpression, className),
57+
node
58+
),
59+
];
5260
}
5361
} else {
54-
return lua.createAssignmentStatement(
55-
lua.createTableIndexExpression(methodTable, methodName),
56-
functionExpression,
57-
node
58-
);
62+
return [
63+
lua.createAssignmentStatement(
64+
lua.createTableIndexExpression(methodTable, methodName),
65+
functionExpression,
66+
node
67+
),
68+
];
5969
}
6070
}

test/unit/classes/decorators.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,23 @@ describe("legacy experimentalDecorators", () => {
604604
.setOptions({ experimentalDecorators: true })
605605
.expectToEqual({ result: "overridden" });
606606
});
607+
608+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1453
609+
test("Class methods with legacy decorators can still be called ($1453)", () => {
610+
util.testFunction`
611+
function decorator<Class>(
612+
target: Class,
613+
propertyKey: keyof Class,
614+
): void {}
615+
616+
class Foo {
617+
@decorator
618+
public method2() { return 4; }
619+
}
620+
621+
return new Foo().method2();
622+
`
623+
.setOptions({ experimentalDecorators: true })
624+
.expectToMatchJsResult();
625+
});
607626
});

0 commit comments

Comments
 (0)