Skip to content

Commit 989cb5a

Browse files
author
Alex D
committed
fixed issues with post ++
1 parent cac415f commit 989cb5a

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/emitterlua.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,22 +2740,30 @@ export class EmitterLua {
27402740
switch (node.operator) {
27412741
case ts.SyntaxKind.PlusPlusToken:
27422742
case ts.SyntaxKind.MinusMinusToken:
2743-
this.functionContext.textCode.push("(function () ");
2744-
let opIndex = parseInt(node.pos.toFixed());
2745-
if (opIndex < 0) {
2746-
opIndex = 0;
2747-
}
2743+
if (this.isValueNotRequired(node.parent))
2744+
{
2745+
this.processExpression(node.operand);
2746+
this.functionContext.textCode.push(" = ");
2747+
this.processExpression(node.operand);
2748+
this.functionContext.textCode.push(" + 1");
2749+
} else {
2750+
this.functionContext.textCode.push("(function () ");
2751+
let opIndex = parseInt(node.pos.toFixed());
2752+
if (opIndex < 0) {
2753+
opIndex = 0;
2754+
}
27482755

2749-
const op = node.operator == ts.SyntaxKind.PlusPlusToken ? '+' : '-';
2756+
const op = node.operator == ts.SyntaxKind.PlusPlusToken ? '+' : '-';
27502757

2751-
this.functionContext.textCode.push("local op" + opIndex + " = (");
2752-
this.processExpression(node.operand);
2753-
this.functionContext.textCode.push(") ");
2754-
this.processExpression(node.operand);
2755-
this.functionContext.textCode.push(" = ");
2756-
this.functionContext.textCode.push("op" + opIndex + " + 1 ");
2757-
this.functionContext.textCode.push("return op" + opIndex + " ");
2758-
this.functionContext.textCode.push("end)()");
2758+
this.functionContext.textCode.push("local op" + opIndex + " = (");
2759+
this.processExpression(node.operand);
2760+
this.functionContext.textCode.push(") ");
2761+
this.processExpression(node.operand);
2762+
this.functionContext.textCode.push(" = ");
2763+
this.functionContext.textCode.push("op" + opIndex + " " + op + " 1 ");
2764+
this.functionContext.textCode.push("return op" + opIndex + " ");
2765+
this.functionContext.textCode.push("end)()");
2766+
}
27592767

27602768
break;
27612769
}

test/test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
let a = 1;
2-
console.log(++a);
3-
console.log(--a);
4-
console.log(a++);
5-
console.log(a--);
1+
var someArray = [9, 2, 5];
2+
for (var item of someArray) {
3+
console.log(item);
4+
}

0 commit comments

Comments
 (0)