|
1 | 1 | import * as ts from "typescript"; |
2 | 2 |
|
3 | 3 | import { CompilerOptions } from "./CommandLineParser"; |
4 | | -import { ForHelper } from "./ForHelper"; |
5 | 4 | import { TSHelper as tsEx } from "./TSHelper"; |
6 | 5 |
|
7 | 6 | import * as path from "path"; |
@@ -362,24 +361,22 @@ export class LuaTranspiler { |
362 | 361 | } |
363 | 362 |
|
364 | 363 | public transpileFor(node: ts.ForStatement): string { |
365 | | - // Get iterator variable |
366 | | - const variable = (node.initializer as ts.VariableDeclarationList).declarations[0]; |
367 | | - const identifier = variable.name as ts.Identifier; |
368 | | - |
369 | | - // Populate three components of lua numeric for loop: |
370 | | - const start = this.transpileExpression(variable.initializer); |
371 | | - const end = ForHelper.GetForEnd(node.condition, this); |
372 | | - const step = ForHelper.GetForStep(node.incrementor, this); |
373 | | - |
374 | 364 | // Add header |
375 | | - let result = this.indent + `for ${identifier.escapedText}=${start},${end},${step} do\n`; |
| 365 | + let result = ""; |
| 366 | + for (const variableDeclaration of (node.initializer as ts.VariableDeclarationList).declarations) { |
| 367 | + result += this.transpileVariableDeclaration(variableDeclaration); |
| 368 | + } |
| 369 | + result += this.indent + `while(${this.transpileExpression(node.condition)}) do\n`; |
376 | 370 |
|
377 | 371 | // Add body |
378 | 372 | this.pushIndent(); |
379 | 373 | result += this.transpileStatement(node.statement); |
| 374 | + result += this.indent + this.transpileExpression(node.incrementor) + "\n"; |
380 | 375 | this.popIndent(); |
381 | 376 |
|
382 | | - return result + this.indent + "end\n"; |
| 377 | + result += this.indent + "end\n"; |
| 378 | + |
| 379 | + return result; |
383 | 380 | } |
384 | 381 |
|
385 | 382 | public transpileForOf(node: ts.ForOfStatement): string { |
|
0 commit comments