Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export abstract class LuaTranspiler {
case ts.SyntaxKind.TryStatement:
return this.transpileTry(node as ts.TryStatement);
case ts.SyntaxKind.ThrowStatement:
return this.transpileThrow(node as ts.ThrowStatement);
return this.indent + this.transpileThrow(node as ts.ThrowStatement) + ";\n";
case ts.SyntaxKind.ContinueStatement:
return this.transpileContinue(node as ts.ContinueStatement);
case ts.SyntaxKind.TypeAliasDeclaration:
Expand Down Expand Up @@ -683,8 +683,9 @@ export abstract class LuaTranspiler {
}

public transpileThrow(node: ts.ThrowStatement): string {
if (ts.isStringLiteral(node.expression)) {
return `error("${node.expression.text}")`;
const type = this.checker.getTypeAtLocation(node.expression);
if (tsHelper.isStringType(type)) {
return `error(${this.transpileExpression(node.expression)})`;
} else {
throw TSTLErrors.InvalidThrowExpression(node.expression);
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class LuaErrorTests {
`throw "Some Error"`
);
// Assert
Expect(lua).toBe(`error("Some Error")`);
Expect(lua).toBe(`error("Some Error");`);
}

@Test("throwError")
Expand Down