Skip to content

Commit

Permalink
[compiler][patch] Fix jsx non-ascii regex pattern
Browse files Browse the repository at this point in the history
ghstack-source-id: e0668730759801f9c80baa30c193a8b8251f7e79
Pull Request resolved: #30382
  • Loading branch information
mofeiZ committed Jul 18, 2024
1 parent 512b09b commit 5daad54
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ function codegenInstructionValue(
* https://en.wikipedia.org/wiki/List_of_Unicode_characters#Control_codes
*/
const STRING_REQUIRES_EXPR_CONTAINER_PATTERN =
/[\u{0000}-\u{001F}|\u{007F}|\u{0080}-\u{FFFF}]|"/u;
/[\u{0000}-\u{001F}\u{007F}\u{0080}-\u{FFFF}]"/u;
function codegenJsxAttribute(
cx: Context,
attribute: JsxAttribute
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

## Input

```javascript
import fbt from "fbt";

function Component(props) {
const element = (
<fbt desc={"Dialog to show to user"}>
Hello <fbt:param name="user name ☺">{props.name}</fbt:param>
</fbt>
);
return element.toString();
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ name: "Jason" }],
};

```


## Error

```
Property arguments[0] of CallExpression expected node to be of a type ["Expression","SpreadElement","JSXNamespacedName","ArgumentPlaceholder"] but instead got "JSXExpressionContainer"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fbt from "fbt";

function Component(props) {
const element = (
<fbt desc={"Dialog to show to user"}>
Hello <fbt:param name="user name ☺">{props.name}</fbt:param>
</fbt>
);
return element.toString();
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ name: "Jason" }],
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import fbt from "fbt";

function Component(props) {
return (
<fbt desc={"Dialog to show to user"}>
Hello <fbt:param name="user name">{props.name}</fbt:param>
</fbt>
<div>
<fbt desc={"Dialog to show to user"}>
Hello <fbt:param name="user name">{props.name}</fbt:param>
</fbt>
<fbt desc={"Available actions|response"}>
<fbt:param name="actions|response">{props.actions}</fbt:param>
</fbt>
</div>
);
}

Expand All @@ -27,7 +32,7 @@ import { c as _c } from "react/compiler-runtime";
import fbt from "fbt";

function Component(props) {
const $ = _c(2);
const $ = _c(7);
let t0;
if ($[0] !== props.name) {
t0 = fbt._("Hello {user name}", [fbt._param("user name", props.name)], {
Expand All @@ -38,7 +43,33 @@ function Component(props) {
} else {
t0 = $[1];
}
return t0;
let t1;
if ($[2] !== props.actions) {
t1 = fbt._(
"{actions|response}",
[fbt._param("actions|response", props.actions)],
{ hk: "1cjfbg" },
);
$[2] = props.actions;
$[3] = t1;
} else {
t1 = $[3];
}
let t2;
if ($[4] !== t0 || $[5] !== t1) {
t2 = (
<div>
{t0}
{t1}
</div>
);
$[4] = t0;
$[5] = t1;
$[6] = t2;
} else {
t2 = $[6];
}
return t2;
}

export const FIXTURE_ENTRYPOINT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import fbt from "fbt";

function Component(props) {
return (
<fbt desc={"Dialog to show to user"}>
Hello <fbt:param name="user name">{props.name}</fbt:param>
</fbt>
<div>
<fbt desc={"Dialog to show to user"}>
Hello <fbt:param name="user name">{props.name}</fbt:param>
</fbt>
<fbt desc={"Available actions|response"}>
<fbt:param name="actions|response">{props.actions}</fbt:param>
</fbt>
</div>
);
}

Expand Down

0 comments on commit 5daad54

Please sign in to comment.