@@ -2,6 +2,7 @@ import * as ts from "typescript";
22import * as lua from "../../../../LuaAST" ;
33import { TransformationContext } from "../../../context" ;
44import { createSelfIdentifier } from "../../../utils/lua-ast" ;
5+ import { transformInPrecedingStatementScope } from "../../../utils/preceding-statements" ;
56import { popScope , pushScope , ScopeType } from "../../../utils/scope" ;
67import { transformFunctionBodyContent , transformFunctionBodyHeader , transformParameters } from "../../function" ;
78import { transformIdentifier } from "../../identifier" ;
@@ -43,7 +44,9 @@ export function transformConstructorDeclaration(
4344 // Check for field declarations in constructor
4445 const constructorFieldsDeclarations = statement . parameters . filter ( p => p . modifiers !== undefined ) ;
4546
46- const classInstanceFields = transformClassInstanceFields ( context , instanceFields ) ;
47+ const [ fieldsPrecedingStatements , classInstanceFields ] = transformInPrecedingStatementScope ( context , ( ) =>
48+ transformClassInstanceFields ( context , instanceFields )
49+ ) ;
4750
4851 // If there are field initializers and the first statement is a super call,
4952 // move super call between default assignments and initializers
@@ -78,6 +81,7 @@ export function transformConstructorDeclaration(
7881 // else { TypeScript error: A parameter property may not be declared using a binding pattern }
7982 }
8083
84+ bodyWithFieldInitializers . push ( ...fieldsPrecedingStatements ) ;
8185 bodyWithFieldInitializers . push ( ...classInstanceFields ) ;
8286
8387 bodyWithFieldInitializers . push ( ...body ) ;
0 commit comments