Skip to content

Commit 8bbd97c

Browse files
author
Alex D
committed
fixes
1 parent c5d4e10 commit 8bbd97c

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/emitterlua.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,7 +2902,6 @@ export class EmitterLua {
29022902
this.processBinaryExpressionEqualOp(node, this.ops[node.operatorToken.kind], this.strOps[node.operatorToken.kind]);
29032903
break;
29042904
case ts.SyntaxKind.EqualsEqualsToken:
2905-
case ts.SyntaxKind.AmpersandAmpersandToken:
29062905
if (this.ignoreExtraLogic) {
29072906
this.processBinaryExpressionSingleOp(node, this.ops[node.operatorToken.kind], this.strOps[node.operatorToken.kind]);
29082907
} else {
@@ -2911,6 +2910,7 @@ export class EmitterLua {
29112910

29122911
break;
29132912
case ts.SyntaxKind.BarBarToken:
2913+
case ts.SyntaxKind.AmpersandAmpersandToken:
29142914
if (this.ignoreExtraLogic) {
29152915
this.processBinaryExpressionSingleOp(node, this.ops[node.operatorToken.kind], this.strOps[node.operatorToken.kind]);
29162916
} else {
@@ -2922,8 +2922,18 @@ export class EmitterLua {
29222922

29232923
this.functionContext.textCode.push("local op" + opIndex + " = ");
29242924
this.processExpression(node.left);
2925-
this.functionContext.textCode.push(" if __is_true(op" + opIndex + ") then return op" + opIndex + " else return ");
2926-
this.processExpression(node.right);
2925+
this.functionContext.textCode.push(" if __is_true(op" + opIndex + ") then");
2926+
if (node.operatorToken.kind === ts.SyntaxKind.BarBarToken)
2927+
{
2928+
this.functionContext.textCode.push(" return op" + opIndex);
2929+
this.functionContext.textCode.push(" else return ");
2930+
this.processExpression(node.right);
2931+
} else {
2932+
this.functionContext.textCode.push(" return ");
2933+
this.processExpression(node.right);
2934+
this.functionContext.textCode.push(" else return op" + opIndex);
2935+
}
2936+
29272937
this.functionContext.textCode.push(" end end)()");
29282938
}
29292939

test/test.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
function _x() {
2-
console.log(1);
3-
return 1;
4-
}
5-
6-
function _y() {
7-
console.log(2);
8-
return 2;
9-
}
10-
11-
console.log(_x() || _x() == 0 ? _x() : _y());
12-
console.log(!_x() && _x() != 0 ? _x() : _y());
1+
function padLeft(value: string, padding: number)
2+
function padLeft(value: string, padding: string)
3+
function padLeft(value: string, padding: any) {
4+
if (typeof padding === "number") {
5+
return String(padding) + value;
6+
}
7+
8+
if (typeof padding === "string") {
9+
return padding + value;
10+
}
11+
12+
throw new Error(`Expected string or number, got \'${padding}\'.`);
13+
}
14+
15+
console.log(padLeft("Hello world", 4));

0 commit comments

Comments
 (0)