mirror of
https://github.com/facebook/react.git
synced 2026-02-23 20:23:02 +00:00
compiler: fix jsx text attributes with double quotes (#29079)
Fixes #29069 by detecting the presence of double-quotes in JSX attribute strings and falling back to using an expression container.
This commit is contained in:
@@ -2040,6 +2040,9 @@ function codegenJsxAttribute(
|
||||
switch (innerValue.type) {
|
||||
case "StringLiteral": {
|
||||
value = innerValue;
|
||||
if (value.value.indexOf('"') !== -1) {
|
||||
value = createJsxExpressionContainer(value.loc, value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
export function Component() {
|
||||
return <Child text='Some \"text\"' />;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
return props.text;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { c as _c } from "react/compiler-runtime";
|
||||
export function Component() {
|
||||
const $ = _c(1);
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = <Child text={'Some \\"text\\"'} />;
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
return props.text;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) Some \"text\"
|
||||
@@ -0,0 +1,12 @@
|
||||
export function Component() {
|
||||
return <Child text='Some \"text\"' />;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
return props.text;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
export function Component() {
|
||||
return <Child text='Some "text"' />;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
return props.text;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { c as _c } from "react/compiler-runtime";
|
||||
export function Component() {
|
||||
const $ = _c(1);
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = <Child text={'Some "text"'} />;
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
return props.text;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) Some "text"
|
||||
@@ -0,0 +1,12 @@
|
||||
export function Component() {
|
||||
return <Child text='Some "text"' />;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
return props.text;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
export function Component() {
|
||||
// Test what happens if a string with double-quotes is interpolated via constant propagation
|
||||
const text = 'Some "text"';
|
||||
return <Child text={text} />;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
return props.text;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { c as _c } from "react/compiler-runtime";
|
||||
export function Component() {
|
||||
const $ = _c(1);
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = <Child text={'Some "text"'} />;
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
return props.text;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) Some "text"
|
||||
@@ -0,0 +1,14 @@
|
||||
export function Component() {
|
||||
// Test what happens if a string with double-quotes is interpolated via constant propagation
|
||||
const text = 'Some "text"';
|
||||
return <Child text={text} />;
|
||||
}
|
||||
|
||||
function Child(props) {
|
||||
return props.text;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
@@ -3745,6 +3745,11 @@ babel-plugin-polyfill-regenerator@^0.5.0:
|
||||
dependencies:
|
||||
"@babel/helper-define-polyfill-provider" "^0.4.0"
|
||||
|
||||
babel-plugin-react-compiler@*:
|
||||
version "0.0.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-react-compiler/-/babel-plugin-react-compiler-0.0.0.tgz#1a1f9867fad83f217f0b3fe6f1b94cca0b77b68b"
|
||||
integrity sha512-Kigl0V36a/6hLVH7+CCe1CCtU3mFBqBd829V//VtuG7I/pyq+B2QZJqOefd63snQmdfCryNhO9XW1FbGPBvYDA==
|
||||
|
||||
babel-plugin-syntax-hermes-parser@^0.15.1:
|
||||
version "0.15.1"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-hermes-parser/-/babel-plugin-syntax-hermes-parser-0.15.1.tgz#d115ee9761a808af590a9b2a0b568115e25ea743"
|
||||
|
||||
Reference in New Issue
Block a user