fbt:param does not allow jsxfragment children
Joe Savona committed
Sep 15, 2023 at 12:10 UTC
bde7875f20b795ef97fec7778946ef245d4a84a9
4 files changed
+72
-5
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+2
-5
@@ -1366,11 +1366,8 @@ function codegenJsxFbtChildElement(
1366
| t.JSXFragment {
1367
const value = codegenPlace(cx, place);
1368
switch (value.type) {
1369
- case "StringLiteral": {
1370
- return createJsxExpressionContainer(place.loc, value);
1371
- }
1372
- case "JSXElement":
1373
- case "JSXFragment": {
1369
+ // fbt:param only allows JSX element or expression container as children
1370
+ case "JSXElement": {
1371
return value;
1372
}
1373
default: {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbtparam-with-jsx-fragment-value.expect.md
new
+55
@@ -0,0 +1,55 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import fbt from "fbt";
6
+import { identity } from "shared-runtime";
7
+
8
+function Component(props) {
9
+ return (
10
+ <Foo
11
+ value={
12
+ <fbt desc="Description of the parameter">
13
+ <fbt:param name="value">{<>{identity(props.text)}</>}</fbt:param>%
14
+ </fbt>
15
+ }
16
+ />
17
+ );
18
+}
19
+
20
+```
21
+
22
+## Code
23
+
24
+```javascript
25
+import { unstable_useMemoCache as useMemoCache } from "react";
26
+import fbt from "fbt";
27
+import { identity } from "shared-runtime";
28
+
29
+function Component(props) {
30
+ const $ = useMemoCache(4);
31
+ const c_0 = $[0] !== props.text;
32
+ let t0;
33
+ if (c_0) {
34
+ t0 = fbt._("{value}%", [fbt._param("value", <>{identity(props.text)}</>)], {
35
+ hk: "10F5Cc",
36
+ });
37
+ $[0] = props.text;
38
+ $[1] = t0;
39
+ } else {
40
+ t0 = $[1];
41
+ }
42
+ const c_2 = $[2] !== t0;
43
+ let t1;
44
+ if (c_2) {
45
+ t1 = <Foo value={t0} />;
46
+ $[2] = t0;
47
+ $[3] = t1;
48
+ } else {
49
+ t1 = $[3];
50
+ }
51
+ return t1;
52
+}
53
+
54
+```
55
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbtparam-with-jsx-fragment-value.js
new
+14
@@ -0,0 +1,14 @@
1
+import fbt from "fbt";
2
+import { identity } from "shared-runtime";
3
+
4
+function Component(props) {
5
+ return (
6
+ <Foo
7
+ value={
8
+ <fbt desc="Description of the parameter">
9
+ <fbt:param name="value">{<>{identity(props.text)}</>}</fbt:param>%
10
+ </fbt>
11
+ }
12
+ />
13
+ );
14
+}
compiler/packages/sprout/src/SproutTodoFilter.ts
+1
@@ -456,6 +456,7 @@ const skipFilter = new Set([
456
"class-component-with-render-helper",
457
"fbtparam-with-jsx-element-content",
458
"fbtparam-text-must-use-expression-container",
459
+ "fbtparam-with-jsx-fragment-value",
460
]);
461
462
export default skipFilter;