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
12 changes: 12 additions & 0 deletions src/LuaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,11 @@ export class LuaTransformer {
} else if (expression.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
// = assignment
return this.transformAssignmentStatement(expression);

} else if (expression.operatorToken.kind === ts.SyntaxKind.CommaToken) {
const lhs = this.transformExpressionStatement(expression.left);
const rhs = this.transformExpressionStatement(expression.right);
return tstl.createDoStatement([lhs, rhs], expression);
}

} else if (
Expand Down Expand Up @@ -1701,6 +1706,13 @@ export class LuaTransformer {
case ts.SyntaxKind.InstanceOfKeyword:
return this.transformLuaLibFunction(LuaLibFeature.InstanceOf, lhs, rhs);

case ts.SyntaxKind.CommaToken:
return this.createImmediatelyInvokedFunctionExpression(
[this.transformExpressionStatement(expression.left)],
rhs,
expression
);

default:
throw TSTLErrors.UnsupportedKind("binary operator", expression.operatorToken.kind, expression);
}
Expand Down
22 changes: 22 additions & 0 deletions test/unit/expressions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ export class ExpressionTests {
Expect(util.transpileString(input)).toBe(lua);
}

@TestCase("bar(),foo()", 1)
@TestCase("foo(),bar()", 2)
@TestCase("foo(),bar(),baz()", 3)
@Test("Binary Comma")
public binaryComma(input: string, expectResult: number): void {
const code =
`function foo() { return 1; }
function bar() { return 2; };
function baz() { return 3; };
return (${input});`;
Expect(util.transpileAndExecute(code)).toBe(expectResult);
}

@Test("Binary Comma Statement in For Loop")
public binaryCommaStatementInForLoop(): void {
const code =
`let x: number, y: number;
for (x = 0, y = 17; x < 5; ++x, --y) {}
return y;`;
Expect(util.transpileAndExecute(code)).toBe(12);
}

@Test("Null Expression")
public nullExpression(): void {
Expect(util.transpileString("null")).toBe("nil;");
Expand Down