Skip to content

Commit a4bb7f5

Browse files
committed
Added some extra brackets for safety
1 parent b4d4504 commit a4bb7f5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Transpiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ export abstract class LuaTranspiler {
824824
case ts.SyntaxKind.MinusMinusToken:
825825
return `${operand}=${operand}-1`;
826826
case ts.SyntaxKind.ExclamationToken:
827-
return `not ${operand}`;
827+
return `(not ${operand})`;
828828
case ts.SyntaxKind.MinusToken:
829829
return `-${operand}`;
830830
default:
@@ -1132,7 +1132,7 @@ export abstract class LuaTranspiler {
11321132

11331133
public transpileTypeOfExpression(node: ts.TypeOfExpression): string {
11341134
const expression = this.transpileExpression(node.expression);
1135-
return `type(${expression}) == "table" and "object" or type(${expression})`;
1135+
return `(type(${expression}) == "table" and "object" or type(${expression}))`;
11361136
}
11371137

11381138
// Transpile a variable statement

test/unit/expressions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class ExpressionTests {
1010
@TestCase("++i", "i=i+1")
1111
@TestCase("i--", "i=i-1")
1212
@TestCase("--i", "i=i-1")
13-
@TestCase("!a", "not a")
13+
@TestCase("!a", "(not a)")
1414
@TestCase("-a", "-a")
1515
@TestCase("delete tbl['test']", "tbl[\"test\"]=nil")
1616
@TestCase("delete tbl.test", "tbl.test=nil")

0 commit comments

Comments
 (0)