3
4
```javascript
5
// @logger
6
-import { useState } from "react";
7
-import { identity, makeObject_Primitives, useHook } from "shared-runtime";
6
+import { createContext, use, useState } from "react";
7
+import {
8
+ Stringify,
9
+ identity,
10
+ makeObject_Primitives,
11
+ useHook,
12
+} from "shared-runtime";
13
14
function Component() {
15
+ const w = use(Context);
16
+
17
// The scopes for x and x2 are interleaved, so this is one scope with two values
18
const x = makeObject_Primitives();
19
const x2 = makeObject_Primitives();
33
}
34
35
// Overall we expect two pruned scopes (for x+x2, and obj), with 3 pruned scope values.
29
- return [x, x2, y, z];
36
+ return <Stringify items={[w, x, x2, y, z]} />;
37
+}
38
+
39
+const Context = createContext();
40
+
41
+function Wrapper() {
42
+ return (
43
+ <Context value={42}>
44
+ <Component />
45
+ </Context>
46
+ );
47
}
48
49
export const FIXTURE_ENTRYPOINT = {
33
- fn: Component,
50
+ fn: Wrapper,
51
params: [{}],
52
};
53
57
58
```javascript
59
import { c as _c } from "react/compiler-runtime"; // @logger
43
-import { useState } from "react";
44
-import { identity, makeObject_Primitives, useHook } from "shared-runtime";
60
+import { createContext, use, useState } from "react";
61
+import {
62
+ Stringify,
63
+ identity,
64
+ makeObject_Primitives,
65
+ useHook,
66
+} from "shared-runtime";
67
68
function Component() {
47
- const $ = _c(5);
69
+ const $ = _c(6);
70
+ const w = use(Context);
71
72
const x = makeObject_Primitives();
73
const x2 = makeObject_Primitives();
88
z = $[0];
89
}
90
let t0;
68
- if ($[1] !== x || $[2] !== x2 || $[3] !== y) {
69
- t0 = [x, x2, y, z];
70
- $[1] = x;
71
- $[2] = x2;
72
- $[3] = y;
73
- $[4] = t0;
91
+ if ($[1] !== w || $[2] !== x || $[3] !== x2 || $[4] !== y) {
92
+ t0 = <Stringify items={[w, x, x2, y, z]} />;
93
+ $[1] = w;
94
+ $[2] = x;
95
+ $[3] = x2;
96
+ $[4] = y;
97
+ $[5] = t0;
98
+ } else {
99
+ t0 = $[5];
100
+ }
101
+ return t0;
102
+}
103
+
104
+const Context = createContext();
105
+
106
+function Wrapper() {
107
+ const $ = _c(1);
108
+ let t0;
109
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
110
+ t0 = (
111
+ <Context value={42}>
112
+ <Component />
113
+ </Context>
114
+ );
115
+ $[0] = t0;
116
} else {
75
- t0 = $[4];
117
+ t0 = $[0];
118
}
119
return t0;
120
}
121
122
export const FIXTURE_ENTRYPOINT = {
81
- fn: Component,
123
+ fn: Wrapper,
124
params: [{}],
125
};
126
129
## Logs
130
131
```
90
-{"kind":"CompileSuccess","fnLoc":{"start":{"line":5,"column":0,"index":121},"end":{"line":26,"column":1,"index":813},"filename":"log-pruned-memoization.ts"},"fnName":"Component","memoSlots":5,"memoBlocks":2,"memoValues":2,"prunedMemoBlocks":2,"prunedMemoValues":3}
132
+{"kind":"CompileSuccess","fnLoc":{"start":{"line":10,"column":0,"index":161},"end":{"line":33,"column":1,"index":905},"filename":"log-pruned-memoization.ts"},"fnName":"Component","memoSlots":6,"memoBlocks":2,"memoValues":2,"prunedMemoBlocks":2,"prunedMemoValues":3}
133
+{"kind":"CompileSuccess","fnLoc":{"start":{"line":37,"column":0,"index":941},"end":{"line":43,"column":1,"index":1039},"filename":"log-pruned-memoization.ts"},"fnName":"Wrapper","memoSlots":1,"memoBlocks":1,"memoValues":1,"prunedMemoBlocks":0,"prunedMemoValues":0}
134
```
135
136
### Eval output
94
-(kind: ok) [{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},[{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true}]]
\ No newline at end of file
137
+(kind: ok) <div>{"items":[42,{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},[{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true},{"a":0,"b":"value1","c":true}]]}</div>
\ No newline at end of file