Skip to content

Commit 30d28fa

Browse files
committed
Modify goto/continue to follow the chained transpilers design
1 parent 093d8fa commit 30d28fa

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

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: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,5 @@ import { TSHelper as tsHelper } from "../TSHelper";
44
import * as ts from "typescript";
55

66
export class LuaTranspiler51 extends LuaTranspiler {
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-
return result;
22-
}
237

24-
public transpileContinue(): string {
25-
throw new TranspileError(
26-
"Unsupported continue statement, " +
27-
"continue is not supported in Lua ${this.options.luaTarget}.",
28-
null
29-
);
30-
}
318
}

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(): string {
26+
return this.indent + `goto __continue${this.loopStack[this.loopStack.length - 1]}\n`;
27+
}
828
}

0 commit comments

Comments
 (0)