[compiler][repro] Test fixture for fbt plural bug
ghstack-source-id: 222e7312c081faf36702a1c790a4e336b5bcc928 Pull Request resolved: https://github.com/facebook/react/pull/30432
Mofei Zhang committed
Jul 26, 2024 at 17:36 UTC
a15e8d7cdc6289c8685588d2821cb7c904141e3e
3 files changed
+153
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/bug-multiple-fbt-plural.expect.md
new
+110
@@ -0,0 +1,110 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import fbt from 'fbt';
6
+
7
+/**
8
+ * Forget + fbt inconsistency. Evaluator errors with the following
9
+ * Found differences in evaluator results
10
+ * Non-forget (expected):
11
+ * (kind: ok) 1 rewrite to Rust · 2 months traveling
12
+ * Forget:
13
+ * (kind: ok) 1 rewrites to Rust · 2 months traveling
14
+ *
15
+ * The root issue here is that fbt:plural reads `.start` and `.end` from
16
+ * babel nodes to slice into source strings. (fbt:enum suffers from the same
17
+ * problem).
18
+ * See:
19
+ * - [getRawSource](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/FbtUtil.js#L666-L673)
20
+ * - [getArgCode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtArguments.js#L88-L97)
21
+ * - [_getStringVariationCombinations](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/JSFbtBuilder.js#L297)
22
+ *
23
+ * Specifically, the `count` node requires that a `.start/.end` be attached
24
+ * (see [code in FbtPluralNode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtPluralNode.js#L87-L90))
25
+ *
26
+ * In this fixture, `count` nodes are the `rewrites` and `months` identifiers.
27
+ */
28
+function Foo({rewrites, months}) {
29
+ return (
30
+ <fbt desc="Test fbt description">
31
+ <fbt:plural count={rewrites} name="number of rewrites" showCount="yes">
32
+ rewrite
33
+ </fbt:plural>
34
+ to Rust ·
35
+ <fbt:plural count={months} name="number of months" showCount="yes">
36
+ month
37
+ </fbt:plural>
38
+ traveling
39
+ </fbt>
40
+ );
41
+}
42
+
43
+export const FIXTURE_ENTRYPOINT = {
44
+ fn: Foo,
45
+ params: [{rewrites: 1, months: 2}],
46
+};
47
+
48
+```
49
+
50
+## Code
51
+
52
+```javascript
53
+import { c as _c } from "react/compiler-runtime";
54
+import fbt from "fbt";
55
+
56
+/**
57
+ * Forget + fbt inconsistency. Evaluator errors with the following
58
+ * Found differences in evaluator results
59
+ * Non-forget (expected):
60
+ * (kind: ok) 1 rewrite to Rust · 2 months traveling
61
+ * Forget:
62
+ * (kind: ok) 1 rewrites to Rust · 2 months traveling
63
+ *
64
+ * The root issue here is that fbt:plural reads `.start` and `.end` from
65
+ * babel nodes to slice into source strings. (fbt:enum suffers from the same
66
+ * problem).
67
+ * See:
68
+ * - [getRawSource](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/FbtUtil.js#L666-L673)
69
+ * - [getArgCode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtArguments.js#L88-L97)
70
+ * - [_getStringVariationCombinations](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/JSFbtBuilder.js#L297)
71
+ *
72
+ * Specifically, the `count` node requires that a `.start/.end` be attached
73
+ * (see [code in FbtPluralNode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtPluralNode.js#L87-L90))
74
+ *
75
+ * In this fixture, `count` nodes are the `rewrites` and `months` identifiers.
76
+ */
77
+function Foo(t0) {
78
+ const $ = _c(3);
79
+ const { rewrites, months } = t0;
80
+ let t1;
81
+ if ($[0] !== rewrites || $[1] !== months) {
82
+ t1 = fbt._(
83
+ {
84
+ "*": {
85
+ "*": "{number of rewrites} rewrites to Rust · {number of months} months traveling",
86
+ },
87
+ _1: { _1: "1 rewrite to Rust · 1 month traveling" },
88
+ },
89
+ [
90
+ fbt._plural(rewrites, "number of rewrites"),
91
+ fbt._plural(months, "number of months"),
92
+ ],
93
+ { hk: "49MfZA" },
94
+ );
95
+ $[0] = rewrites;
96
+ $[1] = months;
97
+ $[2] = t1;
98
+ } else {
99
+ t1 = $[2];
100
+ }
101
+ return t1;
102
+}
103
+
104
+export const FIXTURE_ENTRYPOINT = {
105
+ fn: Foo,
106
+ params: [{ rewrites: 1, months: 2 }],
107
+};
108
+
109
+```
110
+
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/bug-multiple-fbt-plural.tsx
new
+42
@@ -0,0 +1,42 @@
1
+import fbt from 'fbt';
2
+
3
+/**
4
+ * Forget + fbt inconsistency. Evaluator errors with the following
5
+ * Found differences in evaluator results
6
+ * Non-forget (expected):
7
+ * (kind: ok) 1 rewrite to Rust · 2 months traveling
8
+ * Forget:
9
+ * (kind: ok) 1 rewrites to Rust · 2 months traveling
10
+ *
11
+ * The root issue here is that fbt:plural reads `.start` and `.end` from
12
+ * babel nodes to slice into source strings. (fbt:enum suffers from the same
13
+ * problem).
14
+ * See:
15
+ * - [getRawSource](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/FbtUtil.js#L666-L673)
16
+ * - [getArgCode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtArguments.js#L88-L97)
17
+ * - [_getStringVariationCombinations](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/JSFbtBuilder.js#L297)
18
+ *
19
+ * Specifically, the `count` node requires that a `.start/.end` be attached
20
+ * (see [code in FbtPluralNode](https://github.com/facebook/fbt/blob/main/packages/babel-plugin-fbt/src/fbt-nodes/FbtPluralNode.js#L87-L90))
21
+ *
22
+ * In this fixture, `count` nodes are the `rewrites` and `months` identifiers.
23
+ */
24
+function Foo({rewrites, months}) {
25
+ return (
26
+ <fbt desc="Test fbt description">
27
+ <fbt:plural count={rewrites} name="number of rewrites" showCount="yes">
28
+ rewrite
29
+ </fbt:plural>
30
+ to Rust ·
31
+ <fbt:plural count={months} name="number of months" showCount="yes">
32
+ month
33
+ </fbt:plural>
34
+ traveling
35
+ </fbt>
36
+ );
37
+}
38
+
39
+export const FIXTURE_ENTRYPOINT = {
40
+ fn: Foo,
41
+ params: [{rewrites: 1, months: 2}],
42
+};
compiler/packages/snap/src/SproutTodoFilter.ts
+1
@@ -485,6 +485,7 @@ const skipFilter = new Set([
485
'rules-of-hooks/rules-of-hooks-69521d94fa03',
486
487
// bugs
488
+ 'fbt/bug-multiple-fbt-plural',
489
'fbt/bug-fbt-preserve-whitespace-param',
490
'bug-invalid-hoisting-functionexpr',
491
'original-reactive-scopes-fork/bug-nonmutating-capture-in-unsplittable-memo-block',