@@ -1007,7 +1007,10 @@ export class LuaTransformer {
10071007 return undefined ;
10081008 }
10091009
1010- const bodyStatements : tstl . Statement [ ] = this . transformClassInstanceFields ( classDeclaration , instanceFields ) ;
1010+ const bodyWithFieldInitializers : tstl . Statement [ ] = this . transformClassInstanceFields (
1011+ classDeclaration ,
1012+ instanceFields
1013+ ) ;
10111014
10121015 // Check for field declarations in constructor
10131016 const constructorFieldsDeclarations = statement . parameters . filter ( p => p . modifiers !== undefined ) ;
@@ -1027,7 +1030,7 @@ export class LuaTransformer {
10271030 tstl . SyntaxKind . OrOperator
10281031 )
10291032 ) ;
1030- bodyStatements . push ( assignement ) ;
1033+ bodyWithFieldInitializers . push ( assignement ) ;
10311034 } else {
10321035 // self.declarationName = declarationName
10331036 const assignement = tstl . createAssignmentStatement (
@@ -1037,7 +1040,7 @@ export class LuaTransformer {
10371040 ) ,
10381041 declarationName
10391042 ) ;
1040- bodyStatements . push ( assignement ) ;
1043+ bodyWithFieldInitializers . push ( assignement ) ;
10411044 }
10421045 }
10431046
@@ -1049,9 +1052,24 @@ export class LuaTransformer {
10491052 ) ;
10501053
10511054 const [ body ] = this . transformFunctionBody ( statement . parameters , statement . body , restParamName ) ;
1052- bodyStatements . push ( ...body ) ;
10531055
1054- const block : tstl . Block = tstl . createBlock ( bodyStatements ) ;
1056+ // If there are field initializers and the first statement is a super call, hoist the super call to the top
1057+ if ( bodyWithFieldInitializers . length > 0 && statement . body && statement . body . statements . length > 0 ) {
1058+ const firstStatement = statement . body . statements [ 0 ] ;
1059+ if ( ts . isExpressionStatement ( firstStatement )
1060+ && ts . isCallExpression ( firstStatement . expression )
1061+ && firstStatement . expression . expression . kind === ts . SyntaxKind . SuperKeyword )
1062+ {
1063+ const superCall = body . shift ( ) ;
1064+ if ( superCall ) {
1065+ bodyWithFieldInitializers . unshift ( superCall ) ;
1066+ }
1067+ }
1068+ }
1069+
1070+ bodyWithFieldInitializers . push ( ...body ) ;
1071+
1072+ const block : tstl . Block = tstl . createBlock ( bodyWithFieldInitializers ) ;
10551073
10561074 const result = tstl . createAssignmentStatement (
10571075 this . createConstructorName ( className ) ,
0 commit comments