[compiler][repro] fixtures for fbt plural and macro bugs
ghstack-source-id: 8ccf49bb40cd634932b84dd637439042aa60fd46 Pull Request resolved: https://github.com/facebook/react/pull/30535
Mofei Zhang committed
Jul 30, 2024 at 16:24 UTC
212d5ae8cbdb16788bcbb8c7f0c35369968eff5e
7 files changed
+350
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/bug-fbt-plural-multiple-function-calls.expect.md
new
+87
@@ -0,0 +1,87 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import fbt from 'fbt';
6
+
7
+/**
8
+ * Similar to error.todo-multiple-fbt-plural
9
+ *
10
+ * Evaluator error:
11
+ * Found differences in evaluator results
12
+ * Non-forget (expected):
13
+ * (kind: ok) <div>1 apple and 2 bananas</div>
14
+ * Forget:
15
+ * (kind: ok) <div>1 apples and 2 bananas</div>
16
+ */
17
+
18
+function useFoo({apples, bananas}) {
19
+ return fbt(
20
+ `${fbt.param('number of apples', apples)} ` +
21
+ fbt.plural('apple', apples) +
22
+ ` and ${fbt.param('number of bananas', bananas)} ` +
23
+ fbt.plural('banana', bananas),
24
+ 'TestDescription',
25
+ );
26
+}
27
+
28
+export const FIXTURE_ENTRYPOINT = {
29
+ fn: useFoo,
30
+ params: [{apples: 1, bananas: 2}],
31
+};
32
+
33
+```
34
+
35
+## Code
36
+
37
+```javascript
38
+import { c as _c } from "react/compiler-runtime";
39
+import fbt from "fbt";
40
+
41
+/**
42
+ * Similar to error.todo-multiple-fbt-plural
43
+ *
44
+ * Evaluator error:
45
+ * Found differences in evaluator results
46
+ * Non-forget (expected):
47
+ * (kind: ok) <div>1 apple and 2 bananas</div>
48
+ * Forget:
49
+ * (kind: ok) <div>1 apples and 2 bananas</div>
50
+ */
51
+
52
+function useFoo(t0) {
53
+ const $ = _c(3);
54
+ const { apples, bananas } = t0;
55
+ let t1;
56
+ if ($[0] !== apples || $[1] !== bananas) {
57
+ t1 = fbt._(
58
+ {
59
+ "*": {
60
+ "*": "{number of apples} apples and {number of bananas} bananas",
61
+ },
62
+ _1: { _1: "{number of apples} apple and {number of bananas} banana" },
63
+ },
64
+ [
65
+ fbt._plural(apples),
66
+ fbt._plural(bananas),
67
+ fbt._param("number of apples", apples),
68
+ fbt._param("number of bananas", bananas),
69
+ ],
70
+ { hk: "3vKunl" },
71
+ );
72
+ $[0] = apples;
73
+ $[1] = bananas;
74
+ $[2] = t1;
75
+ } else {
76
+ t1 = $[2];
77
+ }
78
+ return t1;
79
+}
80
+
81
+export const FIXTURE_ENTRYPOINT = {
82
+ fn: useFoo,
83
+ params: [{ apples: 1, bananas: 2 }],
84
+};
85
+
86
+```
87
+
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/bug-fbt-plural-multiple-function-calls.ts
new
+27
@@ -0,0 +1,27 @@
1
+import fbt from 'fbt';
2
+
3
+/**
4
+ * Similar to error.todo-multiple-fbt-plural
5
+ *
6
+ * Evaluator error:
7
+ * Found differences in evaluator results
8
+ * Non-forget (expected):
9
+ * (kind: ok) <div>1 apple and 2 bananas</div>
10
+ * Forget:
11
+ * (kind: ok) <div>1 apples and 2 bananas</div>
12
+ */
13
+
14
+function useFoo({apples, bananas}) {
15
+ return fbt(
16
+ `${fbt.param('number of apples', apples)} ` +
17
+ fbt.plural('apple', apples) +
18
+ ` and ${fbt.param('number of bananas', bananas)} ` +
19
+ fbt.plural('banana', bananas),
20
+ 'TestDescription',
21
+ );
22
+}
23
+
24
+export const FIXTURE_ENTRYPOINT = {
25
+ fn: useFoo,
26
+ params: [{apples: 1, bananas: 2}],
27
+};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/bug-fbt-plural-multiple-mixed-call-tag.expect.md
new
+98
@@ -0,0 +1,98 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import fbt from 'fbt';
6
+
7
+/**
8
+ * Similar to error.todo-multiple-fbt-plural, but note that we must
9
+ * count fbt plurals across both <fbt:plural /> namespaced jsx tags
10
+ * and fbt.plural(...) call expressions.
11
+ *
12
+ * Evaluator error:
13
+ * Found differences in evaluator results
14
+ * Non-forget (expected):
15
+ * (kind: ok) <div>1 apple and 2 bananas</div>
16
+ * Forget:
17
+ * (kind: ok) <div>1 apples and 2 bananas</div>
18
+ */
19
+function useFoo({apples, bananas}) {
20
+ return (
21
+ <div>
22
+ <fbt desc="Test Description">
23
+ {fbt.param('number of apples', apples)}
24
+ {' '}
25
+ {fbt.plural('apple', apples)} and
26
+ {' '}
27
+ <fbt:plural name={'number of bananas'} count={bananas} showCount="yes">
28
+ banana
29
+ </fbt:plural>
30
+ </fbt>
31
+ </div>
32
+ );
33
+}
34
+
35
+export const FIXTURE_ENTRYPOINT = {
36
+ fn: useFoo,
37
+ params: [{apples: 1, bananas: 2}],
38
+};
39
+
40
+```
41
+
42
+## Code
43
+
44
+```javascript
45
+import { c as _c } from "react/compiler-runtime";
46
+import fbt from "fbt";
47
+
48
+/**
49
+ * Similar to error.todo-multiple-fbt-plural, but note that we must
50
+ * count fbt plurals across both <fbt:plural /> namespaced jsx tags
51
+ * and fbt.plural(...) call expressions.
52
+ *
53
+ * Evaluator error:
54
+ * Found differences in evaluator results
55
+ * Non-forget (expected):
56
+ * (kind: ok) <div>1 apple and 2 bananas</div>
57
+ * Forget:
58
+ * (kind: ok) <div>1 apples and 2 bananas</div>
59
+ */
60
+function useFoo(t0) {
61
+ const $ = _c(3);
62
+ const { apples, bananas } = t0;
63
+ let t1;
64
+ if ($[0] !== apples || $[1] !== bananas) {
65
+ t1 = (
66
+ <div>
67
+ {fbt._(
68
+ {
69
+ "*": {
70
+ "*": "{number of apples} apples and {number of bananas} bananas",
71
+ },
72
+ _1: { _1: "{number of apples} apple and 1 banana" },
73
+ },
74
+ [
75
+ fbt._plural(apples),
76
+ fbt._plural(bananas, "number of bananas"),
77
+ fbt._param("number of apples", apples),
78
+ ],
79
+ { hk: "2xXrUW" },
80
+ )}
81
+ </div>
82
+ );
83
+ $[0] = apples;
84
+ $[1] = bananas;
85
+ $[2] = t1;
86
+ } else {
87
+ t1 = $[2];
88
+ }
89
+ return t1;
90
+}
91
+
92
+export const FIXTURE_ENTRYPOINT = {
93
+ fn: useFoo,
94
+ params: [{ apples: 1, bananas: 2 }],
95
+};
96
+
97
+```
98
+
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/bug-fbt-plural-multiple-mixed-call-tag.tsx
new
+34
@@ -0,0 +1,34 @@
1
+import fbt from 'fbt';
2
+
3
+/**
4
+ * Similar to error.todo-multiple-fbt-plural, but note that we must
5
+ * count fbt plurals across both <fbt:plural /> namespaced jsx tags
6
+ * and fbt.plural(...) call expressions.
7
+ *
8
+ * Evaluator error:
9
+ * Found differences in evaluator results
10
+ * Non-forget (expected):
11
+ * (kind: ok) <div>1 apple and 2 bananas</div>
12
+ * Forget:
13
+ * (kind: ok) <div>1 apples and 2 bananas</div>
14
+ */
15
+function useFoo({apples, bananas}) {
16
+ return (
17
+ <div>
18
+ <fbt desc="Test Description">
19
+ {fbt.param('number of apples', apples)}
20
+ {' '}
21
+ {fbt.plural('apple', apples)} and
22
+ {' '}
23
+ <fbt:plural name={'number of bananas'} count={bananas} showCount="yes">
24
+ banana
25
+ </fbt:plural>
26
+ </fbt>
27
+ </div>
28
+ );
29
+}
30
+
31
+export const FIXTURE_ENTRYPOINT = {
32
+ fn: useFoo,
33
+ params: [{apples: 1, bananas: 2}],
34
+};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/repro-macro-property-not-handled.expect.md
new
+79
@@ -0,0 +1,79 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import fbt from 'fbt';
6
+import {useIdentity} from 'shared-runtime';
7
+
8
+/**
9
+ * MemoizeFbtAndMacroOperandsInSameScope should also track PropertyLoads (e.g. fbt.plural).
10
+ * This doesn't seem to be an issue for fbt, but affects other internal macros invoked as
11
+ * `importSpecifier.funcName` (see https://fburl.com/code/72icxwmn)
12
+ */
13
+function useFoo({items}: {items: Array<number>}) {
14
+ return fbt(
15
+ 'There ' +
16
+ fbt.plural('is', useIdentity([...items]).length, {many: 'are'}) +
17
+ ' ' +
18
+ fbt.param('number of items', items.length) +
19
+ ' items',
20
+ 'Error content when there are unsupported locales.',
21
+ );
22
+}
23
+
24
+export const FIXTURE_ENTRYPOINT = {
25
+ fn: useFoo,
26
+ params: [{items: [2, 3]}],
27
+};
28
+
29
+```
30
+
31
+## Code
32
+
33
+```javascript
34
+import { c as _c } from "react/compiler-runtime";
35
+import fbt from "fbt";
36
+import { useIdentity } from "shared-runtime";
37
+
38
+/**
39
+ * MemoizeFbtAndMacroOperandsInSameScope should also track PropertyLoads (e.g. fbt.plural).
40
+ * This doesn't seem to be an issue for fbt, but affects other internal macros invoked as
41
+ * `importSpecifier.funcName` (see https://fburl.com/code/72icxwmn)
42
+ */
43
+function useFoo(t0) {
44
+ const $ = _c(2);
45
+ const { items } = t0;
46
+ let t1;
47
+ if ($[0] !== items) {
48
+ t1 = [...items];
49
+ $[0] = items;
50
+ $[1] = t1;
51
+ } else {
52
+ t1 = $[1];
53
+ }
54
+ return fbt._(
55
+ {
56
+ "*": "There are {number of items} items",
57
+ _1: "There is {number of items} items",
58
+ },
59
+ [
60
+ fbt._plural(useIdentity(t1).length),
61
+ fbt._param(
62
+ "number of items",
63
+
64
+ items.length,
65
+ ),
66
+ ],
67
+ { hk: "xsa7w" },
68
+ );
69
+}
70
+
71
+export const FIXTURE_ENTRYPOINT = {
72
+ fn: useFoo,
73
+ params: [{ items: [2, 3] }],
74
+};
75
+
76
+```
77
+
78
+### Eval output
79
+(kind: ok) There are 2 items
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/repro-macro-property-not-handled.tsx
new
+23
@@ -0,0 +1,23 @@
1
+import fbt from 'fbt';
2
+import {useIdentity} from 'shared-runtime';
3
+
4
+/**
5
+ * MemoizeFbtAndMacroOperandsInSameScope should also track PropertyLoads (e.g. fbt.plural).
6
+ * This doesn't seem to be an issue for fbt, but affects other internal macros invoked as
7
+ * `importSpecifier.funcName` (see https://fburl.com/code/72icxwmn)
8
+ */
9
+function useFoo({items}: {items: Array<number>}) {
10
+ return fbt(
11
+ 'There ' +
12
+ fbt.plural('is', useIdentity([...items]).length, {many: 'are'}) +
13
+ ' ' +
14
+ fbt.param('number of items', items.length) +
15
+ ' items',
16
+ 'Error content when there are unsupported locales.',
17
+ );
18
+}
19
+
20
+export const FIXTURE_ENTRYPOINT = {
21
+ fn: useFoo,
22
+ params: [{items: [2, 3]}],
23
+};
compiler/packages/snap/src/SproutTodoFilter.ts
+2
@@ -484,6 +484,8 @@ const skipFilter = new Set([
484
'rules-of-hooks/rules-of-hooks-69521d94fa03',
485
486
// bugs
487
+ 'fbt/bug-fbt-plural-multiple-function-calls',
488
+ 'fbt/bug-fbt-plural-multiple-mixed-call-tag',
489
'bug-invalid-hoisting-functionexpr',
490
'original-reactive-scopes-fork/bug-nonmutating-capture-in-unsplittable-memo-block',
491
'original-reactive-scopes-fork/bug-hoisted-declaration-with-scope',