Skip to content

Commit e08753a

Browse files
tomblindPerryvw
authored andcommitted
allowing all strings to be thrown, not just literals (#244)
* allowing all strings to be thrown, not just literals; also fixed formatting * added semi-colon to throw
1 parent 3095b00 commit e08753a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Transpiler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export abstract class LuaTranspiler {
294294
case ts.SyntaxKind.TryStatement:
295295
return this.transpileTry(node as ts.TryStatement);
296296
case ts.SyntaxKind.ThrowStatement:
297-
return this.transpileThrow(node as ts.ThrowStatement);
297+
return this.indent + this.transpileThrow(node as ts.ThrowStatement) + ";\n";
298298
case ts.SyntaxKind.ContinueStatement:
299299
return this.transpileContinue(node as ts.ContinueStatement);
300300
case ts.SyntaxKind.TypeAliasDeclaration:
@@ -683,8 +683,9 @@ export abstract class LuaTranspiler {
683683
}
684684

685685
public transpileThrow(node: ts.ThrowStatement): string {
686-
if (ts.isStringLiteral(node.expression)) {
687-
return `error("${node.expression.text}")`;
686+
const type = this.checker.getTypeAtLocation(node.expression);
687+
if (tsHelper.isStringType(type)) {
688+
return `error(${this.transpileExpression(node.expression)})`;
688689
} else {
689690
throw TSTLErrors.InvalidThrowExpression(node.expression);
690691
}

test/unit/error.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class LuaErrorTests {
1212
`throw "Some Error"`
1313
);
1414
// Assert
15-
Expect(lua).toBe(`error("Some Error")`);
15+
Expect(lua).toBe(`error("Some Error");`);
1616
}
1717

1818
@Test("throwError")

0 commit comments

Comments
 (0)