mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[test][ssa] Add todo test for reassigning in rval
From my understanding, `LeaveSSA` is not currently handling reassignment in rvals. Source code ```js let x = foo(); x(x = bar()); ``` Simplified HIR (from EnterSSA) ``` [1] $1 = StoreLocal Let x$0 = [[ foo() ]] // x$1 = foo() [2] $2 = LoadLocal x$1 // t0 = x$1 [3] $4 = StoreLocal Reassign x$3 = [[ bar() ]] // t1 = x$3 = bar() [4] $5 = CallExpression $2 ($4) // t0(t1) ``` codegen: ```js let x; x = foo(); x = bar(); x(x); ```
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// Forget should call the original x (x = foo()) to compute result
|
||||
function Component() {
|
||||
let x = foo();
|
||||
let result = x((x = bar()), 5);
|
||||
return [result, x];
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
// Forget should call the original x (x = foo()) to compute result
|
||||
function Component() {
|
||||
const $ = React.unstable_useMemoCache(3);
|
||||
let t0;
|
||||
let x;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
x = foo();
|
||||
x = bar();
|
||||
t0 = x(x, 5);
|
||||
$[0] = t0;
|
||||
$[1] = x;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
x = $[1];
|
||||
}
|
||||
const result = t0;
|
||||
let t1;
|
||||
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t1 = [result, x];
|
||||
$[2] = t1;
|
||||
} else {
|
||||
t1 = $[2];
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Forget should call the original x (x = foo()) to compute result
|
||||
function Component() {
|
||||
let x = foo();
|
||||
let result = x((x = bar()), 5);
|
||||
return [result, x];
|
||||
}
|
||||
Reference in New Issue
Block a user