[compiler][repro] JSX escape sequences not printed correctly by @babel/generator (#32130)
Repro for https://github.com/facebook/react/issues/32123 Note that this is only a bug when calling `@babel/generator:generate()` before transforming JSX. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32130). * #32131 * __->__ #32130
mofeiZ committed
Jan 22, 2025 at 13:52 UTC
19557443c8c2f54571dbb1519403cf310ad6e68b
2 files changed
+74
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-preserve-escape-character.expect.md
new
+57
@@ -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">
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-preserve-escape-character.js
new
+17
@@ -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
+};