@@ -213,7 +213,7 @@ export abstract class LuaTranspiler {
213213 }
214214
215215 // Inline lualib features
216- if ( this . options . luaLibImport === LuaLibImportKind . Inline && this . luaLibFeatureSet . size > 0 ) {
216+ if ( this . options . luaLibImport === LuaLibImportKind . Inline ) {
217217 result += "\n" + "-- Lua Library Imports\n" ;
218218 for ( const feature of this . luaLibFeatureSet ) {
219219 const featureFile = path . resolve ( __dirname , `../dist/lualib/${ feature } .lua` ) ;
@@ -1789,30 +1789,29 @@ export abstract class LuaTranspiler {
17891789
17901790 public transpileConstructor ( node : ts . ConstructorDeclaration ,
17911791 className : string ) : string {
1792- // Check for field declarations in constructor
1793- const constructorFieldsDeclarations = node . parameters . filter ( p => p . modifiers !== undefined ) ;
1792+ const extraInstanceFields = [ ] ;
17941793
1795- const [ paramNames , spreadIdentifier ] = this . transpileParameters ( node . parameters ) ;
1796-
1797- let result = this . indent + `function ${ className } .constructor(${ [ "self" ] . concat ( paramNames ) . join ( "," ) } )\n` ;
1794+ const parameters = [ "self" ] ;
1795+ node . parameters . forEach ( param => {
1796+ // If param has decorators, add extra instance field
1797+ if ( param . modifiers !== undefined ) {
1798+ extraInstanceFields . push ( this . transpileIdentifier ( param . name as ts . Identifier ) ) ;
1799+ }
1800+ // Add to parameter list
1801+ parameters . push ( this . transpileIdentifier ( param . name as ts . Identifier ) ) ;
1802+ } ) ;
17981803
1799- // Transpile constructor body
1800- this . pushIndent ( ) ;
1801- this . classStack . push ( className ) ;
1804+ let result = this . indent + `function ${ className } .constructor(${ parameters . join ( "," ) } )\n` ;
18021805
18031806 // Add in instance field declarations
1804- for ( const declaration of constructorFieldsDeclarations ) {
1805- const declarationName = this . transpileIdentifier ( declaration . name as ts . Identifier ) ;
1806- if ( declaration . initializer ) {
1807- const value = this . transpileExpression ( declaration . initializer ) ;
1808- result += this . indent + `self.${ declarationName } = ${ declarationName } or ${ value } \n` ;
1809- } else {
1810- result += this . indent + `self.${ declarationName } = ${ declarationName } \n` ;
1811- }
1807+ for ( const f of extraInstanceFields ) {
1808+ result += this . indent + ` self.${ f } = ${ f } \n` ;
18121809 }
18131810
1814- result += this . transpileFunctionBody ( node . parameters , node . body , spreadIdentifier ) ;
1815-
1811+ // Transpile constructor body
1812+ this . pushIndent ( ) ;
1813+ this . classStack . push ( className ) ;
1814+ result += this . transpileBlock ( node . body ) ;
18161815 this . classStack . pop ( ) ;
18171816 this . popIndent ( ) ;
18181817
0 commit comments