@@ -473,7 +473,6 @@ export abstract class LuaTranspiler {
473473 public transpileForOf ( node : ts . ForOfStatement ) : string {
474474 // Get variable identifier
475475 const variable = ( node . initializer as ts . VariableDeclarationList ) . declarations [ 0 ] ;
476- const identifier = variable . name as ts . Identifier ;
477476
478477 // Transpile expression
479478 const expression = this . transpileExpression ( node . expression ) ;
@@ -483,7 +482,15 @@ export abstract class LuaTranspiler {
483482 const pairs = isArray ? "ipairs" : "pairs" ;
484483
485484 // Make header
486- let result = this . indent + `for _, ${ this . transpileIdentifier ( identifier ) } in ${ pairs } (${ expression } ) do\n` ;
485+ let result = "" ;
486+ if ( ts . isIdentifier ( variable . name ) ) {
487+ result = this . indent + `for _, ${ this . transpileIdentifier ( variable . name ) } in ${ pairs } (${ expression } ) do\n` ;
488+ } else if ( ts . isArrayBindingPattern ( variable . name ) ) {
489+ const valueVar = "__forOfValue" + this . genVarCounter ;
490+ result = this . indent + `for _, ${ valueVar } in ${ pairs } (${ expression } ) do\n` ;
491+ const declaration = ts . createVariableDeclaration ( variable . name , undefined , ts . createIdentifier ( valueVar ) ) ;
492+ result += this . indent + this . transpileVariableDeclaration ( declaration ) ;
493+ }
487494
488495 // For body
489496 this . pushIndent ( ) ;
@@ -1217,6 +1224,17 @@ export abstract class LuaTranspiler {
12171224 return escapedText ;
12181225 }
12191226
1227+ public transpileArrayBindingElement ( name : ts . ArrayBindingElement ) : string {
1228+ if ( ts . isOmittedExpression ( name ) ) {
1229+ return "_" ;
1230+ } else if ( ts . isIdentifier ( name ) ) {
1231+ return this . transpileIdentifier ( name ) ;
1232+ } else {
1233+ const kind = tsHelper . enumName ( name . kind , ts . SyntaxKind ) ;
1234+ throw new TranspileError ( `Encountered not-supported array binding element kind: ${ kind } ` , name ) ;
1235+ }
1236+ }
1237+
12201238 public transpileTypeOfExpression ( node : ts . TypeOfExpression ) : string {
12211239 const expression = this . transpileExpression ( node . expression ) ;
12221240 return `(type(${ expression } ) == "table" and "object" or type(${ expression } ))` ;
0 commit comments