Skip to content

Commit 78e4e93

Browse files
committed
[compiler][repro] JSX escape sequences not printed correctly by @babel/generator
Repro for #32123 Note that this is only a bug when calling `@babel/generator:generate()` before transforming JSX.
1 parent 18eaf51 commit 78e4e93

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
## Input
3+
4+
```javascript
5+
/**
6+
* Fixture showing `@babel/generator` bug with jsx attribute strings containing
7+
* escape sequences. Note that this is only a problem when generating jsx
8+
* literals.
9+
*
10+
* When using the jsx transform to correctly lower jsx into
11+
* `React.createElement` calls, the escape sequences are preserved correctly
12+
* (see evaluator output).
13+
*/
14+
function MyApp() {
15+
return <input pattern="\w" />;
16+
}
17+
18+
export const FIXTURE_ENTRYPOINT = {
19+
fn: MyApp,
20+
params: [],
21+
};
22+
23+
```
24+
25+
## Code
26+
27+
```javascript
28+
import { c as _c } from "react/compiler-runtime"; /**
29+
* Fixture showing `@babel/generator` bug with jsx attribute strings containing
30+
* escape sequences. Note that this is only a problem when generating jsx
31+
* literals.
32+
*
33+
* When using the jsx transform to correctly lower jsx into
34+
* `React.createElement` calls, the escape sequences are preserved correctly
35+
* (see evaluator output).
36+
*/
37+
function MyApp() {
38+
const $ = _c(1);
39+
let t0;
40+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
41+
t0 = <input pattern="\\w" />;
42+
$[0] = t0;
43+
} else {
44+
t0 = $[0];
45+
}
46+
return t0;
47+
}
48+
49+
export const FIXTURE_ENTRYPOINT = {
50+
fn: MyApp,
51+
params: [],
52+
};
53+
54+
```
55+
56+
### Eval output
57+
(kind: ok) <input pattern="\w">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Fixture showing `@babel/generator` bug with jsx attribute strings containing
3+
* escape sequences. Note that this is only a problem when generating jsx
4+
* literals.
5+
*
6+
* When using the jsx transform to correctly lower jsx into
7+
* `React.createElement` calls, the escape sequences are preserved correctly
8+
* (see evaluator output).
9+
*/
10+
function MyApp() {
11+
return <input pattern="\w" />;
12+
}
13+
14+
export const FIXTURE_ENTRYPOINT = {
15+
fn: MyApp,
16+
params: [],
17+
};

0 commit comments

Comments
 (0)