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: fix jsx text attributes with double quotes #29079

Merged
Merged
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 @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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\"
Original file line number Diff line number Diff line change
@@ -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: [{}],
};
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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: [{}],
};
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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: [{}],
};
5 changes: 5 additions & 0 deletions compiler/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading