From 6bb897cba3e6d00e043604be658900f14bd096ea Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Thu, 18 Jul 2024 14:32:00 -0400 Subject: [PATCH] [compiler][patch] Fix jsx non-ascii regex pattern ghstack-source-id: 19aa7901306dc2b6e8e67a4782677a92256a9476 Pull Request resolved: https://github.com/facebook/react/pull/30382 --- .../ReactiveScopes/CodegenReactiveFunction.ts | 2 +- ...rror.todo-fbt-param-with-unicode.expect.md | 30 ++++++++++++++ .../fbt/error.todo-fbt-param-with-unicode.js | 15 +++++++ .../compiler/fbt/fbt-params.expect.md | 41 ++++++++++++++++--- .../fixtures/compiler/fbt/fbt-params.js | 11 +++-- 5 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-param-with-unicode.expect.md create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-param-with-unicode.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts b/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts index 38d030cd71..ff11c09939 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts @@ -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 diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-param-with-unicode.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-param-with-unicode.expect.md new file mode 100644 index 0000000000..ef75314048 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-param-with-unicode.expect.md @@ -0,0 +1,30 @@ + +## Input + +```javascript +import fbt from "fbt"; + +function Component(props) { + const element = ( + + Hello {props.name} + + ); + 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" +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-param-with-unicode.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-param-with-unicode.js new file mode 100644 index 0000000000..3e1883fa1d --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/error.todo-fbt-param-with-unicode.js @@ -0,0 +1,15 @@ +import fbt from "fbt"; + +function Component(props) { + const element = ( + + Hello {props.name} + + ); + return element.toString(); +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{ name: "Jason" }], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-params.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-params.expect.md index d5ec6eb468..c15244491f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-params.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-params.expect.md @@ -6,9 +6,14 @@ import fbt from "fbt"; function Component(props) { return ( - - Hello {props.name} - +
+ + Hello {props.name} + + + {props.actions} + +
); } @@ -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)], { @@ -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 = ( +
+ {t0} + {t1} +
+ ); + $[4] = t0; + $[5] = t1; + $[6] = t2; + } else { + t2 = $[6]; + } + return t2; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-params.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-params.js index b2959036e5..4750fcf8a7 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-params.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-params.js @@ -2,9 +2,14 @@ import fbt from "fbt"; function Component(props) { return ( - - Hello {props.name} - +
+ + Hello {props.name} + + + {props.actions} + +
); }