fbt:param does not allow jsxfragment children

This commit is contained in:
Joe Savona
2023-09-15 12:10:51 -07:00
parent dc4e63e2d5
commit bde7875f20
4 changed files with 72 additions and 5 deletions
@@ -1366,11 +1366,8 @@ function codegenJsxFbtChildElement(
| t.JSXFragment {
const value = codegenPlace(cx, place);
switch (value.type) {
case "StringLiteral": {
return createJsxExpressionContainer(place.loc, value);
}
case "JSXElement":
case "JSXFragment": {
// fbt:param only allows JSX element or expression container as children
case "JSXElement": {
return value;
}
default: {
@@ -0,0 +1,55 @@
## Input
```javascript
import fbt from "fbt";
import { identity } from "shared-runtime";
function Component(props) {
return (
<Foo
value={
<fbt desc="Description of the parameter">
<fbt:param name="value">{<>{identity(props.text)}</>}</fbt:param>%
</fbt>
}
/>
);
}
```
## Code
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
import fbt from "fbt";
import { identity } from "shared-runtime";
function Component(props) {
const $ = useMemoCache(4);
const c_0 = $[0] !== props.text;
let t0;
if (c_0) {
t0 = fbt._("{value}%", [fbt._param("value", <>{identity(props.text)}</>)], {
hk: "10F5Cc",
});
$[0] = props.text;
$[1] = t0;
} else {
t0 = $[1];
}
const c_2 = $[2] !== t0;
let t1;
if (c_2) {
t1 = <Foo value={t0} />;
$[2] = t0;
$[3] = t1;
} else {
t1 = $[3];
}
return t1;
}
```
@@ -0,0 +1,14 @@
import fbt from "fbt";
import { identity } from "shared-runtime";
function Component(props) {
return (
<Foo
value={
<fbt desc="Description of the parameter">
<fbt:param name="value">{<>{identity(props.text)}</>}</fbt:param>%
</fbt>
}
/>
);
}
@@ -456,6 +456,7 @@ const skipFilter = new Set([
"class-component-with-render-helper",
"fbtparam-with-jsx-element-content",
"fbtparam-text-must-use-expression-container",
"fbtparam-with-jsx-fragment-value",
]);
export default skipFilter;