[compiler] Fix broken tests
ghstack-source-id: 000a37ae1f819eef676dcd52410d5231cd2d50fe Pull Request resolved: https://github.com/facebook/react/pull/31078
Lauren Tan committed
Sep 26, 2024 at 17:34 UTC
3edc000d7717027a1ce23611070a56358040a554
10 files changed
+56
-32
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/meta-isms/repro-cx-namespace-assigned-to-temporary.expect.md
+21
-17
@@ -19,15 +19,17 @@ function Component() {
19
);
20
}
21
22
-function cx(obj) {
23
- const classes = [];
24
- for (const [key, value] of Object.entries(obj)) {
25
- if (value) {
26
- classes.push(key);
22
+const cx = {
23
+ foo(obj) {
24
+ const classes = [];
25
+ for (const [key, value] of Object.entries(obj)) {
26
+ if (value) {
27
+ classes.push(key);
28
+ }
29
}
28
- }
29
- return classes.join(' ');
30
-}
30
+ return classes.join(' ');
31
+ },
32
+};
33
34
function useTheme() {
35
return {
@@ -71,15 +73,17 @@ function Component() {
73
return t1;
74
}
75
74
-function cx(obj) {
75
- const classes = [];
76
- for (const [key, value] of Object.entries(obj)) {
77
- if (value) {
78
- classes.push(key);
76
+const cx = {
77
+ foo(obj) {
78
+ const classes = [];
79
+ for (const [key, value] of Object.entries(obj)) {
80
+ if (value) {
81
+ classes.push(key);
82
+ }
83
}
80
- }
81
- return classes.join(" ");
82
-}
84
+ return classes.join(" ");
85
+ },
86
+};
87
88
function useTheme() {
89
return {
@@ -97,4 +101,4 @@ export const FIXTURE_ENTRYPOINT = {
101
```
102
103
### Eval output
100
-(kind: exception) cx.foo is not a function
\ No newline at end of file
104
+(kind: ok) <div class="styles/light styles/dark"></div>
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/meta-isms/repro-cx-namespace-assigned-to-temporary.js
+10
-8
@@ -15,15 +15,17 @@ function Component() {
15
);
16
}
17
18
-function cx(obj) {
19
- const classes = [];
20
- for (const [key, value] of Object.entries(obj)) {
21
- if (value) {
22
- classes.push(key);
18
+const cx = {
19
+ foo(obj) {
20
+ const classes = [];
21
+ for (const [key, value] of Object.entries(obj)) {
22
+ if (value) {
23
+ classes.push(key);
24
+ }
25
}
24
- }
25
- return classes.join(' ');
26
-}
26
+ return classes.join(' ');
27
+ },
28
+};
29
30
function useTheme() {
31
return {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutate-outer-scope-within-value-block.expect.md
+5
-1
@@ -4,6 +4,8 @@
4
```javascript
5
import {CONST_TRUE, identity, shallowCopy} from 'shared-runtime';
6
7
+function mutate(_: unknown) {}
8
+
9
/**
10
* There are three values with their own scopes in this fixture.
11
* - arr, whose mutable range extends to the `mutate(...)` call
@@ -45,6 +47,8 @@ export const FIXTURE_ENTRYPOINT = {
47
import { c as _c } from "react/compiler-runtime";
48
import { CONST_TRUE, identity, shallowCopy } from "shared-runtime";
49
50
+function mutate(_) {}
51
+
52
/**
53
* There are three values with their own scopes in this fixture.
54
* - arr, whose mutable range extends to the `mutate(...)` call
@@ -91,4 +95,4 @@ export const FIXTURE_ENTRYPOINT = {
95
```
96
97
### Eval output
94
-(kind: exception) mutate is not defined
\ No newline at end of file
98
+(kind: ok)
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutate-outer-scope-within-value-block.ts
+2
@@ -1,5 +1,7 @@
1
import {CONST_TRUE, identity, shallowCopy} from 'shared-runtime';
2
3
+function mutate(_: unknown) {}
4
+
5
/**
6
* There are three values with their own scopes in this fixture.
7
* - arr, whose mutable range extends to the `mutate(...)` call
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-dep-scope-pruned.expect.md
+5
-1
@@ -6,6 +6,8 @@
6
import {useCallback} from 'react';
7
import {identity, useIdentity} from 'shared-runtime';
8
9
+function mutate(_: unknown) {}
10
+
11
/**
12
* Repro showing a manual memo whose declaration (useCallback's 1st argument)
13
* is memoized, but not its dependency (x). In this case, `x`'s scope is pruned
@@ -33,6 +35,8 @@ import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMe
35
import { useCallback } from "react";
36
import { identity, useIdentity } from "shared-runtime";
37
38
+function mutate(_) {}
39
+
40
/**
41
* Repro showing a manual memo whose declaration (useCallback's 1st argument)
42
* is memoized, but not its dependency (x). In this case, `x`'s scope is pruned
@@ -62,4 +66,4 @@ export const FIXTURE_ENTRYPOINT = {
66
```
67
68
### Eval output
65
-(kind: exception) mutate is not defined
\ No newline at end of file
69
+(kind: ok) "[[ function params=0 ]]"
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-dep-scope-pruned.ts
+2
@@ -2,6 +2,8 @@
2
import {useCallback} from 'react';
3
import {identity, useIdentity} from 'shared-runtime';
4
5
+function mutate(_: unknown) {}
6
+
7
/**
8
* Repro showing a manual memo whose declaration (useCallback's 1st argument)
9
* is memoized, but not its dependency (x). In this case, `x`'s scope is pruned
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-allocating-ternary-test-instruction-scope.expect.md
+5
-1
@@ -4,6 +4,8 @@
4
```javascript
5
import {identity, makeObject_Primitives} from 'shared-runtime';
6
7
+function useHook() {}
8
+
9
function useTest({cond}) {
10
const val = makeObject_Primitives();
11
@@ -31,6 +33,8 @@ export const FIXTURE_ENTRYPOINT = {
33
import { c as _c } from "react/compiler-runtime";
34
import { identity, makeObject_Primitives } from "shared-runtime";
35
36
+function useHook() {}
37
+
38
function useTest(t0) {
39
const $ = _c(3);
40
const { cond } = t0;
@@ -64,4 +68,4 @@ export const FIXTURE_ENTRYPOINT = {
68
```
69
70
### Eval output
67
-(kind: exception) useHook is not defined
\ No newline at end of file
71
+(kind: ok) {"a":0,"b":"value1","c":true}
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-allocating-ternary-test-instruction-scope.ts
+2
@@ -1,5 +1,7 @@
1
import {identity, makeObject_Primitives} from 'shared-runtime';
2
3
+function useHook() {}
4
+
5
function useTest({cond}) {
6
const val = makeObject_Primitives();
7
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/allow-locals-named-like-hooks.expect.md
+3
-3
@@ -2,7 +2,7 @@
2
## Input
3
4
```javascript
5
-import {makeObject_Primitives} from 'shared-runtime';
5
+import {makeObject_Primitives, Stringify} from 'shared-runtime';
6
7
function Component(props) {
8
let useFeature = makeObject_Primitives();
@@ -32,7 +32,7 @@ export const FIXTURE_ENTRYPOINT = {
32
33
```javascript
34
import { c as _c } from "react/compiler-runtime";
35
-import { makeObject_Primitives } from "shared-runtime";
35
+import { makeObject_Primitives, Stringify } from "shared-runtime";
36
37
function Component(props) {
38
const $ = _c(2);
@@ -75,4 +75,4 @@ export const FIXTURE_ENTRYPOINT = {
75
```
76
77
### Eval output
78
-(kind: exception) Stringify is not defined
\ No newline at end of file
78
+(kind: ok) <div>{"val":{"a":0,"b":"value1","c":true},"children":[2,"[[ cyclic ref *1 ]]",null]}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/allow-locals-named-like-hooks.js
+1
-1
@@ -1,4 +1,4 @@
1
-import {makeObject_Primitives} from 'shared-runtime';
1
+import {makeObject_Primitives, Stringify} from 'shared-runtime';
2
3
function Component(props) {
4
let useFeature = makeObject_Primitives();