[bug] fix codegen for LVals with memberPath (#772)
Jan Kassens committed
Nov 14, 2022 at 11:35 UTC
5f40a1bf751459341b61de757a4eee203eb04172
5 files changed
+14
-6
compiler/forget/src/HIR/Codegen.ts
+9
-1
@@ -745,7 +745,15 @@ function codegenJsxElement(
745
}
746
747
function codegenLVal(lval: LValue): t.LVal {
748
- return convertIdentifier(lval.place.identifier);
748
+ const expr = convertIdentifier(lval.place.identifier);
749
+ const memberPath = lval.place.memberPath;
750
+ return memberPath == null
751
+ ? expr
752
+ : memberPath.reduceRight(
753
+ (path: t.Identifier | t.MemberExpression, member) =>
754
+ t.memberExpression(path, t.identifier(member)),
755
+ expr
756
+ );
757
}
758
759
function codegenValue(
compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md
+2
-2
@@ -98,8 +98,8 @@ flowchart TB
98
99
```javascript
100
function g$0(a$4) {
101
- a$4 = a$4.b.c + 1;
102
- a$4 = a$4.b.c * 2;
101
+ a$4.c.b = a$4.b.c + 1;
102
+ a$4.c.b = a$4.b.c * 2;
103
return;
104
}
105
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md
+1
-1
@@ -156,7 +156,7 @@ function Component$0(props$10) {
156
c: c$13,
157
};
158
const x$15 = {};
159
- x$15 = b$12;
159
+ x$15.b = b$12;
160
const y$16 = mutate$8(x$15, d$14);
161
a$11;
162
b$12;
compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md
+1
-1
@@ -53,7 +53,7 @@ flowchart TB
53
function Component$0(props$6) {
54
const x$7 = {};
55
const y$8 = [];
56
- x$7 = y$8;
56
+ x$7.y = y$8;
57
const child$9 = <Component$0 data={y$8}></Component$0>;
58
x$7.y.push(props$6.p0);
59
return <Component$0 data={x$7}>{child$9}</Component$0>;
compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md
+1
-1
@@ -45,7 +45,7 @@ flowchart TB
45
function foo$0() {
46
const x$3 = [];
47
const y$4 = {};
48
- y$4 = x$3;
48
+ y$4.x = x$3;
49
return y$4;
50
}
51