-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler:codegen] Wrap non-ascii characters in JsxExpressionContainer
This PR extends the previous logic added in #29141 to also account for other kinds of non-ascii characters such as `\n`. Because these control characters are individual special characters (and not 2 characters `\` and `n`) we match based on unicode which was already being checked for non-Latin characters. This allows control characters to continue to be compiled equivalently to its original source if it was provided in a JsxExpressionContainer. However note that this PR does not convert JSX attributes that are StringLiterals to JsxExpressionContainer, to preserve the original source code as it was written. Alternatively we could always emit a JsxExpressionContainer if it was used in the source and not try to down level it to some other node kind. But since we already do this I opted to keep this behavior. Partially addresses #29648. ghstack-source-id: ecc61c9f0bece90d18623b3c570fea05fbcd811a Pull Request resolved: #29997
- Loading branch information
Showing
4 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...__tests__/fixtures/compiler/jsx-string-attribute-expression-container.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function Component() { | ||
return ( | ||
<div> | ||
<Text value={"\n"} /> | ||
<Text value={"A\tE"} /> | ||
<Text value={"나은"} /> | ||
<Text value={"Lauren"} /> | ||
<Text value={"சத்யா"} /> | ||
<Text value={"Sathya"} /> | ||
</div> | ||
); | ||
} | ||
|
||
function Text({ value }) { | ||
return <span>{value}</span>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Component() { | ||
const $ = _c(1); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = ( | ||
<div> | ||
<Text value={"\n"} /> | ||
<Text value={"A\tE"} /> | ||
<Text value={"\uB098\uC740"} /> | ||
<Text value="Lauren" /> | ||
<Text value={"\u0B9A\u0BA4\u0BCD\u0BAF\u0BBE"} /> | ||
<Text value="Sathya" /> | ||
</div> | ||
); | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
return t0; | ||
} | ||
|
||
function Text(t0) { | ||
const $ = _c(2); | ||
const { value } = t0; | ||
let t1; | ||
if ($[0] !== value) { | ||
t1 = <span>{value}</span>; | ||
$[0] = value; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div><span> | ||
</span><span>A E</span><span>나은</span><span>Lauren</span><span>சத்யா</span><span>Sathya</span></div> |
21 changes: 21 additions & 0 deletions
21
...act-compiler/src/__tests__/fixtures/compiler/jsx-string-attribute-expression-container.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function Component() { | ||
return ( | ||
<div> | ||
<Text value={"\n"} /> | ||
<Text value={"A\tE"} /> | ||
<Text value={"나은"} /> | ||
<Text value={"Lauren"} /> | ||
<Text value={"சத்யா"} /> | ||
<Text value={"Sathya"} /> | ||
</div> | ||
); | ||
} | ||
|
||
function Text({ value }) { | ||
return <span>{value}</span>; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{}], | ||
}; |