Skip to content

Commit 89ae1d2

Browse files
authored
Support for NonNullExpression (#226)
1 parent cd89882 commit 89ae1d2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Transpiler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,8 @@ export abstract class LuaTranspiler {
803803
return "";
804804
case ts.SyntaxKind.SpreadElement:
805805
return this.transpileSpreadElement(node as ts.SpreadElement);
806+
case ts.SyntaxKind.NonNullExpression:
807+
return this.transpileExpression((node as ts.NonNullExpression).expression);
806808
case ts.SyntaxKind.Block:
807809
this.pushIndent();
808810
const ret = "do \n" + this.transpileBlock(node as ts.Block) + "end\n";

test/unit/expressions.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ export class ExpressionTests {
290290
const result = util.transpileAndExecute(`let a = 4; {let a = 42; } return a;`);
291291
Expect(result).toBe(4);
292292
}
293+
294+
@Test("Non-null expression")
295+
public nonNullExpression(): void {
296+
const result = util.transpileAndExecute(`function abc(): number | undefined { return 3; }
297+
const a: number = abc()!;
298+
return a;`);
299+
Expect(result).toBe(3);
300+
}
293301
// ====================================
294302
// Test expected errors
295303
// ====================================

0 commit comments

Comments
 (0)