[BE] Remove navigator; edit sprout fixtures
--- I recall adding the navigator override because some React library file had done an unconditional access, but this doesn't seem to be the case anymore. Regardless, newer versions of nodejs comes with a global `navigator` [see thread](https://github.com/nodejs/node/issues/39540) that error on writes
Mofei Zhang committed
Feb 12, 2024 at 19:12 UTC
a107ba81ed08e25696cb17a015b6c6f8bac606b0
10 files changed
+65
-68
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hoisting-computed-member-expression.expect.md
+19
-17
@@ -2,17 +2,21 @@
2
## Input
3
4
```javascript
5
+import { Stringify } from "shared-runtime";
6
+
7
function hoisting() {
6
- function onClick(x) {
7
- return x + bar["baz"];
8
+ function onClick() {
9
+ return bar["baz"];
10
}
9
- function onClick2(x) {
10
- return x + bar[baz];
11
+ function onClick2() {
12
+ return bar[baz];
13
}
14
const baz = "baz";
15
const bar = { baz: 1 };
16
15
- return <Button onClick={onClick} onClick2={onClick2} />;
17
+ return (
18
+ <Stringify onClick={onClick} onClick2={onClick2} shouldInvokeFns={true} />
19
+ );
20
}
21
22
export const FIXTURE_ENTRYPOINT = {
@@ -26,17 +30,19 @@ export const FIXTURE_ENTRYPOINT = {
30
31
```javascript
32
import { unstable_useMemoCache as useMemoCache } from "react";
33
+import { Stringify } from "shared-runtime";
34
+
35
function hoisting() {
36
const $ = useMemoCache(3);
37
let onClick;
38
let onClick2;
39
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
34
- onClick = function onClick(x) {
35
- return x + bar.baz;
40
+ onClick = function onClick() {
41
+ return bar.baz;
42
};
43
38
- onClick2 = function onClick2(x_0) {
39
- return x_0 + bar[baz];
44
+ onClick2 = function onClick2() {
45
+ return bar[baz];
46
};
47
48
const baz = "baz";
@@ -49,7 +55,9 @@ function hoisting() {
55
}
56
let t0;
57
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
52
- t0 = <Button onClick={onClick} onClick2={onClick2} />;
58
+ t0 = (
59
+ <Stringify onClick={onClick} onClick2={onClick2} shouldInvokeFns={true} />
60
+ );
61
$[2] = t0;
62
} else {
63
t0 = $[2];
@@ -65,10 +73,4 @@ export const FIXTURE_ENTRYPOINT = {
73
```
74
75
### Eval output
68
-(kind: exception) Button is not defined
69
-logs: ['The above error occurred in the <WrapperTestComponent> component:\n' +
70
- '\n' +
71
- ' at WrapperTestComponent (<project_root>/packages/sprout/dist/runner-evaluator.js:55:26)\n' +
72
- '\n' +
73
- 'Consider adding an error boundary to your tree to customize error handling behavior.\n' +
74
- 'Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.']
\ No newline at end of file
76
+(kind: ok) <div>{"onClick":{"kind":"Function","result":1},"onClick2":{"kind":"Function","result":1},"shouldInvokeFns":true}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hoisting-computed-member-expression.js
+9
-5
@@ -1,14 +1,18 @@
1
+import { Stringify } from "shared-runtime";
2
+
3
function hoisting() {
2
- function onClick(x) {
3
- return x + bar["baz"];
4
+ function onClick() {
5
+ return bar["baz"];
6
}
5
- function onClick2(x) {
6
- return x + bar[baz];
7
+ function onClick2() {
8
+ return bar[baz];
9
}
10
const baz = "baz";
11
const bar = { baz: 1 };
12
11
- return <Button onClick={onClick} onClick2={onClick2} />;
13
+ return (
14
+ <Stringify onClick={onClick} onClick2={onClick2} shouldInvokeFns={true} />
15
+ );
16
}
17
18
export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/iife-return-modified-later-phi.expect.md
+8
-15
@@ -10,7 +10,7 @@ function Component(props) {
10
return null;
11
}
12
})();
13
- items.push(props.a);
13
+ items?.push(props.a);
14
return items;
15
}
16
@@ -26,9 +26,9 @@ export const FIXTURE_ENTRYPOINT = {
26
```javascript
27
import { unstable_useMemoCache as useMemoCache } from "react";
28
function Component(props) {
29
- const $ = useMemoCache(3);
29
+ const $ = useMemoCache(2);
30
let items;
31
- if ($[0] !== props.cond || $[1] !== props.a) {
31
+ if ($[0] !== props) {
32
let t9;
33
if (props.cond) {
34
t9 = [];
@@ -37,12 +37,11 @@ function Component(props) {
37
}
38
items = t9;
39
40
- items.push(props.a);
41
- $[0] = props.cond;
42
- $[1] = props.a;
43
- $[2] = items;
40
+ items?.push(props.a);
41
+ $[0] = props;
42
+ $[1] = items;
43
} else {
45
- items = $[2];
44
+ items = $[1];
45
}
46
return items;
47
}
@@ -55,10 +54,4 @@ export const FIXTURE_ENTRYPOINT = {
54
```
55
56
### Eval output
58
-(kind: exception) Cannot read properties of null (reading 'push')
59
-logs: ['The above error occurred in the <WrapperTestComponent> component:\n' +
60
- '\n' +
61
- ' at WrapperTestComponent (<project_root>/packages/sprout/dist/runner-evaluator.js:55:26)\n' +
62
- '\n' +
63
- 'Consider adding an error boundary to your tree to customize error handling behavior.\n' +
64
- 'Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.']
\ No newline at end of file
57
+(kind: ok) null
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/iife-return-modified-later-phi.js
+1
-1
@@ -6,7 +6,7 @@ function Component(props) {
6
return null;
7
}
8
})();
9
- items.push(props.a);
9
+ items?.push(props.a);
10
return items;
11
}
12
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/rules-of-hooks/allow-locals-named-like-hooks.expect.md
+7
-8
@@ -13,11 +13,11 @@ function Component(props) {
13
let y = useFeature;
14
let z = useFeature.useProperty;
15
return (
16
- <div onClick={useFeature}>
16
+ <Stringify val={useFeature}>
17
{x}
18
{y}
19
{z}
20
- </div>
20
+ </Stringify>
21
);
22
}
23
@@ -54,11 +54,11 @@ function Component(props) {
54
let t1;
55
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
56
t1 = (
57
- <div onClick={useFeature}>
57
+ <Stringify val={useFeature}>
58
{x}
59
{y}
60
{z}
61
- </div>
61
+ </Stringify>
62
);
63
$[1] = t1;
64
} else {
@@ -75,11 +75,10 @@ export const FIXTURE_ENTRYPOINT = {
75
```
76
77
### Eval output
78
-(kind: exception) Objects are not valid as a React child (found: object with keys {a, b, c}). If you meant to render a collection of children, use an array instead.
79
-logs: ['The above error occurred in the <div> component:\n' +
78
+(kind: exception) Stringify is not defined
79
+logs: ['The above error occurred in the <WrapperTestComponent> component:\n' +
80
'\n' +
81
- ' at div\n' +
82
- ' at WrapperTestComponent (<project_root>/packages/sprout/dist/runner-evaluator.js:55:26)\n' +
81
+ ' at WrapperTestComponent (<project_root>/packages/sprout/dist/runner-evaluator.js:54:26)\n' +
82
'\n' +
83
'Consider adding an error boundary to your tree to customize error handling behavior.\n' +
84
'Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.']
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/rules-of-hooks/allow-locals-named-like-hooks.js
+2
-2
@@ -9,11 +9,11 @@ function Component(props) {
9
let y = useFeature;
10
let z = useFeature.useProperty;
11
return (
12
- <div onClick={useFeature}>
12
+ <Stringify val={useFeature}>
13
{x}
14
{y}
15
{z}
16
- </div>
16
+ </Stringify>
17
);
18
}
19
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/rules-of-hooks/allow-props-named-like-hooks.expect.md
+13
-15
@@ -2,6 +2,8 @@
2
## Input
3
4
```javascript
5
+import { Stringify } from "shared-runtime";
6
+
7
function Component({ useFeature }) {
8
let x;
9
if (useFeature) {
@@ -10,17 +12,17 @@ function Component({ useFeature }) {
12
let y = useFeature;
13
let z = useFeature.useProperty;
14
return (
13
- <div onClick={useFeature}>
15
+ <Stringify val={useFeature}>
16
{x}
17
{y}
18
{z}
17
- </div>
19
+ </Stringify>
20
);
21
}
22
23
export const FIXTURE_ENTRYPOINT = {
24
fn: Component,
23
- params: [{}],
25
+ params: [{ useFeature: { useProperty: true } }],
26
};
27
28
```
@@ -29,9 +31,11 @@ export const FIXTURE_ENTRYPOINT = {
31
32
```javascript
33
import { unstable_useMemoCache as useMemoCache } from "react";
32
-function Component(t28) {
34
+import { Stringify } from "shared-runtime";
35
+
36
+function Component(t29) {
37
const $ = useMemoCache(8);
34
- const { useFeature } = t28;
38
+ const { useFeature } = t29;
39
let x;
40
if (useFeature) {
41
const t0 = useFeature + useFeature;
@@ -52,11 +56,11 @@ function Component(t28) {
56
let t2;
57
if ($[3] !== useFeature || $[4] !== x || $[5] !== y || $[6] !== z) {
58
t2 = (
55
- <div onClick={useFeature}>
59
+ <Stringify val={useFeature}>
60
{x}
61
{y}
62
{z}
59
- </div>
63
+ </Stringify>
64
);
65
$[3] = useFeature;
66
$[4] = x;
@@ -71,16 +75,10 @@ function Component(t28) {
75
76
export const FIXTURE_ENTRYPOINT = {
77
fn: Component,
74
- params: [{}],
78
+ params: [{ useFeature: { useProperty: true } }],
79
};
80
81
```
82
83
### Eval output
80
-(kind: exception) Cannot read properties of undefined (reading 'useProperty')
81
-logs: ['The above error occurred in the <WrapperTestComponent> component:\n' +
82
- '\n' +
83
- ' at WrapperTestComponent (<project_root>/packages/sprout/dist/runner-evaluator.js:55:26)\n' +
84
- '\n' +
85
- 'Consider adding an error boundary to your tree to customize error handling behavior.\n' +
86
- 'Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.']
\ No newline at end of file
84
+(kind: ok) <div>{"val":{"useProperty":true},"children":[2,"[[ cyclic ref *1 ]]",true]}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/rules-of-hooks/allow-props-named-like-hooks.js
+5
-3
@@ -1,3 +1,5 @@
1
+import { Stringify } from "shared-runtime";
2
+
3
function Component({ useFeature }) {
4
let x;
5
if (useFeature) {
@@ -6,15 +8,15 @@ function Component({ useFeature }) {
8
let y = useFeature;
9
let z = useFeature.useProperty;
10
return (
9
- <div onClick={useFeature}>
11
+ <Stringify val={useFeature}>
12
{x}
13
{y}
14
{z}
13
- </div>
15
+ </Stringify>
16
);
17
}
18
19
export const FIXTURE_ENTRYPOINT = {
20
fn: Component,
19
- params: [{}],
21
+ params: [{ useFeature: { useProperty: true } }],
22
};
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ssa-throw.expect.md
+1
-1
@@ -37,7 +37,7 @@ export const FIXTURE_ENTRYPOINT = {
37
(kind: exception) undefined
38
logs: ['The above error occurred in the <WrapperTestComponent> component:\n' +
39
'\n' +
40
- ' at WrapperTestComponent (<project_root>/packages/sprout/dist/runner-evaluator.js:55:26)\n' +
40
+ ' at WrapperTestComponent (<project_root>/packages/sprout/dist/runner-evaluator.js:54:26)\n' +
41
'\n' +
42
'Consider adding an error boundary to your tree to customize error handling behavior.\n' +
43
'Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.']
\ No newline at end of file
compiler/packages/sprout/src/runner-evaluator.ts
-1
@@ -24,7 +24,6 @@ const React = require("react");
24
const { window: testWindow } = new JSDOM(undefined);
25
(globalThis as any).document = testWindow.document;
26
(globalThis as any).window = testWindow.window;
27
-(globalThis as any).navigator = testWindow.navigator;
27
(globalThis as any).React = React;
28
(globalThis as any).render = render;
29
initFbt();