Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler][ez] Patch for JSX escape sequences in @babel/generator #32131

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2269,7 +2269,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,57 @@

## Input

```javascript
/**
* Fixture showing `@babel/generator` bug with jsx attribute strings containing
* escape sequences. Note that this is only a problem when generating jsx
* literals.
*
* When using the jsx transform to correctly lower jsx into
* `React.createElement` calls, the escape sequences are preserved correctly
* (see evaluator output).
*/
function MyApp() {
return <input pattern="\w" />;
}

export const FIXTURE_ENTRYPOINT = {
fn: MyApp,
params: [],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime"; /**
* Fixture showing `@babel/generator` bug with jsx attribute strings containing
* escape sequences. Note that this is only a problem when generating jsx
* literals.
*
* When using the jsx transform to correctly lower jsx into
* `React.createElement` calls, the escape sequences are preserved correctly
* (see evaluator output).
*/
function MyApp() {
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <input pattern={"\\w"} />;
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
}

export const FIXTURE_ENTRYPOINT = {
fn: MyApp,
params: [],
};

```

### Eval output
(kind: ok) <input pattern="\w">
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Fixture showing `@babel/generator` bug with jsx attribute strings containing
* escape sequences. Note that this is only a problem when generating jsx
* literals.
*
* When using the jsx transform to correctly lower jsx into
* `React.createElement` calls, the escape sequences are preserved correctly
* (see evaluator output).
*/
function MyApp() {
return <input pattern="\w" />;
}

export const FIXTURE_ENTRYPOINT = {
fn: MyApp,
params: [],
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,23 @@ function V0(t0) {
<ComponentC cd="TxqUy" ce="oh`]uc" cf="Bdbo" c10={!V9.va && v11.v12}>
gmhubcw
{v1 === V3.V13 ? (
<c14 c15="L^]w\\\\T\\\\qrGmqrlQyrvBgf\\\\inuRdkEqwVPwixiriYGSZmKJf]E]RdT{N[WyVPiEJIbdFzvDohJV[BV`H[[K^xoy[HOGKDqVzUJ^h">
<c14
c15={
"L^]w\\\\T\\\\qrGmqrlQyrvBgf\\\\inuRdkEqwVPwixiriYGSZmKJf]E]RdT{N[WyVPiEJIbdFzvDohJV[BV`H[[K^xoy[HOGKDqVzUJ^h"
}
>
iawyneijcgamsfgrrjyvhjrrqvzexxwenxqoknnilmfloafyvnvkqbssqnxnexqvtcpvjysaiovjxyqrorqskfph
</c14>
) : v16.v17("pyorztRC]EJzVuP^e") ? (
<c14 c15="CRinMqvmOknWRAKERI]RBzB_LXGKQe{SUpoN[\\\\gL[`bLMOhvFqDVVMNOdY">
<c14
c15={
"CRinMqvmOknWRAKERI]RBzB_LXGKQe{SUpoN[\\\\gL[`bLMOhvFqDVVMNOdY"
}
>
goprinbjmmjhfserfuqyluxcewpyjihektogc
</c14>
) : (
<c14 c15="H\\\\\\\\GAcTc\\\\lfGMW[yHriCpvW`w]niSIKj\\\\kdgFI">
<c14 c15={"H\\\\\\\\GAcTc\\\\lfGMW[yHriCpvW`w]niSIKj\\\\kdgFI"}>
yejarlvudihqdrdgpvahovggdnmgnueedxpbwbkdvvkdhqwrtoiual
</c14>
)}
Expand Down
Loading