File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -225,7 +225,26 @@ export class LuaTranspiler {
225225 }
226226
227227 static transpileBinaryExpression ( node : ts . BinaryExpression ) : string {
228- return this . transpileExpression ( node . left ) + this . transpileOperator ( node . operatorToken ) + this . transpileExpression ( node . right ) ;
228+ // Transpile operands
229+ const lhs = this . transpileExpression ( node . left ) ;
230+ const rhs = this . transpileExpression ( node . right ) ;
231+ // Rewrite some non-existant binary operators
232+ switch ( node . operatorToken . kind ) {
233+ case ts . SyntaxKind . PlusEqualsToken :
234+ return `${ lhs } =${ lhs } +${ rhs } ` ;
235+ case ts . SyntaxKind . MinusEqualsToken :
236+ return `${ lhs } =${ lhs } -${ rhs } ` ;
237+ case ts . SyntaxKind . AmpersandAmpersandToken :
238+ return `${ lhs } and ${ rhs } ` ;
239+ case ts . SyntaxKind . BarBarToken :
240+ return `${ lhs } or ${ rhs } ` ;
241+ case ts . SyntaxKind . AmpersandToken :
242+ return `bit.band(${ lhs } ,${ rhs } )` ;
243+ case ts . SyntaxKind . BarToken :
244+ return `bit.bor(${ lhs } ,${ rhs } )` ;
245+ default :
246+ return lhs + this . transpileOperator ( node . operatorToken ) + rhs ;
247+ }
229248 }
230249
231250 // Replace some missmatching operators
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ function Activate() {
5858 ++ i ;
5959 i += 1 ;
6060 i -= 1 ;
61+ let a = 24 & 4 ;
6162
6263 let list = [ 1 , 2 , 3 ] ;
6364
You can’t perform that action at this time.
0 commit comments