@samitouri / QOS-React-2 / commits / e45f69154f

Fix dropped temporary in value block

Joe Savona committed Feb 16, 2023 at 08:57 UTC e45f69154f3f4dd2868cad7e86407a701d0af6ec
3 files changed +38
compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts
+1
@@ -520,6 +520,7 @@ class Driver {
520 const sequence: ReactiveSequenceValue = {
521 kind: "SequenceExpression",
522 instructions: [
523 + ...defaultBlock.instructions,
524 {
525 id: init.id,
526 loc,
compiler/forget/src/__tests__/fixtures/hir/temporary-at-start-of-value-block.expect.md new
+32
@@ -0,0 +1,32 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function component(props) {
6 + // NOTE: the temporary for the leading space was previously dropped
7 + const x = isMenuShown ? <Bar> {props.a ? props.b : props.c}</Bar> : null;
8 + return x;
9 +}
10 +
11 +```
12 +
13 +## Code
14 +
15 +```javascript
16 +function component(props) {
17 + const $ = React.unstable_useMemoCache();
18 + const c_0 = $[0] !== props;
19 + let t0;
20 + if (c_0) {
21 + t0 = isMenuShown ? <Bar> {props.a ? props.b : props.c}</Bar> : null;
22 + $[0] = props;
23 + $[1] = t0;
24 + } else {
25 + t0 = $[1];
26 + }
27 + const x = t0;
28 + return x;
29 +}
30 +
31 +```
32 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/temporary-at-start-of-value-block.js new
+5
@@ -0,0 +1,5 @@
1 +function component(props) {
2 + // NOTE: the temporary for the leading space was previously dropped
3 + const x = isMenuShown ? <Bar> {props.a ? props.b : props.c}</Bar> : null;
4 + return x;
5 +}