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
15 changes: 11 additions & 4 deletions src/transformation/visitors/class/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ function transformClassLikeDeclaration(
}

// Transform class members

// First transform the methods, in case the static properties call them
for (const member of classDeclaration.members) {
if (ts.isMethodDeclaration(member)) {
// Methods
const statements = transformMethodDeclaration(context, member, localClassName);
result.push(...statements);
}
}

// Then transform the rest
for (const member of classDeclaration.members) {
if (ts.isAccessor(member)) {
// Accessors
Expand All @@ -170,10 +181,6 @@ function transformClassLikeDeclaration(
if (accessorsResult) {
result.push(accessorsResult);
}
} else if (ts.isMethodDeclaration(member)) {
// Methods
const statements = transformMethodDeclaration(context, member, localClassName);
result.push(...statements);
} else if (ts.isPropertyDeclaration(member)) {
// Properties
if (isStaticNode(member)) {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/classes/classes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,18 @@ test("static initialization block (#1447)", () => {
export const result2 = A.staticProperty3;
`.expectToMatchJsResult();
});

// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1457
test("static member definition order (#1457)", () => {
util.testFunction`
class A {
static a = A.foo()
static foo(): number {
return 5
}
}
return A.a;
`.expectToMatchJsResult();
});