Skip to content

Commit bbaf3ae

Browse files
authored
Merge pull request #124 from zengjie/master
Fixed continue implementation breaking versions before 5.2.
2 parents ee4130c + bf91b1b commit bbaf3ae

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.js
22
node_modules/
3+
yarn.lock
34

45
coverage/
56
.nyc*

src/Transpiler.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export abstract class LuaTranspiler {
194194
case ts.SyntaxKind.ThrowStatement:
195195
return this.transpileThrow(node as ts.ThrowStatement);
196196
case ts.SyntaxKind.ContinueStatement:
197-
return this.transpileContinue();
197+
return this.transpileContinue(node as ts.ContinueStatement);
198198
case ts.SyntaxKind.TypeAliasDeclaration:
199199
case ts.SyntaxKind.InterfaceDeclaration:
200200
case ts.SyntaxKind.EndOfFileToken:
@@ -316,8 +316,12 @@ export abstract class LuaTranspiler {
316316
}
317317
}
318318

319-
public transpileContinue(): string {
320-
return this.indent + `goto __continue${this.loopStack[this.loopStack.length - 1]}\n`;
319+
public transpileContinue(node: ts.ContinueStatement): string {
320+
throw new TranspileError(
321+
`Unsupported continue statement, ` +
322+
`continue is not supported in Lua ${this.options.luaTarget}.`,
323+
node
324+
);
321325
}
322326

323327
public transpileIf(node: ts.IfStatement): string {
@@ -352,7 +356,6 @@ export abstract class LuaTranspiler {
352356
result += this.transpileStatement(node.statement);
353357
this.popIndent();
354358
result += this.indent + "end\n";
355-
result += this.indent + `::__continue${this.loopStack.pop()}::\n`;
356359
return result;
357360
}
358361

src/targets/Transpiler.51.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ import { TSHelper as tsHelper } from "../TSHelper";
44
import * as ts from "typescript";
55

66
export class LuaTranspiler51 extends LuaTranspiler {
7+
78
}

src/targets/Transpiler.52.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,25 @@ import { LuaTranspiler51 } from "./Transpiler.51";
44
import * as ts from "typescript";
55

66
export class LuaTranspiler52 extends LuaTranspiler51 {
7+
public transpileLoopBody(
8+
node: ts.WhileStatement
9+
| ts.DoStatement
10+
| ts.ForStatement
11+
| ts.ForOfStatement
12+
| ts.ForInStatement
13+
): string {
14+
this.loopStack.push(this.genVarCounter);
15+
this.genVarCounter++;
16+
let result = this.indent + "do\n";
17+
this.pushIndent();
18+
result += this.transpileStatement(node.statement);
19+
this.popIndent();
20+
result += this.indent + "end\n";
21+
result += this.indent + `::__continue${this.loopStack.pop()}::\n`;
22+
return result;
23+
}
724

25+
public transpileContinue(node: ts.ContinueStatement): string {
26+
return this.indent + `goto __continue${this.loopStack[this.loopStack.length - 1]}\n`;
27+
}
828
}

0 commit comments

Comments
 (0)