Skip to content

Commit de1a087

Browse files
committed
fix(react-compiler): JSXText emits incorrect with bracket
1 parent 18eaf51 commit de1a087

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { c as _c } from "react/compiler-runtime"; // 
2+
        @compilationMode(all)
3+
function Component() {
4+
  const $ = _c(1);
5+
  let t0;
6+
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
7+
    t0 = <div>{"Hello, {world}!"}</div>;
8+
    $[0] = t0;
9+
  } else {
10+
    t0 = $[0];
11+
  }
12+
  return t0;
13+
}

compiler/apps/playground/__tests__/e2e/page.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ function nonReactFn() {
9797
input: `// @compilationMode(all)
9898
function nonReactFn() {
9999
return {};
100+
}
101+
`,
102+
noFormat: true,
103+
},
104+
{
105+
name: 'bracket-in-jsx-text',
106+
input: `// @compilationMode(all)
107+
function Component() {
108+
return <div>Hello, &#123;world&#125;!</div>;
100109
}
101110
`,
102111
noFormat: true,

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,7 @@ function codegenJsxAttribute(
23272327
}
23282328
}
23292329

2330-
const JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&]/;
2330+
const JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&{}]/;
23312331
function codegenJsxElement(
23322332
cx: Context,
23332333
place: Place,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
## Input
3+
4+
```javascript
5+
function Test({friends}) {
6+
return (
7+
<div>
8+
If the string contains the string &#123;pageNumber&#125; it will be
9+
replaced by the page number.
10+
</div>
11+
);
12+
}
13+
14+
export const FIXTURE_ENTRYPOINT = {
15+
fn: Test,
16+
params: [{friends: []}],
17+
};
18+
```
19+
20+
## Code
21+
22+
```javascript
23+
import { c as _c } from "react/compiler-runtime";
24+
function Test(t0) {
25+
const $ = _c(1);
26+
let t1;
27+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28+
t1 = (
29+
<div>
30+
{
31+
"If the string contains the string {pageNumber} it will be replaced by the page number."
32+
}
33+
</div>
34+
);
35+
$[0] = t1;
36+
} else {
37+
t1 = $[0];
38+
}
39+
return t1;
40+
}
41+
42+
export const FIXTURE_ENTRYPOINT = {
43+
fn: Test,
44+
params: [{ friends: [] }],
45+
};
46+
47+
```
48+
49+
### Eval output
50+
(kind: ok) <div>If the string contains the string {pageNumber} it will be replaced by the page number.</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function Test() {
2+
return (
3+
<div>
4+
If the string contains the string &#123;pageNumber&#125; it will be
5+
replaced by the page number.
6+
</div>
7+
);
8+
}
9+
10+
export const FIXTURE_ENTRYPOINT = {
11+
fn: Test,
12+
};

0 commit comments

Comments
 (0)