Skip to content

Commit 3bd5d04

Browse files
lollekoPerryvw
authored andcommitted
Added missing bit operations (#31)
* Added missing bit operations * Added test cases for shift operators
1 parent 1c3fd47 commit 3bd5d04

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

dist/Transpiler.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,33 @@ var LuaTranspiler = /** @class */ (function () {
443443
case ts.SyntaxKind.AmpersandToken:
444444
result = "bit.band(" + lhs + "," + rhs + ")";
445445
break;
446+
case ts.SyntaxKind.AmpersandEqualsToken:
447+
result = lhs + "=bit.band(" + lhs + "," + rhs + ")";
448+
break;
446449
case ts.SyntaxKind.BarToken:
447450
result = "bit.bor(" + lhs + "," + rhs + ")";
448451
break;
452+
case ts.SyntaxKind.BarEqualsToken:
453+
result = lhs + "=bit.bor(" + lhs + "," + rhs + ")";
454+
break;
455+
case ts.SyntaxKind.LessThanLessThanToken:
456+
result = "bit.lshift(" + lhs + "," + rhs + ")";
457+
break;
458+
case ts.SyntaxKind.LessThanLessThanEqualsToken:
459+
result = lhs + "=bit.lshift(" + lhs + "," + rhs + ")";
460+
break;
461+
case ts.SyntaxKind.GreaterThanGreaterThanToken:
462+
result = "bit.arshift(" + lhs + "," + rhs + ")";
463+
break;
464+
case ts.SyntaxKind.GreaterThanGreaterThanEqualsToken:
465+
result = lhs + "=bit.arshift(" + lhs + "," + rhs + ")";
466+
break;
467+
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
468+
result = "bit.rshift(" + lhs + "," + rhs + ")";
469+
break;
470+
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
471+
result = lhs + "=bit.rshift(" + lhs + "," + rhs + ")";
472+
break;
449473
case ts.SyntaxKind.PlusToken:
450474
// Replace string + with ..
451475
var typeLeft = this.checker.getTypeAtLocation(node.left);

src/Transpiler.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,33 @@ export class LuaTranspiler {
486486
case ts.SyntaxKind.AmpersandToken:
487487
result = `bit.band(${lhs},${rhs})`;
488488
break;
489+
case ts.SyntaxKind.AmpersandEqualsToken:
490+
result = `${lhs}=bit.band(${lhs},${rhs})`;
491+
break;
489492
case ts.SyntaxKind.BarToken:
490493
result = `bit.bor(${lhs},${rhs})`;
491494
break;
495+
case ts.SyntaxKind.BarEqualsToken:
496+
result = `${lhs}=bit.bor(${lhs},${rhs})`;
497+
break;
498+
case ts.SyntaxKind.LessThanLessThanToken:
499+
result = `bit.lshift(${lhs},${rhs})`;
500+
break;
501+
case ts.SyntaxKind.LessThanLessThanEqualsToken:
502+
result = `${lhs}=bit.lshift(${lhs},${rhs})`;
503+
break;
504+
case ts.SyntaxKind.GreaterThanGreaterThanToken:
505+
result = `bit.arshift(${lhs},${rhs})`;
506+
break;
507+
case ts.SyntaxKind.GreaterThanGreaterThanEqualsToken:
508+
result = `${lhs}=bit.arshift(${lhs},${rhs})`;
509+
break;
510+
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
511+
result = `bit.rshift(${lhs},${rhs})`;
512+
break;
513+
case ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
514+
result = `${lhs}=bit.rshift(${lhs},${rhs})`;
515+
break;
492516
case ts.SyntaxKind.PlusToken:
493517
// Replace string + with ..
494518
const typeLeft = this.checker.getTypeAtLocation(node.left);

test/unit/expressions.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ export class ExpressionTests {
3939
@TestCase("a*=b", "a=a*b")
4040
@TestCase("a/=b", "a=a/b")
4141
@TestCase("a&b", "bit.band(a,b)")
42+
@TestCase("a&=b", "a=bit.band(a,b)")
4243
@TestCase("a|b", "bit.bor(a,b)")
44+
@TestCase("a|=b", "a=bit.bor(a,b)")
45+
@TestCase("a<<b", "bit.lshift(a,b)")
46+
@TestCase("a<<=b", "a=bit.lshift(a,b)")
47+
@TestCase("a>>b", "bit.arshift(a,b)")
48+
@TestCase("a>>=b", "a=bit.arshift(a,b)")
49+
@TestCase("a>>>b", "bit.rshift(a,b)")
50+
@TestCase("a>>>=b", "a=bit.rshift(a,b)")
4351
@Test("Binary expressions overridden operators")
4452
public binaryOperatorOverride(input: string, lua: string) {
4553
Expect(transpileString(input)).toBe(lua);
@@ -61,4 +69,4 @@ export class ExpressionTests {
6169
public conditional(input: string, lua: string) {
6270
Expect(transpileString(input)).toBe(lua);
6371
}
64-
}
72+
}

0 commit comments

Comments
 (0)