Skip to content

Commit 2606809

Browse files
committed
Simplify expression + 1 for numeric literals
1 parent 392caad commit 2606809

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/LuaTransformer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5086,10 +5086,17 @@ export class LuaTransformer {
50865086
return tstl.createCallExpression(tstl.createIdentifier("tostring"), [expression]);
50875087
}
50885088

5089-
protected expressionPlusOne(expression: tstl.Expression): tstl.BinaryExpression {
5089+
protected expressionPlusOne(expression: tstl.Expression): tstl.Expression {
5090+
if (tstl.isNumericLiteral(expression)) {
5091+
const newNode = tstl.cloneNode(expression);
5092+
newNode.value += 1;
5093+
return newNode;
5094+
}
5095+
50905096
if (tstl.isBinaryExpression(expression)) {
50915097
expression = tstl.createParenthesizedExpression(expression);
50925098
}
5099+
50935100
return tstl.createBinaryExpression(expression, tstl.createNumericLiteral(1), tstl.SyntaxKind.AdditionOperator);
50945101
}
50955102

0 commit comments

Comments
 (0)