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 ( +