diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-for-loop-with-context-variable-iterator.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-for-loop-with-context-variable-iterator.expect.md new file mode 100644 index 0000000000..a2fb2d6d60 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-for-loop-with-context-variable-iterator.expect.md @@ -0,0 +1,35 @@ + +## Input + +```javascript +function Component() { + const data = useData(); + const items = []; + // NOTE: `i` is a context variable because it's reassigned and also referenced + // within a closure, the `onClick` handler of each item + for (let i = MIN; i <= MAX; i += INCREMENT) { + items.push( data.set(i)} />); + } + return items; +} + +``` + + +## Error + +``` + 4 | // NOTE: `i` is a context variable because it's reassigned and also referenced + 5 | // within a closure, the `onClick` handler of each item +> 6 | for (let i = MIN; i <= MAX; i += INCREMENT) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> 7 | items.push( data.set(i)} />); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +> 8 | } + | ^^^^ [ReactForget] Invariant: Expected a variable declaration (6:8) + 9 | return items; + 10 | } + 11 | +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-for-loop-with-context-variable-iterator.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-for-loop-with-context-variable-iterator.js new file mode 100644 index 0000000000..5330874b89 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-for-loop-with-context-variable-iterator.js @@ -0,0 +1,10 @@ +function Component() { + const data = useData(); + const items = []; + // NOTE: `i` is a context variable because it's reassigned and also referenced + // within a closure, the `onClick` handler of each item + for (let i = MIN; i <= MAX; i += INCREMENT) { + items.push( data.set(i)} />); + } + return items; +}