Skip to content

Commit 40fc3b1

Browse files
TheLartiansPerryvw
authored andcommitted
Fix accessor assignment (#360)
* fix accessor assignment * add test * add brackets
1 parent 58cd74d commit 40fc3b1

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/LuaTransformer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,10 @@ export class LuaTransformer {
17971797
);
17981798
}
17991799

1800-
if (ts.isPropertyAccessExpression(expression.left) || ts.isElementAccessExpression(expression.left)) {
1800+
if (
1801+
(ts.isPropertyAccessExpression(expression.left) && !tsHelper.hasSetAccessor(expression.left, this.checker))
1802+
|| ts.isElementAccessExpression(expression.left)
1803+
) {
18011804
// Left is property/element access: cache result while maintaining order of evaluation
18021805
// (function(o, i, v) o[i] = v; return v end)(${objExpression}, ${indexExpression}, ${right})
18031806
const objParameter = tstl.createIdentifier("o");

test/unit/expressions.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ export class ExpressionTests {
224224
@TestCase("inst.field | 3", 8 | 3)
225225
@TestCase("inst.field << 3", 8 << 3)
226226
@TestCase("inst.field >> 1", 8 >> 1)
227+
@TestCase("inst.field = 3", 7)
227228
@TestCase(`"abc" + inst.field`, "abc8")
228229
@Test("Get accessor expression")
229230
public getAccessorBinary(expression: string, expected: any): void {

0 commit comments

Comments
 (0)