Skip to content

Commit 0b23547

Browse files
committed
[compiler] Fix broken tests
ghstack-source-id: 000a37a Pull Request resolved: #31078
1 parent 67fee58 commit 0b23547

10 files changed

+56
-32
lines changed

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/meta-isms/repro-cx-namespace-assigned-to-temporary.expect.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ function Component() {
1919
);
2020
}
2121

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+
}
2729
}
28-
}
29-
return classes.join(' ');
30-
}
30+
return classes.join(' ');
31+
},
32+
};
3133

3234
function useTheme() {
3335
return {
@@ -71,15 +73,17 @@ function Component() {
7173
return t1;
7274
}
7375

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+
}
7983
}
80-
}
81-
return classes.join(" ");
82-
}
84+
return classes.join(" ");
85+
},
86+
};
8387

8488
function useTheme() {
8589
return {
@@ -97,4 +101,4 @@ export const FIXTURE_ENTRYPOINT = {
97101
```
98102
99103
### Eval output
100-
(kind: exception) cx.foo is not a function
104+
(kind: ok) <div class="styles/light styles/dark"></div>

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/meta-isms/repro-cx-namespace-assigned-to-temporary.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ function Component() {
1515
);
1616
}
1717

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+
}
2325
}
24-
}
25-
return classes.join(' ');
26-
}
26+
return classes.join(' ');
27+
},
28+
};
2729

2830
function useTheme() {
2931
return {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutate-outer-scope-within-value-block.expect.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
```javascript
55
import {CONST_TRUE, identity, shallowCopy} from 'shared-runtime';
66

7+
function mutate(_: unknown) {}
8+
79
/**
810
* There are three values with their own scopes in this fixture.
911
* - arr, whose mutable range extends to the `mutate(...)` call
@@ -45,6 +47,8 @@ export const FIXTURE_ENTRYPOINT = {
4547
import { c as _c } from "react/compiler-runtime";
4648
import { CONST_TRUE, identity, shallowCopy } from "shared-runtime";
4749

50+
function mutate(_) {}
51+
4852
/**
4953
* There are three values with their own scopes in this fixture.
5054
* - arr, whose mutable range extends to the `mutate(...)` call
@@ -91,4 +95,4 @@ export const FIXTURE_ENTRYPOINT = {
9195
```
9296
9397
### Eval output
94-
(kind: exception) mutate is not defined
98+
(kind: ok)

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutate-outer-scope-within-value-block.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {CONST_TRUE, identity, shallowCopy} from 'shared-runtime';
22

3+
function mutate(_: unknown) {}
4+
35
/**
46
* There are three values with their own scopes in this fixture.
57
* - 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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import {useCallback} from 'react';
77
import {identity, useIdentity} from 'shared-runtime';
88

9+
function mutate(_: unknown) {}
10+
911
/**
1012
* Repro showing a manual memo whose declaration (useCallback's 1st argument)
1113
* 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
3335
import { useCallback } from "react";
3436
import { identity, useIdentity } from "shared-runtime";
3537

38+
function mutate(_) {}
39+
3640
/**
3741
* Repro showing a manual memo whose declaration (useCallback's 1st argument)
3842
* is memoized, but not its dependency (x). In this case, `x`'s scope is pruned
@@ -62,4 +66,4 @@ export const FIXTURE_ENTRYPOINT = {
6266
```
6367
6468
### Eval output
65-
(kind: exception) mutate is not defined
69+
(kind: ok) "[[ function params=0 ]]"

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useCallback-dep-scope-pruned.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import {useCallback} from 'react';
33
import {identity, useIdentity} from 'shared-runtime';
44

5+
function mutate(_: unknown) {}
6+
57
/**
68
* Repro showing a manual memo whose declaration (useCallback's 1st argument)
79
* 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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
```javascript
55
import {identity, makeObject_Primitives} from 'shared-runtime';
66

7+
function useHook() {}
8+
79
function useTest({cond}) {
810
const val = makeObject_Primitives();
911

@@ -31,6 +33,8 @@ export const FIXTURE_ENTRYPOINT = {
3133
import { c as _c } from "react/compiler-runtime";
3234
import { identity, makeObject_Primitives } from "shared-runtime";
3335

36+
function useHook() {}
37+
3438
function useTest(t0) {
3539
const $ = _c(3);
3640
const { cond } = t0;
@@ -64,4 +68,4 @@ export const FIXTURE_ENTRYPOINT = {
6468
```
6569
6670
### Eval output
67-
(kind: exception) useHook is not defined
71+
(kind: ok) {"a":0,"b":"value1","c":true}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-allocating-ternary-test-instruction-scope.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {identity, makeObject_Primitives} from 'shared-runtime';
22

3+
function useHook() {}
4+
35
function useTest({cond}) {
46
const val = makeObject_Primitives();
57

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/allow-locals-named-like-hooks.expect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Input
33

44
```javascript
5-
import {makeObject_Primitives} from 'shared-runtime';
5+
import {makeObject_Primitives, Stringify} from 'shared-runtime';
66

77
function Component(props) {
88
let useFeature = makeObject_Primitives();
@@ -32,7 +32,7 @@ export const FIXTURE_ENTRYPOINT = {
3232

3333
```javascript
3434
import { c as _c } from "react/compiler-runtime";
35-
import { makeObject_Primitives } from "shared-runtime";
35+
import { makeObject_Primitives, Stringify } from "shared-runtime";
3636

3737
function Component(props) {
3838
const $ = _c(2);
@@ -75,4 +75,4 @@ export const FIXTURE_ENTRYPOINT = {
7575
```
7676
7777
### Eval output
78-
(kind: exception) Stringify is not defined
78+
(kind: ok) <div>{"val":{"a":0,"b":"value1","c":true},"children":[2,"[[ cyclic ref *1 ]]",null]}</div>

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/rules-of-hooks/allow-locals-named-like-hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {makeObject_Primitives} from 'shared-runtime';
1+
import {makeObject_Primitives, Stringify} from 'shared-runtime';
22

33
function Component(props) {
44
let useFeature = makeObject_Primitives();

0 commit comments

Comments
 (0)