Gugu8 commited on
Commit
f167dd1
·
verified ·
1 Parent(s): 9bed46b

Add github_code/react__react from GitHub - direct commit (part 7)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-recursive-call-within-lambda.js +17 -0
  2. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-recursive-call.expect.md +57 -0
  3. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-recursive-call.ts +16 -0
  4. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-repro-variable-used-in-assignment.expect.md +50 -0
  5. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-repro-variable-used-in-assignment.js +13 -0
  6. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-setstate-captured-indirectly-jsx.expect.md +73 -0
  7. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-setstate-captured-indirectly-jsx.js +17 -0
  8. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-const-declaration.expect.md +50 -0
  9. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-const-declaration.js +14 -0
  10. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-function-expression.expect.md +54 -0
  11. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-function-expression.js +16 -0
  12. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-let-declaration.expect.md +50 -0
  13. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-let-declaration.js +14 -0
  14. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-skip-type-alias-declarations.expect.md +51 -0
  15. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-skip-type-alias-declarations.js +13 -0
  16. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-within-lambda.expect.md +53 -0
  17. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-within-lambda.js +15 -0
  18. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-expr.expect.md +49 -0
  19. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-expr.js +12 -0
  20. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-pattern-dce-2.expect.md +33 -0
  21. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-pattern-dce-2.js +10 -0
  22. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-pattern-dce.expect.md +33 -0
  23. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-pattern-dce.js +10 -0
  24. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call-freezes-captured-memberexpr.expect.md +87 -0
  25. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call-freezes-captured-memberexpr.tsx +21 -0
  26. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call.expect.md +58 -0
  27. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call.js +14 -0
  28. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-declaration-basic.flow.expect.md +42 -0
  29. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-declaration-basic.flow.js +9 -0
  30. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-inside-logical-expression.expect.md +37 -0
  31. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-inside-logical-expression.js +12 -0
  32. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-noAlias.expect.md +64 -0
  33. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-noAlias.js +15 -0
  34. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-property-load-local.expect.md +40 -0
  35. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-property-load-local.js +12 -0
  36. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-ref-callback.expect.md +54 -0
  37. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-ref-callback.js +15 -0
  38. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-freeze-arguments.expect.md +42 -0
  39. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-freeze-arguments.js +10 -0
  40. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-freeze-possibly-mutable-arguments.expect.md +57 -0
  41. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-freeze-possibly-mutable-arguments.js +17 -0
  42. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-with-React-namespace.expect.md +33 -0
  43. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-with-React-namespace.js +9 -0
  44. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-method-no-outlining-wildcard.expect.md +113 -0
  45. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-method-no-outlining-wildcard.js +23 -0
  46. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-method-no-outlining.expect.md +79 -0
  47. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-method-no-outlining.js +17 -0
  48. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-no-outlining.expect.md +62 -0
  49. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-no-outlining.js +13 -0
  50. github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.expect.md +35 -0
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-recursive-call-within-lambda.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function Foo({}) {
2
+ const outer = val => {
3
+ const fact = x => {
4
+ if (x <= 0) {
5
+ return 1;
6
+ }
7
+ return x * fact(x - 1);
8
+ };
9
+ return fact(val);
10
+ };
11
+ return outer(3);
12
+ }
13
+
14
+ export const FIXTURE_ENTRYPOINT = {
15
+ fn: Foo,
16
+ params: [{}],
17
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-recursive-call.expect.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function Foo({value}: {value: number}) {
6
+ const factorial = (x: number) => {
7
+ if (x <= 1) {
8
+ return 1;
9
+ } else {
10
+ return x * factorial(x - 1);
11
+ }
12
+ };
13
+
14
+ return factorial(value);
15
+ }
16
+
17
+ export const FIXTURE_ENTRYPOINT = {
18
+ fn: Foo,
19
+ params: [{value: 3}],
20
+ };
21
+
22
+ ```
23
+
24
+ ## Code
25
+
26
+ ```javascript
27
+ import { c as _c } from "react/compiler-runtime";
28
+ function Foo(t0) {
29
+ const $ = _c(2);
30
+ const { value } = t0;
31
+ let t1;
32
+ if ($[0] !== value) {
33
+ const factorial = (x) => {
34
+ if (x <= 1) {
35
+ return 1;
36
+ } else {
37
+ return x * factorial(x - 1);
38
+ }
39
+ };
40
+ t1 = factorial(value);
41
+ $[0] = value;
42
+ $[1] = t1;
43
+ } else {
44
+ t1 = $[1];
45
+ }
46
+ return t1;
47
+ }
48
+
49
+ export const FIXTURE_ENTRYPOINT = {
50
+ fn: Foo,
51
+ params: [{ value: 3 }],
52
+ };
53
+
54
+ ```
55
+
56
+ ### Eval output
57
+ (kind: ok) 6
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-recursive-call.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function Foo({value}: {value: number}) {
2
+ const factorial = (x: number) => {
3
+ if (x <= 1) {
4
+ return 1;
5
+ } else {
6
+ return x * factorial(x - 1);
7
+ }
8
+ };
9
+
10
+ return factorial(value);
11
+ }
12
+
13
+ export const FIXTURE_ENTRYPOINT = {
14
+ fn: Foo,
15
+ params: [{value: 3}],
16
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-repro-variable-used-in-assignment.expect.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function get2() {
6
+ const callbk = () => {
7
+ const copy = x;
8
+ return copy;
9
+ };
10
+ const x = 2;
11
+ return callbk();
12
+ }
13
+
14
+ export const FIXTURE_ENTRYPOINT = {
15
+ fn: get2,
16
+ params: [],
17
+ };
18
+
19
+ ```
20
+
21
+ ## Code
22
+
23
+ ```javascript
24
+ import { c as _c } from "react/compiler-runtime";
25
+ function get2() {
26
+ const $ = _c(1);
27
+ let t0;
28
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
29
+ const callbk = () => {
30
+ const copy = x;
31
+ return copy;
32
+ };
33
+ const x = 2;
34
+ t0 = callbk();
35
+ $[0] = t0;
36
+ } else {
37
+ t0 = $[0];
38
+ }
39
+ return t0;
40
+ }
41
+
42
+ export const FIXTURE_ENTRYPOINT = {
43
+ fn: get2,
44
+ params: [],
45
+ };
46
+
47
+ ```
48
+
49
+ ### Eval output
50
+ (kind: ok) 2
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-repro-variable-used-in-assignment.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function get2() {
2
+ const callbk = () => {
3
+ const copy = x;
4
+ return copy;
5
+ };
6
+ const x = 2;
7
+ return callbk();
8
+ }
9
+
10
+ export const FIXTURE_ENTRYPOINT = {
11
+ fn: get2,
12
+ params: [],
13
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-setstate-captured-indirectly-jsx.expect.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ // @validatePreserveExistingMemoizationGuarantees
6
+ function useFoo() {
7
+ const onClick = response => {
8
+ setState(DISABLED_FORM);
9
+ };
10
+
11
+ const [state, setState] = useState();
12
+ const handleLogout = useCallback(() => {
13
+ setState(DISABLED_FORM);
14
+ }, [setState]);
15
+ const getComponent = () => {
16
+ return <ColumnItem onPress={() => handleLogout()} />;
17
+ };
18
+
19
+ // this `getComponent` call should not be inferred as mutating setState
20
+ return [getComponent(), onClick]; // pass onClick to avoid dce
21
+ }
22
+
23
+ ```
24
+
25
+ ## Code
26
+
27
+ ```javascript
28
+ import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
29
+ function useFoo() {
30
+ const $ = _c(7);
31
+ const onClick = (response) => {
32
+ setState(DISABLED_FORM);
33
+ };
34
+
35
+ const [, t0] = useState();
36
+ const setState = t0;
37
+ let t1;
38
+ if ($[0] !== setState) {
39
+ t1 = () => {
40
+ setState(DISABLED_FORM);
41
+ };
42
+ $[0] = setState;
43
+ $[1] = t1;
44
+ } else {
45
+ t1 = $[1];
46
+ }
47
+ setState;
48
+ const handleLogout = t1;
49
+ let t2;
50
+ if ($[2] !== handleLogout) {
51
+ const getComponent = () => <ColumnItem onPress={() => handleLogout()} />;
52
+ t2 = getComponent();
53
+ $[2] = handleLogout;
54
+ $[3] = t2;
55
+ } else {
56
+ t2 = $[3];
57
+ }
58
+ let t3;
59
+ if ($[4] !== onClick || $[5] !== t2) {
60
+ t3 = [t2, onClick];
61
+ $[4] = onClick;
62
+ $[5] = t2;
63
+ $[6] = t3;
64
+ } else {
65
+ t3 = $[6];
66
+ }
67
+ return t3;
68
+ }
69
+
70
+ ```
71
+
72
+ ### Eval output
73
+ (kind: exception) Fixture not implemented
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-setstate-captured-indirectly-jsx.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @validatePreserveExistingMemoizationGuarantees
2
+ function useFoo() {
3
+ const onClick = response => {
4
+ setState(DISABLED_FORM);
5
+ };
6
+
7
+ const [state, setState] = useState();
8
+ const handleLogout = useCallback(() => {
9
+ setState(DISABLED_FORM);
10
+ }, [setState]);
11
+ const getComponent = () => {
12
+ return <ColumnItem onPress={() => handleLogout()} />;
13
+ };
14
+
15
+ // this `getComponent` call should not be inferred as mutating setState
16
+ return [getComponent(), onClick]; // pass onClick to avoid dce
17
+ }
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-const-declaration.expect.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function hoisting() {
6
+ const foo = () => {
7
+ return bar + baz;
8
+ };
9
+ const bar = 3;
10
+ const baz = 2;
11
+ return foo(); // OK: called outside of TDZ for bar/baz
12
+ }
13
+
14
+ export const FIXTURE_ENTRYPOINT = {
15
+ fn: hoisting,
16
+ params: [],
17
+ isComponent: false,
18
+ };
19
+
20
+ ```
21
+
22
+ ## Code
23
+
24
+ ```javascript
25
+ import { c as _c } from "react/compiler-runtime";
26
+ function hoisting() {
27
+ const $ = _c(1);
28
+ let foo;
29
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30
+ foo = () => bar + baz;
31
+
32
+ const bar = 3;
33
+ const baz = 2;
34
+ $[0] = foo;
35
+ } else {
36
+ foo = $[0];
37
+ }
38
+ return foo();
39
+ }
40
+
41
+ export const FIXTURE_ENTRYPOINT = {
42
+ fn: hoisting,
43
+ params: [],
44
+ isComponent: false,
45
+ };
46
+
47
+ ```
48
+
49
+ ### Eval output
50
+ (kind: ok) 5
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-const-declaration.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function hoisting() {
2
+ const foo = () => {
3
+ return bar + baz;
4
+ };
5
+ const bar = 3;
6
+ const baz = 2;
7
+ return foo(); // OK: called outside of TDZ for bar/baz
8
+ }
9
+
10
+ export const FIXTURE_ENTRYPOINT = {
11
+ fn: hoisting,
12
+ params: [],
13
+ isComponent: false,
14
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-function-expression.expect.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function hoisting() {
6
+ const foo = () => {
7
+ return bar();
8
+ };
9
+ const bar = () => {
10
+ return 1;
11
+ };
12
+
13
+ return foo(); // OK: bar's value is only accessed outside of its TDZ
14
+ }
15
+
16
+ export const FIXTURE_ENTRYPOINT = {
17
+ fn: hoisting,
18
+ params: [],
19
+ isComponent: false,
20
+ };
21
+
22
+ ```
23
+
24
+ ## Code
25
+
26
+ ```javascript
27
+ import { c as _c } from "react/compiler-runtime";
28
+ function hoisting() {
29
+ const $ = _c(1);
30
+ let t0;
31
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
32
+ const foo = () => bar();
33
+ const bar = _temp;
34
+ t0 = foo();
35
+ $[0] = t0;
36
+ } else {
37
+ t0 = $[0];
38
+ }
39
+ return t0;
40
+ }
41
+ function _temp() {
42
+ return 1;
43
+ }
44
+
45
+ export const FIXTURE_ENTRYPOINT = {
46
+ fn: hoisting,
47
+ params: [],
48
+ isComponent: false,
49
+ };
50
+
51
+ ```
52
+
53
+ ### Eval output
54
+ (kind: ok) 1
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-function-expression.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function hoisting() {
2
+ const foo = () => {
3
+ return bar();
4
+ };
5
+ const bar = () => {
6
+ return 1;
7
+ };
8
+
9
+ return foo(); // OK: bar's value is only accessed outside of its TDZ
10
+ }
11
+
12
+ export const FIXTURE_ENTRYPOINT = {
13
+ fn: hoisting,
14
+ params: [],
15
+ isComponent: false,
16
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-let-declaration.expect.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function hoisting() {
6
+ let foo = () => {
7
+ return bar + baz;
8
+ };
9
+ let bar = 3;
10
+ let baz = 2;
11
+ return foo(); // OK: called outside of TDZ for bar/baz
12
+ }
13
+
14
+ export const FIXTURE_ENTRYPOINT = {
15
+ fn: hoisting,
16
+ params: [],
17
+ isComponent: false,
18
+ };
19
+
20
+ ```
21
+
22
+ ## Code
23
+
24
+ ```javascript
25
+ import { c as _c } from "react/compiler-runtime";
26
+ function hoisting() {
27
+ const $ = _c(1);
28
+ let foo;
29
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30
+ foo = () => bar + baz;
31
+
32
+ let bar = 3;
33
+ let baz = 2;
34
+ $[0] = foo;
35
+ } else {
36
+ foo = $[0];
37
+ }
38
+ return foo();
39
+ }
40
+
41
+ export const FIXTURE_ENTRYPOINT = {
42
+ fn: hoisting,
43
+ params: [],
44
+ isComponent: false,
45
+ };
46
+
47
+ ```
48
+
49
+ ### Eval output
50
+ (kind: ok) 5
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-simple-let-declaration.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function hoisting() {
2
+ let foo = () => {
3
+ return bar + baz;
4
+ };
5
+ let bar = 3;
6
+ let baz = 2;
7
+ return foo(); // OK: called outside of TDZ for bar/baz
8
+ }
9
+
10
+ export const FIXTURE_ENTRYPOINT = {
11
+ fn: hoisting,
12
+ params: [],
13
+ isComponent: false,
14
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-skip-type-alias-declarations.expect.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ // @flow
6
+ type Item = {id: string, name: string};
7
+
8
+ function Component({items}: {items: Array<Item>}) {
9
+ const onClick = () => {
10
+ const mapped: Array<Item> = items.map(item => ({
11
+ id: item.id,
12
+ name: item.name.toUpperCase(),
13
+ }));
14
+ submit(mapped);
15
+ };
16
+ return <Button onClick={onClick} />;
17
+ }
18
+
19
+ ```
20
+
21
+ ## Code
22
+
23
+ ```javascript
24
+ import { c as _c } from "react/compiler-runtime";
25
+ type Item = { id: string, name: string };
26
+
27
+ function Component(t0) {
28
+ const $ = _c(2);
29
+ const { items } = t0;
30
+ let t1;
31
+ if ($[0] !== items) {
32
+ const onClick = () => {
33
+ const mapped = items.map(_temp);
34
+ submit(mapped);
35
+ };
36
+ t1 = <Button onClick={onClick} />;
37
+ $[0] = items;
38
+ $[1] = t1;
39
+ } else {
40
+ t1 = $[1];
41
+ }
42
+ return t1;
43
+ }
44
+ function _temp(item) {
45
+ return { id: item.id, name: item.name.toUpperCase() };
46
+ }
47
+
48
+ ```
49
+
50
+ ### Eval output
51
+ (kind: exception) Fixture not implemented
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-skip-type-alias-declarations.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+ type Item = {id: string, name: string};
3
+
4
+ function Component({items}: {items: Array<Item>}) {
5
+ const onClick = () => {
6
+ const mapped: Array<Item> = items.map(item => ({
7
+ id: item.id,
8
+ name: item.name.toUpperCase(),
9
+ }));
10
+ submit(mapped);
11
+ };
12
+ return <Button onClick={onClick} />;
13
+ }
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-within-lambda.expect.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function Component({}) {
6
+ const outer = () => {
7
+ const inner = () => {
8
+ return x;
9
+ };
10
+ const x = 3;
11
+ return inner();
12
+ };
13
+ return <div>{outer()}</div>;
14
+ }
15
+
16
+ export const FIXTURE_ENTRYPOINT = {
17
+ fn: Component,
18
+ params: [{}],
19
+ };
20
+
21
+ ```
22
+
23
+ ## Code
24
+
25
+ ```javascript
26
+ import { c as _c } from "react/compiler-runtime";
27
+ function Component(t0) {
28
+ const $ = _c(1);
29
+ const outer = _temp;
30
+ let t1;
31
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
32
+ t1 = <div>{outer()}</div>;
33
+ $[0] = t1;
34
+ } else {
35
+ t1 = $[0];
36
+ }
37
+ return t1;
38
+ }
39
+ function _temp() {
40
+ const inner = () => x;
41
+ const x = 3;
42
+ return inner();
43
+ }
44
+
45
+ export const FIXTURE_ENTRYPOINT = {
46
+ fn: Component,
47
+ params: [{}],
48
+ };
49
+
50
+ ```
51
+
52
+ ### Eval output
53
+ (kind: ok) <div>3</div>
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-within-lambda.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function Component({}) {
2
+ const outer = () => {
3
+ const inner = () => {
4
+ return x;
5
+ };
6
+ const x = 3;
7
+ return inner();
8
+ };
9
+ return <div>{outer()}</div>;
10
+ }
11
+
12
+ export const FIXTURE_ENTRYPOINT = {
13
+ fn: Component,
14
+ params: [{}],
15
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-expr.expect.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ import {CONST_STRING0} from 'shared-runtime';
6
+
7
+ function t(props) {
8
+ let x = [, CONST_STRING0, props];
9
+ return x;
10
+ }
11
+
12
+ export const FIXTURE_ENTRYPOINT = {
13
+ fn: t,
14
+ params: [{a: 1, b: 2}],
15
+ isComponent: false,
16
+ };
17
+
18
+ ```
19
+
20
+ ## Code
21
+
22
+ ```javascript
23
+ import { c as _c } from "react/compiler-runtime";
24
+ import { CONST_STRING0 } from "shared-runtime";
25
+
26
+ function t(props) {
27
+ const $ = _c(2);
28
+ let t0;
29
+ if ($[0] !== props) {
30
+ t0 = [, CONST_STRING0, props];
31
+ $[0] = props;
32
+ $[1] = t0;
33
+ } else {
34
+ t0 = $[1];
35
+ }
36
+ const x = t0;
37
+ return x;
38
+ }
39
+
40
+ export const FIXTURE_ENTRYPOINT = {
41
+ fn: t,
42
+ params: [{ a: 1, b: 2 }],
43
+ isComponent: false,
44
+ };
45
+
46
+ ```
47
+
48
+ ### Eval output
49
+ (kind: ok) [null,"global string 0",{"a":1,"b":2}]
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-expr.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {CONST_STRING0} from 'shared-runtime';
2
+
3
+ function t(props) {
4
+ let x = [, CONST_STRING0, props];
5
+ return x;
6
+ }
7
+
8
+ export const FIXTURE_ENTRYPOINT = {
9
+ fn: t,
10
+ params: [{a: 1, b: 2}],
11
+ isComponent: false,
12
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-pattern-dce-2.expect.md ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function t(props) {
6
+ let [foo, bar, ,] = props;
7
+ return foo;
8
+ }
9
+
10
+ export const FIXTURE_ENTRYPOINT = {
11
+ fn: t,
12
+ params: ['TodoAdd'],
13
+ isComponent: 'TodoAdd',
14
+ };
15
+
16
+ ```
17
+
18
+ ## Code
19
+
20
+ ```javascript
21
+ function t(props) {
22
+ const [foo] = props;
23
+ return foo;
24
+ }
25
+
26
+ export const FIXTURE_ENTRYPOINT = {
27
+ fn: t,
28
+ params: ["TodoAdd"],
29
+ isComponent: "TodoAdd",
30
+ };
31
+
32
+ ```
33
+
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-pattern-dce-2.js ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ function t(props) {
2
+ let [foo, bar, ,] = props;
3
+ return foo;
4
+ }
5
+
6
+ export const FIXTURE_ENTRYPOINT = {
7
+ fn: t,
8
+ params: ['TodoAdd'],
9
+ isComponent: 'TodoAdd',
10
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-pattern-dce.expect.md ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function t(props) {
6
+ let [, foo, bar] = props;
7
+ return foo;
8
+ }
9
+
10
+ export const FIXTURE_ENTRYPOINT = {
11
+ fn: t,
12
+ params: ['TodoAdd'],
13
+ isComponent: 'TodoAdd',
14
+ };
15
+
16
+ ```
17
+
18
+ ## Code
19
+
20
+ ```javascript
21
+ function t(props) {
22
+ const [, foo] = props;
23
+ return foo;
24
+ }
25
+
26
+ export const FIXTURE_ENTRYPOINT = {
27
+ fn: t,
28
+ params: ["TodoAdd"],
29
+ isComponent: "TodoAdd",
30
+ };
31
+
32
+ ```
33
+
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/holey-array-pattern-dce.js ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ function t(props) {
2
+ let [, foo, bar] = props;
3
+ return foo;
4
+ }
5
+
6
+ export const FIXTURE_ENTRYPOINT = {
7
+ fn: t,
8
+ params: ['TodoAdd'],
9
+ isComponent: 'TodoAdd',
10
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call-freezes-captured-memberexpr.expect.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ import {useIdentity, Stringify, identity} from 'shared-runtime';
6
+
7
+ function Foo({val1}) {
8
+ // `x={inner: val1}` should be able to be memoized
9
+ const x = {inner: val1};
10
+
11
+ // Any references to `x` after this hook call should be read-only
12
+ const cb = useIdentity(() => x.inner);
13
+
14
+ // With enableTransitivelyFreezeFunctionExpressions, it's invalid
15
+ // to write to `x` after it's been frozen.
16
+ // TODO: runtime validation for DX
17
+ const copy = identity(x);
18
+ return <Stringify copy={copy} cb={cb} shouldInvokeFns={true} />;
19
+ }
20
+
21
+ export const FIXTURE_ENTRYPOINT = {
22
+ fn: Foo,
23
+ params: [{val1: 1}],
24
+ sequentialRenders: [{val1: 1}, {val1: 1}],
25
+ };
26
+
27
+ ```
28
+
29
+ ## Code
30
+
31
+ ```javascript
32
+ import { c as _c } from "react/compiler-runtime";
33
+ import { useIdentity, Stringify, identity } from "shared-runtime";
34
+
35
+ function Foo(t0) {
36
+ const $ = _c(9);
37
+ const { val1 } = t0;
38
+ let t1;
39
+ if ($[0] !== val1) {
40
+ t1 = { inner: val1 };
41
+ $[0] = val1;
42
+ $[1] = t1;
43
+ } else {
44
+ t1 = $[1];
45
+ }
46
+ const x = t1;
47
+ let t2;
48
+ if ($[2] !== x.inner) {
49
+ t2 = () => x.inner;
50
+ $[2] = x.inner;
51
+ $[3] = t2;
52
+ } else {
53
+ t2 = $[3];
54
+ }
55
+ const cb = useIdentity(t2);
56
+ let t3;
57
+ if ($[4] !== x) {
58
+ t3 = identity(x);
59
+ $[4] = x;
60
+ $[5] = t3;
61
+ } else {
62
+ t3 = $[5];
63
+ }
64
+ const copy = t3;
65
+ let t4;
66
+ if ($[6] !== cb || $[7] !== copy) {
67
+ t4 = <Stringify copy={copy} cb={cb} shouldInvokeFns={true} />;
68
+ $[6] = cb;
69
+ $[7] = copy;
70
+ $[8] = t4;
71
+ } else {
72
+ t4 = $[8];
73
+ }
74
+ return t4;
75
+ }
76
+
77
+ export const FIXTURE_ENTRYPOINT = {
78
+ fn: Foo,
79
+ params: [{ val1: 1 }],
80
+ sequentialRenders: [{ val1: 1 }, { val1: 1 }],
81
+ };
82
+
83
+ ```
84
+
85
+ ### Eval output
86
+ (kind: ok) <div>{"copy":{"inner":1},"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}</div>
87
+ <div>{"copy":{"inner":1},"cb":{"kind":"Function","result":1},"shouldInvokeFns":true}</div>
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call-freezes-captured-memberexpr.tsx ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {useIdentity, Stringify, identity} from 'shared-runtime';
2
+
3
+ function Foo({val1}) {
4
+ // `x={inner: val1}` should be able to be memoized
5
+ const x = {inner: val1};
6
+
7
+ // Any references to `x` after this hook call should be read-only
8
+ const cb = useIdentity(() => x.inner);
9
+
10
+ // With enableTransitivelyFreezeFunctionExpressions, it's invalid
11
+ // to write to `x` after it's been frozen.
12
+ // TODO: runtime validation for DX
13
+ const copy = identity(x);
14
+ return <Stringify copy={copy} cb={cb} shouldInvokeFns={true} />;
15
+ }
16
+
17
+ export const FIXTURE_ENTRYPOINT = {
18
+ fn: Foo,
19
+ params: [{val1: 1}],
20
+ sequentialRenders: [{val1: 1}, {val1: 1}],
21
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call.expect.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function useFreeze() {}
6
+ function foo() {}
7
+
8
+ function Component(props) {
9
+ const x = [];
10
+ const y = useFreeze(x);
11
+ foo(y, x);
12
+ return (
13
+ <Component>
14
+ {x}
15
+ {y}
16
+ </Component>
17
+ );
18
+ }
19
+
20
+ ```
21
+
22
+ ## Code
23
+
24
+ ```javascript
25
+ import { c as _c } from "react/compiler-runtime";
26
+ function useFreeze() {}
27
+ function foo() {}
28
+
29
+ function Component(props) {
30
+ const $ = _c(3);
31
+ let t0;
32
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
33
+ t0 = [];
34
+ $[0] = t0;
35
+ } else {
36
+ t0 = $[0];
37
+ }
38
+ const x = t0;
39
+ const y = useFreeze(x);
40
+ foo(y, x);
41
+ let t1;
42
+ if ($[1] !== y) {
43
+ t1 = (
44
+ <Component>
45
+ {x}
46
+ {y}
47
+ </Component>
48
+ );
49
+ $[1] = y;
50
+ $[2] = t1;
51
+ } else {
52
+ t1 = $[2];
53
+ }
54
+ return t1;
55
+ }
56
+
57
+ ```
58
+
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function useFreeze() {}
2
+ function foo() {}
3
+
4
+ function Component(props) {
5
+ const x = [];
6
+ const y = useFreeze(x);
7
+ foo(y, x);
8
+ return (
9
+ <Component>
10
+ {x}
11
+ {y}
12
+ </Component>
13
+ );
14
+ }
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-declaration-basic.flow.expect.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ // @flow @compilationMode:"infer"
6
+ export default hook useFoo(bar: number) {
7
+ return [bar];
8
+ }
9
+
10
+ export const FIXTURE_ENTRYPOINT = {
11
+ fn: useFoo,
12
+ params: [42],
13
+ };
14
+
15
+ ```
16
+
17
+ ## Code
18
+
19
+ ```javascript
20
+ import { c as _c } from "react/compiler-runtime";
21
+ export default function useFoo(bar) {
22
+ const $ = _c(2);
23
+ let t0;
24
+ if ($[0] !== bar) {
25
+ t0 = [bar];
26
+ $[0] = bar;
27
+ $[1] = t0;
28
+ } else {
29
+ t0 = $[1];
30
+ }
31
+ return t0;
32
+ }
33
+
34
+ export const FIXTURE_ENTRYPOINT = {
35
+ fn: useFoo,
36
+ params: [42],
37
+ };
38
+
39
+ ```
40
+
41
+ ### Eval output
42
+ (kind: ok) [42]
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-declaration-basic.flow.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ // @flow @compilationMode:"infer"
2
+ export default hook useFoo(bar: number) {
3
+ return [bar];
4
+ }
5
+
6
+ export const FIXTURE_ENTRYPOINT = {
7
+ fn: useFoo,
8
+ params: [42],
9
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-inside-logical-expression.expect.md ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function Component(props) {
6
+ const user =
7
+ useFragment(
8
+ graphql`
9
+ fragment F on T {
10
+ id
11
+ }
12
+ `,
13
+ props.user
14
+ ) ?? {};
15
+ return user.name;
16
+ }
17
+
18
+ ```
19
+
20
+ ## Code
21
+
22
+ ```javascript
23
+ function Component(props) {
24
+ const user =
25
+ useFragment(
26
+ graphql`
27
+ fragment F on T {
28
+ id
29
+ }
30
+ `,
31
+ props.user,
32
+ ) ?? {};
33
+ return user.name;
34
+ }
35
+
36
+ ```
37
+
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-inside-logical-expression.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function Component(props) {
2
+ const user =
3
+ useFragment(
4
+ graphql`
5
+ fragment F on T {
6
+ id
7
+ }
8
+ `,
9
+ props.user
10
+ ) ?? {};
11
+ return user.name;
12
+ }
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-noAlias.expect.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ import {useNoAlias} from 'shared-runtime';
6
+
7
+ function Component(props) {
8
+ const item = {a: props.a};
9
+ const x = useNoAlias(item, () => {
10
+ console.log(props);
11
+ }, [props.a]);
12
+ return [x, item];
13
+ }
14
+
15
+ export const FIXTURE_ENTRYPOINT = {
16
+ fn: Component,
17
+ params: [{a: {id: 42}}],
18
+ isComponent: true,
19
+ };
20
+
21
+ ```
22
+
23
+ ## Code
24
+
25
+ ```javascript
26
+ import { c as _c } from "react/compiler-runtime";
27
+ import { useNoAlias } from "shared-runtime";
28
+
29
+ function Component(props) {
30
+ const $ = _c(5);
31
+ let t0;
32
+ if ($[0] !== props.a) {
33
+ t0 = { a: props.a };
34
+ $[0] = props.a;
35
+ $[1] = t0;
36
+ } else {
37
+ t0 = $[1];
38
+ }
39
+ const item = t0;
40
+ const x = useNoAlias(item, () => {
41
+ console.log(props);
42
+ }, [props.a]);
43
+ let t1;
44
+ if ($[2] !== item || $[3] !== x) {
45
+ t1 = [x, item];
46
+ $[2] = item;
47
+ $[3] = x;
48
+ $[4] = t1;
49
+ } else {
50
+ t1 = $[4];
51
+ }
52
+ return t1;
53
+ }
54
+
55
+ export const FIXTURE_ENTRYPOINT = {
56
+ fn: Component,
57
+ params: [{ a: { id: 42 } }],
58
+ isComponent: true,
59
+ };
60
+
61
+ ```
62
+
63
+ ### Eval output
64
+ (kind: ok) [{},{"a":{"id":42}}]
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-noAlias.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {useNoAlias} from 'shared-runtime';
2
+
3
+ function Component(props) {
4
+ const item = {a: props.a};
5
+ const x = useNoAlias(item, () => {
6
+ console.log(props);
7
+ }, [props.a]);
8
+ return [x, item];
9
+ }
10
+
11
+ export const FIXTURE_ENTRYPOINT = {
12
+ fn: Component,
13
+ params: [{a: {id: 42}}],
14
+ isComponent: true,
15
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-property-load-local.expect.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function useFoo() {}
6
+
7
+ function Foo() {
8
+ let name = useFoo.name;
9
+ console.log(name);
10
+ return name;
11
+ }
12
+
13
+ export const FIXTURE_ENTRYPOINT = {
14
+ fn: Foo,
15
+ params: [],
16
+ };
17
+
18
+ ```
19
+
20
+ ## Code
21
+
22
+ ```javascript
23
+ function useFoo() {}
24
+
25
+ function Foo() {
26
+ const name = useFoo.name;
27
+ console.log(name);
28
+ return name;
29
+ }
30
+
31
+ export const FIXTURE_ENTRYPOINT = {
32
+ fn: Foo,
33
+ params: [],
34
+ };
35
+
36
+ ```
37
+
38
+ ### Eval output
39
+ (kind: ok) "useFoo"
40
+ logs: ['useFoo']
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-property-load-local.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function useFoo() {}
2
+
3
+ function Foo() {
4
+ let name = useFoo.name;
5
+ console.log(name);
6
+ return name;
7
+ }
8
+
9
+ export const FIXTURE_ENTRYPOINT = {
10
+ fn: Foo,
11
+ params: [],
12
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-ref-callback.expect.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ import {useEffect, useRef} from 'react';
6
+
7
+ function Component(props) {
8
+ const ref = useRef();
9
+ useFoo(() => {
10
+ ref.current = 42;
11
+ });
12
+ }
13
+
14
+ function useFoo(x) {}
15
+
16
+ export const FIXTURE_ENTRYPOINT = {
17
+ fn: Component,
18
+ params: [],
19
+ };
20
+
21
+ ```
22
+
23
+ ## Code
24
+
25
+ ```javascript
26
+ import { c as _c } from "react/compiler-runtime";
27
+ import { useEffect, useRef } from "react";
28
+
29
+ function Component(props) {
30
+ const $ = _c(1);
31
+ const ref = useRef();
32
+ let t0;
33
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
34
+ t0 = () => {
35
+ ref.current = 42;
36
+ };
37
+ $[0] = t0;
38
+ } else {
39
+ t0 = $[0];
40
+ }
41
+ useFoo(t0);
42
+ }
43
+
44
+ function useFoo(x) {}
45
+
46
+ export const FIXTURE_ENTRYPOINT = {
47
+ fn: Component,
48
+ params: [],
49
+ };
50
+
51
+ ```
52
+
53
+ ### Eval output
54
+ (kind: ok)
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-ref-callback.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {useEffect, useRef} from 'react';
2
+
3
+ function Component(props) {
4
+ const ref = useRef();
5
+ useFoo(() => {
6
+ ref.current = 42;
7
+ });
8
+ }
9
+
10
+ function useFoo(x) {}
11
+
12
+ export const FIXTURE_ENTRYPOINT = {
13
+ fn: Component,
14
+ params: [],
15
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-freeze-arguments.expect.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function Component() {
6
+ const a = [];
7
+ useFreeze(a); // should freeze
8
+ useFreeze(a); // should be readonly
9
+ call(a); // should be readonly
10
+ return a;
11
+ }
12
+
13
+ function useFreeze(x) {}
14
+ function call(x) {}
15
+
16
+ ```
17
+
18
+ ## Code
19
+
20
+ ```javascript
21
+ import { c as _c } from "react/compiler-runtime";
22
+ function Component() {
23
+ const $ = _c(1);
24
+ let t0;
25
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
26
+ t0 = [];
27
+ $[0] = t0;
28
+ } else {
29
+ t0 = $[0];
30
+ }
31
+ const a = t0;
32
+ useFreeze(a);
33
+ useFreeze(a);
34
+ call(a);
35
+ return a;
36
+ }
37
+
38
+ function useFreeze(x) {}
39
+ function call(x) {}
40
+
41
+ ```
42
+
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-freeze-arguments.js ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ function Component() {
2
+ const a = [];
3
+ useFreeze(a); // should freeze
4
+ useFreeze(a); // should be readonly
5
+ call(a); // should be readonly
6
+ return a;
7
+ }
8
+
9
+ function useFreeze(x) {}
10
+ function call(x) {}
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-freeze-possibly-mutable-arguments.expect.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function Component(props) {
6
+ const cond = props.cond;
7
+ const x = props.x;
8
+ let a;
9
+ if (cond) {
10
+ a = x;
11
+ } else {
12
+ a = [];
13
+ }
14
+ useFreeze(a); // should freeze, value *may* be mutable
15
+ useFreeze(a); // should be readonly
16
+ call(a); // should be readonly
17
+ return a;
18
+ }
19
+
20
+ function useFreeze(x) {}
21
+ function call(x) {}
22
+
23
+ ```
24
+
25
+ ## Code
26
+
27
+ ```javascript
28
+ import { c as _c } from "react/compiler-runtime";
29
+ function Component(props) {
30
+ const $ = _c(1);
31
+ const cond = props.cond;
32
+ const x = props.x;
33
+ let a;
34
+ if (cond) {
35
+ a = x;
36
+ } else {
37
+ let t0;
38
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
39
+ t0 = [];
40
+ $[0] = t0;
41
+ } else {
42
+ t0 = $[0];
43
+ }
44
+ a = t0;
45
+ }
46
+
47
+ useFreeze(a);
48
+ useFreeze(a);
49
+ call(a);
50
+ return a;
51
+ }
52
+
53
+ function useFreeze(x) {}
54
+ function call(x) {}
55
+
56
+ ```
57
+
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-freeze-possibly-mutable-arguments.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function Component(props) {
2
+ const cond = props.cond;
3
+ const x = props.x;
4
+ let a;
5
+ if (cond) {
6
+ a = x;
7
+ } else {
8
+ a = [];
9
+ }
10
+ useFreeze(a); // should freeze, value *may* be mutable
11
+ useFreeze(a); // should be readonly
12
+ call(a); // should be readonly
13
+ return a;
14
+ }
15
+
16
+ function useFreeze(x) {}
17
+ function call(x) {}
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-with-React-namespace.expect.md ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function Component() {
6
+ const [x, setX] = React.useState(1);
7
+ return x;
8
+ }
9
+
10
+ export const FIXTURE_ENTRYPOINT = {
11
+ fn: Component,
12
+ params: [],
13
+ };
14
+
15
+ ```
16
+
17
+ ## Code
18
+
19
+ ```javascript
20
+ function Component() {
21
+ const [x] = React.useState(1);
22
+ return x;
23
+ }
24
+
25
+ export const FIXTURE_ENTRYPOINT = {
26
+ fn: Component,
27
+ params: [],
28
+ };
29
+
30
+ ```
31
+
32
+ ### Eval output
33
+ (kind: ok) 1
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-with-React-namespace.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ function Component() {
2
+ const [x, setX] = React.useState(1);
3
+ return x;
4
+ }
5
+
6
+ export const FIXTURE_ENTRYPOINT = {
7
+ fn: Component,
8
+ params: [],
9
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-method-no-outlining-wildcard.expect.md ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ // @customMacros:"idx.*.b"
6
+
7
+ function Component(props) {
8
+ // outlined
9
+ const groupName1 = idx(props, _ => _.group.label);
10
+ // outlined
11
+ const groupName2 = idx.a(props, _ => _.group.label);
12
+ // not outlined
13
+ const groupName3 = idx.a.b(props, _ => _.group.label);
14
+ // not outlined
15
+ const groupName4 = idx.hello_world.b(props, _ => _.group.label);
16
+ // outlined
17
+ const groupName5 = idx.hello_world.b.c(props, _ => _.group.label);
18
+ return (
19
+ <div>
20
+ {groupName1}
21
+ {groupName2}
22
+ {groupName3}
23
+ {groupName4}
24
+ {groupName5}
25
+ </div>
26
+ );
27
+ }
28
+
29
+ ```
30
+
31
+ ## Code
32
+
33
+ ```javascript
34
+ import { c as _c } from "react/compiler-runtime"; // @customMacros:"idx.*.b"
35
+
36
+ function Component(props) {
37
+ const $ = _c(16);
38
+ let t0;
39
+ if ($[0] !== props) {
40
+ t0 = idx(props, (_) => _.group.label);
41
+ $[0] = props;
42
+ $[1] = t0;
43
+ } else {
44
+ t0 = $[1];
45
+ }
46
+ const groupName1 = t0;
47
+ let t1;
48
+ if ($[2] !== props) {
49
+ t1 = idx.a(props, (__0) => __0.group.label);
50
+ $[2] = props;
51
+ $[3] = t1;
52
+ } else {
53
+ t1 = $[3];
54
+ }
55
+ const groupName2 = t1;
56
+ let t2;
57
+ if ($[4] !== props) {
58
+ t2 = idx.a.b(props, (__1) => __1.group.label);
59
+ $[4] = props;
60
+ $[5] = t2;
61
+ } else {
62
+ t2 = $[5];
63
+ }
64
+ const groupName3 = t2;
65
+ let t3;
66
+ if ($[6] !== props) {
67
+ t3 = idx.hello_world.b(props, (__2) => __2.group.label);
68
+ $[6] = props;
69
+ $[7] = t3;
70
+ } else {
71
+ t3 = $[7];
72
+ }
73
+ const groupName4 = t3;
74
+ let t4;
75
+ if ($[8] !== props) {
76
+ t4 = idx.hello_world.b.c(props, (__3) => __3.group.label);
77
+ $[8] = props;
78
+ $[9] = t4;
79
+ } else {
80
+ t4 = $[9];
81
+ }
82
+ const groupName5 = t4;
83
+ let t5;
84
+ if (
85
+ $[10] !== groupName1 ||
86
+ $[11] !== groupName2 ||
87
+ $[12] !== groupName3 ||
88
+ $[13] !== groupName4 ||
89
+ $[14] !== groupName5
90
+ ) {
91
+ t5 = (
92
+ <div>
93
+ {groupName1}
94
+ {groupName2}
95
+ {groupName3}
96
+ {groupName4}
97
+ {groupName5}
98
+ </div>
99
+ );
100
+ $[10] = groupName1;
101
+ $[11] = groupName2;
102
+ $[12] = groupName3;
103
+ $[13] = groupName4;
104
+ $[14] = groupName5;
105
+ $[15] = t5;
106
+ } else {
107
+ t5 = $[15];
108
+ }
109
+ return t5;
110
+ }
111
+
112
+ ```
113
+
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-method-no-outlining-wildcard.js ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @customMacros:"idx.*.b"
2
+
3
+ function Component(props) {
4
+ // outlined
5
+ const groupName1 = idx(props, _ => _.group.label);
6
+ // outlined
7
+ const groupName2 = idx.a(props, _ => _.group.label);
8
+ // not outlined
9
+ const groupName3 = idx.a.b(props, _ => _.group.label);
10
+ // not outlined
11
+ const groupName4 = idx.hello_world.b(props, _ => _.group.label);
12
+ // outlined
13
+ const groupName5 = idx.hello_world.b.c(props, _ => _.group.label);
14
+ return (
15
+ <div>
16
+ {groupName1}
17
+ {groupName2}
18
+ {groupName3}
19
+ {groupName4}
20
+ {groupName5}
21
+ </div>
22
+ );
23
+ }
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-method-no-outlining.expect.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ // @customMacros:"idx.a"
6
+
7
+ function Component(props) {
8
+ // outlined
9
+ const groupName1 = idx(props, _ => _.group.label);
10
+ // not outlined
11
+ const groupName2 = idx.a(props, _ => _.group.label);
12
+ // outlined
13
+ const groupName3 = idx.a.b(props, _ => _.group.label);
14
+ return (
15
+ <div>
16
+ {groupName1}
17
+ {groupName2}
18
+ {groupName3}
19
+ </div>
20
+ );
21
+ }
22
+
23
+ ```
24
+
25
+ ## Code
26
+
27
+ ```javascript
28
+ import { c as _c } from "react/compiler-runtime"; // @customMacros:"idx.a"
29
+
30
+ function Component(props) {
31
+ const $ = _c(10);
32
+ let t0;
33
+ if ($[0] !== props) {
34
+ t0 = idx(props, (_) => _.group.label);
35
+ $[0] = props;
36
+ $[1] = t0;
37
+ } else {
38
+ t0 = $[1];
39
+ }
40
+ const groupName1 = t0;
41
+ let t1;
42
+ if ($[2] !== props) {
43
+ t1 = idx.a(props, (__0) => __0.group.label);
44
+ $[2] = props;
45
+ $[3] = t1;
46
+ } else {
47
+ t1 = $[3];
48
+ }
49
+ const groupName2 = t1;
50
+ let t2;
51
+ if ($[4] !== props) {
52
+ t2 = idx.a.b(props, (__1) => __1.group.label);
53
+ $[4] = props;
54
+ $[5] = t2;
55
+ } else {
56
+ t2 = $[5];
57
+ }
58
+ const groupName3 = t2;
59
+ let t3;
60
+ if ($[6] !== groupName1 || $[7] !== groupName2 || $[8] !== groupName3) {
61
+ t3 = (
62
+ <div>
63
+ {groupName1}
64
+ {groupName2}
65
+ {groupName3}
66
+ </div>
67
+ );
68
+ $[6] = groupName1;
69
+ $[7] = groupName2;
70
+ $[8] = groupName3;
71
+ $[9] = t3;
72
+ } else {
73
+ t3 = $[9];
74
+ }
75
+ return t3;
76
+ }
77
+
78
+ ```
79
+
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-method-no-outlining.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @customMacros:"idx.a"
2
+
3
+ function Component(props) {
4
+ // outlined
5
+ const groupName1 = idx(props, _ => _.group.label);
6
+ // not outlined
7
+ const groupName2 = idx.a(props, _ => _.group.label);
8
+ // outlined
9
+ const groupName3 = idx.a.b(props, _ => _.group.label);
10
+ return (
11
+ <div>
12
+ {groupName1}
13
+ {groupName2}
14
+ {groupName3}
15
+ </div>
16
+ );
17
+ }
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-no-outlining.expect.md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ // @customMacros:"idx"
6
+ import idx from 'idx';
7
+
8
+ function Component(props) {
9
+ // the lambda should not be outlined
10
+ const groupName = idx(props, _ => _.group.label);
11
+ return <div>{groupName}</div>;
12
+ }
13
+
14
+ export const FIXTURE_ENTRYPOINT = {
15
+ fn: Component,
16
+ params: [{}],
17
+ };
18
+
19
+ ```
20
+
21
+ ## Code
22
+
23
+ ```javascript
24
+ import { c as _c } from "react/compiler-runtime"; // @customMacros:"idx"
25
+
26
+ function Component(props) {
27
+ const $ = _c(4);
28
+ let t0;
29
+ if ($[0] !== props) {
30
+ var _ref;
31
+ t0 =
32
+ (_ref = props) != null
33
+ ? (_ref = _ref.group) != null
34
+ ? _ref.label
35
+ : _ref
36
+ : _ref;
37
+ $[0] = props;
38
+ $[1] = t0;
39
+ } else {
40
+ t0 = $[1];
41
+ }
42
+ const groupName = t0;
43
+ let t1;
44
+ if ($[2] !== groupName) {
45
+ t1 = <div>{groupName}</div>;
46
+ $[2] = groupName;
47
+ $[3] = t1;
48
+ } else {
49
+ t1 = $[3];
50
+ }
51
+ return t1;
52
+ }
53
+
54
+ export const FIXTURE_ENTRYPOINT = {
55
+ fn: Component,
56
+ params: [{}],
57
+ };
58
+
59
+ ```
60
+
61
+ ### Eval output
62
+ (kind: ok) <div></div>
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/idx-no-outlining.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @customMacros:"idx"
2
+ import idx from 'idx';
3
+
4
+ function Component(props) {
5
+ // the lambda should not be outlined
6
+ const groupName = idx(props, _ => _.group.label);
7
+ return <div>{groupName}</div>;
8
+ }
9
+
10
+ export const FIXTURE_ENTRYPOINT = {
11
+ fn: Component,
12
+ params: [{}],
13
+ };
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ignore-inner-interface-types.expect.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## Input
3
+
4
+ ```javascript
5
+ function Foo() {
6
+ type X = number;
7
+ interface Bar {
8
+ baz: number;
9
+ }
10
+ return 0;
11
+ }
12
+
13
+ export const FIXTURE_ENTRYPOINT = {
14
+ fn: Foo,
15
+ params: [],
16
+ };
17
+
18
+ ```
19
+
20
+ ## Code
21
+
22
+ ```javascript
23
+ function Foo() {
24
+ return 0;
25
+ }
26
+
27
+ export const FIXTURE_ENTRYPOINT = {
28
+ fn: Foo,
29
+ params: [],
30
+ };
31
+
32
+ ```
33
+
34
+ ### Eval output
35
+ (kind: ok) 0