Skip to content

Commit

Permalink
fix(react-compiler): JSXText emits incorrect with bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed Jan 22, 2025
1 parent 028c8e6 commit 6efadb9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { c as _c } from "react/compiler-runtime"; // 
        @compilationMode(all)
function Component() {
  const $ = _c(1);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = <div>{"Hello, {world}!"}</div>;
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  return t0;
}
9 changes: 9 additions & 0 deletions compiler/apps/playground/__tests__/e2e/page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ function nonReactFn() {
input: `// @compilationMode(all)
function nonReactFn() {
return {};
}
`,
noFormat: true,
},
{
name: 'bracket-in-jsx-text',
input: `// @compilationMode(all)
function Component() {
return <div>Hello, &#123;world&#125;!</div>;
}
`,
noFormat: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,7 @@ function codegenJsxAttribute(
}
}

const JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&]/;
const JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&{}]/;
function codegenJsxElement(
cx: Context,
place: Place,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

## Input

```javascript
function Test() {
return (
<div>
If the string contains the string &#123;pageNumber&#125; it will be
replaced by the page number.
</div>
);
}

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

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
function Test() {
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = (
<div>
{
"If the string contains the string {pageNumber} it will be replaced by the page number."
}
</div>
);
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
}

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

```
### Eval output
(kind: ok) <div>If the string contains the string {pageNumber} it will be replaced by the page number.</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Test() {
return (
<div>
If the string contains the string &#123;pageNumber&#125; it will be
replaced by the page number.
</div>
);
}

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

0 comments on commit 6efadb9

Please sign in to comment.