@samitouri / QOS-React / commits / 21bb8f9e75

Repro for inconsistent context/local variable reference

We currently assume JSX element tags are always locals, and need to check which load kind to use. Fixed in the next PR.

Joe Savona committed Mar 21, 2024 at 17:12 UTC 21bb8f9e75be24a7730c890409a53bc2120eef68
2 files changed +38
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-context-variable-as-jsx-element-tag.expect.md new
+29
@@ -0,0 +1,29 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(props) {
6 + let Component = Foo;
7 +
8 + Component = useMemo(() => {
9 + return Component;
10 + });
11 +
12 + return <Component />;
13 +}
14 +
15 +```
16 +
17 +
18 +## Error
19 +
20 +```
21 + 6 | });
22 + 7 |
23 +> 8 | return <Component />;
24 + | ^^^^^^^^^ [ReactForget] Invariant: Expected all references to a variable to be consistently local or context references. Identifier <unknown> Component$2 is referenced as a local variable, but was previously referenced as a context variable (8:8)
25 + 9 | }
26 + 10 |
27 +```
28 +
29 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-context-variable-as-jsx-element-tag.js new
+9
@@ -0,0 +1,9 @@
1 +function Component(props) {
2 + let Component = Foo;
3 +
4 + Component = useMemo(() => {
5 + return Component;
6 + });
7 +
8 + return <Component />;
9 +}