[bug] fix codegen for LVals with memberPath (#772)

This commit is contained in:
Jan Kassens
2022-11-14 11:35:47 -05:00
parent 99181160d5
commit 5f40a1bf75
5 changed files with 14 additions and 6 deletions
+9 -1
View File
@@ -745,7 +745,15 @@ function codegenJsxElement(
}
function codegenLVal(lval: LValue): t.LVal {
return convertIdentifier(lval.place.identifier);
const expr = convertIdentifier(lval.place.identifier);
const memberPath = lval.place.memberPath;
return memberPath == null
? expr
: memberPath.reduceRight(
(path: t.Identifier | t.MemberExpression, member) =>
t.memberExpression(path, t.identifier(member)),
expr
);
}
function codegenValue(
@@ -98,8 +98,8 @@ flowchart TB
```javascript
function g$0(a$4) {
a$4 = a$4.b.c + 1;
a$4 = a$4.b.c * 2;
a$4.c.b = a$4.b.c + 1;
a$4.c.b = a$4.b.c * 2;
return;
}
@@ -156,7 +156,7 @@ function Component$0(props$10) {
c: c$13,
};
const x$15 = {};
x$15 = b$12;
x$15.b = b$12;
const y$16 = mutate$8(x$15, d$14);
a$11;
b$12;
@@ -53,7 +53,7 @@ flowchart TB
function Component$0(props$6) {
const x$7 = {};
const y$8 = [];
x$7 = y$8;
x$7.y = y$8;
const child$9 = <Component$0 data={y$8}></Component$0>;
x$7.y.push(props$6.p0);
return <Component$0 data={x$7}>{child$9}</Component$0>;
@@ -45,7 +45,7 @@ flowchart TB
function foo$0() {
const x$3 = [];
const y$4 = {};
y$4 = x$3;
y$4.x = x$3;
return y$4;
}