mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[buildhir] Patch: lower nested OptionalMemberExpr
This commit is contained in:
@@ -1871,7 +1871,7 @@ function lowerMemberExpression(
|
||||
object: { ...object },
|
||||
property: property.node.name,
|
||||
loc: exprLoc,
|
||||
optional: t.isOptionalMemberExpression(expr),
|
||||
optional: expr.node.optional ?? false,
|
||||
};
|
||||
return { object, property: property.node.name, value };
|
||||
} else {
|
||||
|
||||
@@ -349,9 +349,9 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
|
||||
break;
|
||||
}
|
||||
case "PropertyLoad": {
|
||||
value = `PropertyLoad ${printPlace(instrValue.object)}.${
|
||||
instrValue.property
|
||||
}`;
|
||||
value = `PropertyLoad ${printPlace(instrValue.object)}${
|
||||
instrValue.optional ? "?" : ""
|
||||
}.${instrValue.property}`;
|
||||
break;
|
||||
}
|
||||
case "PropertyStore": {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
function Component(props) {
|
||||
let x = foo(props.a?.b.c.d);
|
||||
return x;
|
||||
}
|
||||
+5
-1
@@ -2,6 +2,8 @@
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// We should codegen nested optional properties correctly
|
||||
// (i.e. placing `?` in the correct PropertyLoad)
|
||||
function Component(props) {
|
||||
let x = foo(props.a?.b.c.d);
|
||||
return x;
|
||||
@@ -12,12 +14,14 @@ function Component(props) {
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
// We should codegen nested optional properties correctly
|
||||
// (i.e. placing `?` in the correct PropertyLoad)
|
||||
function Component(props) {
|
||||
const $ = React.unstable_useMemoCache(2);
|
||||
const c_0 = $[0] !== props.a.b.c.d;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = foo(props.a?.b?.c?.d);
|
||||
t0 = foo((props.a?.b).c.d);
|
||||
$[0] = props.a.b.c.d;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
@@ -0,0 +1,6 @@
|
||||
// We should codegen nested optional properties correctly
|
||||
// (i.e. placing `?` in the correct PropertyLoad)
|
||||
function Component(props) {
|
||||
let x = foo(props.a?.b.c.d);
|
||||
return x;
|
||||
}
|
||||
Reference in New Issue
Block a user