From b83c44f4ad604edc30ec157aa8fb0d8755adb389 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Wed, 27 Nov 2024 11:37:10 +0800 Subject: [PATCH] fix(es/codegen): Use raw value for emitting JSX text (#9762) **Related issue:** - Closes https://github.com/swc-project/swc/issues/9758 --- .changeset/little-scissors-join.md | 6 ++++++ crates/swc_ecma_codegen/src/jsx.rs | 2 +- crates/swc_ecma_codegen/tests/fixture.rs | 1 + .../tests/fixture/issue-9758/input.jsx | 10 ++++++++++ .../tests/fixture/issue-9758/output.jsx | 7 +++++++ .../tests/fixture/issue-9758/output.min.jsx | 4 ++++ 6 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .changeset/little-scissors-join.md create mode 100644 crates/swc_ecma_codegen/tests/fixture/issue-9758/input.jsx create mode 100644 crates/swc_ecma_codegen/tests/fixture/issue-9758/output.jsx create mode 100644 crates/swc_ecma_codegen/tests/fixture/issue-9758/output.min.jsx diff --git a/.changeset/little-scissors-join.md b/.changeset/little-scissors-join.md new file mode 100644 index 000000000000..b70c335b45c6 --- /dev/null +++ b/.changeset/little-scissors-join.md @@ -0,0 +1,6 @@ +--- +swc_ecma_codegen: patch +swc_core: patch +--- + +fix(es/codegen): use raw value for emitting JSX text diff --git a/crates/swc_ecma_codegen/src/jsx.rs b/crates/swc_ecma_codegen/src/jsx.rs index 9f1483b65101..f304ed138b47 100644 --- a/crates/swc_ecma_codegen/src/jsx.rs +++ b/crates/swc_ecma_codegen/src/jsx.rs @@ -174,7 +174,7 @@ where #[emitter] fn emit_jsx_text(&mut self, node: &JSXText) -> Result { - self.emit_atom(node.span(), &node.value)?; + self.emit_atom(node.span(), &node.raw)?; } #[emitter] diff --git a/crates/swc_ecma_codegen/tests/fixture.rs b/crates/swc_ecma_codegen/tests/fixture.rs index 09a7ed8853ea..db158f9a2480 100644 --- a/crates/swc_ecma_codegen/tests/fixture.rs +++ b/crates/swc_ecma_codegen/tests/fixture.rs @@ -74,6 +74,7 @@ fn ts(input: PathBuf) { } #[testing::fixture("tests/fixture/**/input.js")] +#[testing::fixture("tests/fixture/**/input.jsx")] fn js(input: PathBuf) { run(&input, false); run(&input, true); diff --git a/crates/swc_ecma_codegen/tests/fixture/issue-9758/input.jsx b/crates/swc_ecma_codegen/tests/fixture/issue-9758/input.jsx new file mode 100644 index 000000000000..54dbad957bdb --- /dev/null +++ b/crates/swc_ecma_codegen/tests/fixture/issue-9758/input.jsx @@ -0,0 +1,10 @@ +import React from 'react'; + +export function Test() { + return ( +
+ > 右上角设置 + > 保证金管理 +
+ ); +} diff --git a/crates/swc_ecma_codegen/tests/fixture/issue-9758/output.jsx b/crates/swc_ecma_codegen/tests/fixture/issue-9758/output.jsx new file mode 100644 index 000000000000..2e1a49ff5f31 --- /dev/null +++ b/crates/swc_ecma_codegen/tests/fixture/issue-9758/output.jsx @@ -0,0 +1,7 @@ +import React from 'react'; +export function Test() { + return (
+ > 右上角设置 + > 保证金管理 +
); +} diff --git a/crates/swc_ecma_codegen/tests/fixture/issue-9758/output.min.jsx b/crates/swc_ecma_codegen/tests/fixture/issue-9758/output.min.jsx new file mode 100644 index 000000000000..caa2a354b86c --- /dev/null +++ b/crates/swc_ecma_codegen/tests/fixture/issue-9758/output.min.jsx @@ -0,0 +1,4 @@ +import React from"react";export function Test(){return(
+ > 右上角设置 + > 保证金管理 +
)}