@samitouri / QOS-React / commits / a2169d894a

[test case] Test for DeclareLocal instruction

--- Record incorrect output. If a declaration for an immutable identifier (i.e. one that is not later re-assigned, since `undefined` is a primitive) is sandwiched between mutations, we currently do not record it as an output or hoist it out of the reactive scope.

Mofei Zhang committed May 11, 2023 at 16:24 UTC a2169d894a380c184036ea020a8e149857eb3941
2 files changed +46
compiler/forget/src/__tests__/fixtures/compiler/_bug.uninitialized-declaration-in-reactive-scope.expect.md new
+40
@@ -0,0 +1,40 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(props) {
6 + let x = mutate();
7 + let y;
8 + foo(x);
9 + return [y, x];
10 +}
11 +
12 +```
13 +
14 +## Code
15 +
16 +```javascript
17 +import { unstable_useMemoCache as useMemoCache } from "react";
18 +function Component(props) {
19 + const $ = useMemoCache(2);
20 + let x;
21 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
22 + x = mutate();
23 + let y;
24 + foo(x);
25 + $[0] = x;
26 + } else {
27 + x = $[0];
28 + }
29 + let t0;
30 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
31 + t0 = [y, x];
32 + $[1] = t0;
33 + } else {
34 + t0 = $[1];
35 + }
36 + return t0;
37 +}
38 +
39 +```
40 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/_bug.uninitialized-declaration-in-reactive-scope.js new
+6
@@ -0,0 +1,6 @@
1 +function Component(props) {
2 + let x = mutate();
3 + let y;
4 + foo(x);
5 + return [y, x];
6 +}