Skip to content

Commit

Permalink
fix(es/codegen): Use raw value for emitting JSX text (#9762)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9758
  • Loading branch information
magic-akari authored Nov 27, 2024
1 parent fa80a1e commit b83c44f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/little-scissors-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_ecma_codegen: patch
swc_core: patch
---

fix(es/codegen): use raw value for emitting JSX text
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/src/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_codegen/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions crates/swc_ecma_codegen/tests/fixture/issue-9758/input.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

export function Test() {
return (
<div className={test}>
<span>&gt; 右上角设置</span>
<span>&gt; 保证金管理</span>
</div>
);
}
7 changes: 7 additions & 0 deletions crates/swc_ecma_codegen/tests/fixture/issue-9758/output.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';
export function Test() {
return (<div className={test}>
<span>&gt; 右上角设置</span>
<span>&gt; 保证金管理</span>
</div>);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import React from"react";export function Test(){return(<div className={test}>
<span>&gt; 右上角设置</span>
<span>&gt; 保证金管理</span>
</div>)}

0 comments on commit b83c44f

Please sign in to comment.