@samitouri / QOS-React-1 / commits / f6472522da

[repro] Fixture for incorrect lowering for break (label within loop)

--- unlabeled breaks must goto the nearest iteration or switch boundary (not labeled block) --- Sprout fails with the following: ``` FAIL: bug-unlabeled-break-within-label-loop >> Unexpected error during test: Found differences in evaluator results Non-forget (expected): (kind: ok) ["0 @A","0 @B","0 @C","1 @A"] Forget: (kind: ok) ["0 @A","0 @B","0 @C","1 @A","1 @C"] ```

Mofei Zhang committed Mar 22, 2024 at 16:14 UTC f6472522da8a756e300ca6914d081b8ea82f4646
3 files changed +82
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-unlabeled-break-within-label-loop.expect.md new
+62
@@ -0,0 +1,62 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function useHook(end) {
6 + const log = [];
7 + for (let i = 0; i < end + 1; i++) {
8 + log.push(`${i} @A`);
9 + bb0: {
10 + if (i === end) {
11 + break;
12 + }
13 + log.push(`${i} @B`);
14 + }
15 + log.push(`${i} @C`);
16 + }
17 + return log;
18 +}
19 +
20 +export const FIXTURE_ENTRYPOINT = {
21 + fn: useHook,
22 + params: [1],
23 +};
24 +
25 +```
26 +
27 +## Code
28 +
29 +```javascript
30 +import { unstable_useMemoCache as useMemoCache } from "react";
31 +function useHook(end) {
32 + const $ = useMemoCache(2);
33 + let log;
34 + if ($[0] !== end) {
35 + log = [];
36 + for (let i = 0; i < end + 1; i++) {
37 + log.push(`${i} @A`);
38 + bb6: {
39 + if (i === end) {
40 + break bb6;
41 + }
42 +
43 + log.push(`${i} @B`);
44 + }
45 +
46 + log.push(`${i} @C`);
47 + }
48 + $[0] = end;
49 + $[1] = log;
50 + } else {
51 + log = $[1];
52 + }
53 + return log;
54 +}
55 +
56 +export const FIXTURE_ENTRYPOINT = {
57 + fn: useHook,
58 + params: [1],
59 +};
60 +
61 +```
62 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-unlabeled-break-within-label-loop.ts new
+19
@@ -0,0 +1,19 @@
1 +function useHook(end) {
2 + const log = [];
3 + for (let i = 0; i < end + 1; i++) {
4 + log.push(`${i} @A`);
5 + bb0: {
6 + if (i === end) {
7 + break;
8 + }
9 + log.push(`${i} @B`);
10 + }
11 + log.push(`${i} @C`);
12 + }
13 + return log;
14 +}
15 +
16 +export const FIXTURE_ENTRYPOINT = {
17 + fn: useHook,
18 + params: [1],
19 +};
compiler/packages/snap/src/SproutTodoFilter.ts
+1
@@ -534,6 +534,7 @@ const skipFilter = new Set([
534 // bugs
535 "bug-reduce-reactive-deps-return-in-scope",
536 "bug-reduce-reactive-deps-break-in-scope",
537 + "bug-unlabeled-break-within-label-loop",
538
539 // 'react-forget-runtime' not yet supported
540 "flag-enable-emit-hook-guards",