[test] Failing test for using hooks from React namespace
Forget assumes hooks are imported and used directly without the React namespace and generates incorrect code when if there's a namespace.
Sathya Gunasekaran committed
Jul 25, 2023 at 15:56 UTC
3f0afcbe471fdebab1b2df9c006d587f044aeb07
2 files changed
+34
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/_bug.hooks-with-React-namespace.expect.md
new
+30
@@ -0,0 +1,30 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Foo() {
6
+ const [x, setX] = React.useState(1);
7
+ return x;
8
+}
9
+
10
+```
11
+
12
+## Code
13
+
14
+```javascript
15
+import { unstable_useMemoCache as useMemoCache } from "react";
16
+function Foo() {
17
+ const $ = useMemoCache(1);
18
+ let t0;
19
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
20
+ t0 = React.useState(1);
21
+ $[0] = t0;
22
+ } else {
23
+ t0 = $[0];
24
+ }
25
+ const [x] = t0;
26
+ return x;
27
+}
28
+
29
+```
30
+
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/_bug.hooks-with-React-namespace.js
new
+4
@@ -0,0 +1,4 @@
1
+function Foo() {
2
+ const [x, setX] = React.useState(1);
3
+ return x;
4
+}