File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -1037,6 +1037,11 @@ export class LuaTransformer {
10371037 } else if ( expression . operatorToken . kind === ts . SyntaxKind . EqualsToken ) {
10381038 // = assignment
10391039 return this . transformAssignmentStatement ( expression ) ;
1040+
1041+ } else if ( expression . operatorToken . kind === ts . SyntaxKind . CommaToken ) {
1042+ const lhs = this . transformExpressionStatement ( expression . left ) ;
1043+ const rhs = this . transformExpressionStatement ( expression . right ) ;
1044+ return tstl . createDoStatement ( [ lhs , rhs ] , expression ) ;
10401045 }
10411046
10421047 } else if (
@@ -1701,6 +1706,13 @@ export class LuaTransformer {
17011706 case ts . SyntaxKind . InstanceOfKeyword :
17021707 return this . transformLuaLibFunction ( LuaLibFeature . InstanceOf , lhs , rhs ) ;
17031708
1709+ case ts . SyntaxKind . CommaToken :
1710+ return this . createImmediatelyInvokedFunctionExpression (
1711+ [ this . transformExpressionStatement ( expression . left ) ] ,
1712+ rhs ,
1713+ expression
1714+ ) ;
1715+
17041716 default :
17051717 throw TSTLErrors . UnsupportedKind ( "binary operator" , expression . operatorToken . kind , expression ) ;
17061718 }
Original file line number Diff line number Diff line change @@ -177,6 +177,28 @@ export class ExpressionTests {
177177 Expect ( util . transpileString ( input ) ) . toBe ( lua ) ;
178178 }
179179
180+ @TestCase ( "bar(),foo()" , 1 )
181+ @TestCase ( "foo(),bar()" , 2 )
182+ @TestCase ( "foo(),bar(),baz()" , 3 )
183+ @Test ( "Binary Comma" )
184+ public binaryComma ( input : string , expectResult : number ) : void {
185+ const code =
186+ `function foo() { return 1; }
187+ function bar() { return 2; };
188+ function baz() { return 3; };
189+ return (${ input } );` ;
190+ Expect ( util . transpileAndExecute ( code ) ) . toBe ( expectResult ) ;
191+ }
192+
193+ @Test ( "Binary Comma Statement in For Loop" )
194+ public binaryCommaStatementInForLoop ( ) : void {
195+ const code =
196+ `let x: number, y: number;
197+ for (x = 0, y = 17; x < 5; ++x, --y) {}
198+ return y;` ;
199+ Expect ( util . transpileAndExecute ( code ) ) . toBe ( 12 ) ;
200+ }
201+
180202 @Test ( "Null Expression" )
181203 public nullExpression ( ) : void {
182204 Expect ( util . transpileString ( "null" ) ) . toBe ( "nil;" ) ;
You can’t perform that action at this time.
0 commit comments