From a2c6dca4d7279e768bcea3c68d7e7ad9a6a74b4c Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Sat, 26 Jan 2019 15:13:31 +0100 Subject: [PATCH 1/3] fix accessor assignment --- src/LuaTransformer.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/LuaTransformer.ts b/src/LuaTransformer.ts index e4dab185d..ce9f407ab 100644 --- a/src/LuaTransformer.ts +++ b/src/LuaTransformer.ts @@ -1797,7 +1797,10 @@ export class LuaTransformer { ); } - if (ts.isPropertyAccessExpression(expression.left) || ts.isElementAccessExpression(expression.left)) { + if ( + ts.isPropertyAccessExpression(expression.left) && !tsHelper.hasSetAccessor(expression.left, this.checker) + || ts.isElementAccessExpression(expression.left) + ) { // Left is property/element access: cache result while maintaining order of evaluation // (function(o, i, v) o[i] = v; return v end)(${objExpression}, ${indexExpression}, ${right}) const objParameter = tstl.createIdentifier("o"); From 7bf2ec96b5a0fdec61b54f121d153d816689379b Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Sat, 26 Jan 2019 15:16:15 +0100 Subject: [PATCH 2/3] add test --- test/unit/expressions.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/expressions.spec.ts b/test/unit/expressions.spec.ts index c3fd733ae..bb2cfb0bc 100644 --- a/test/unit/expressions.spec.ts +++ b/test/unit/expressions.spec.ts @@ -224,6 +224,7 @@ export class ExpressionTests { @TestCase("inst.field | 3", 8 | 3) @TestCase("inst.field << 3", 8 << 3) @TestCase("inst.field >> 1", 8 >> 1) + @TestCase("inst.field = 3", 7) @TestCase(`"abc" + inst.field`, "abc8") @Test("Get accessor expression") public getAccessorBinary(expression: string, expected: any): void { From 21dd86b5d7da39a4f2998ec3b39328184b2ed78d Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Sat, 26 Jan 2019 17:34:27 +0100 Subject: [PATCH 3/3] add brackets --- src/LuaTransformer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LuaTransformer.ts b/src/LuaTransformer.ts index ce9f407ab..d49fcbe47 100644 --- a/src/LuaTransformer.ts +++ b/src/LuaTransformer.ts @@ -1798,7 +1798,7 @@ export class LuaTransformer { } if ( - ts.isPropertyAccessExpression(expression.left) && !tsHelper.hasSetAccessor(expression.left, this.checker) + (ts.isPropertyAccessExpression(expression.left) && !tsHelper.hasSetAccessor(expression.left, this.checker)) || ts.isElementAccessExpression(expression.left) ) { // Left is property/element access: cache result while maintaining order of evaluation