Skip to content

Commit a9b25aa

Browse files
authoredFeb 12, 2023
fix(es/react): Fix handling of whitespaces (#6935)
**Related issue:** - Closes #6931.
1 parent 5a59814 commit a9b25aa

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed
 

‎crates/swc_ecma_transforms_react/src/jsx/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1336,15 +1336,19 @@ fn count_children(children: &[JSXElementChild]) -> usize {
13361336
fn transform_jsx_attr_str(v: &str) -> String {
13371337
let single_quote = false;
13381338
let mut buf = String::with_capacity(v.len());
1339+
let mut iter = v.chars().peekable();
13391340

1340-
for c in v.chars() {
1341+
while let Some(c) = iter.next() {
13411342
match c {
13421343
'\u{0008}' => buf.push_str("\\b"),
13431344
'\u{000c}' => buf.push_str("\\f"),
1344-
' ' | '\n' | '\r' | '\t' => {
1345-
if buf.ends_with(' ') {
1346-
} else {
1347-
buf.push(' ')
1345+
' ' => buf.push(' '),
1346+
1347+
'\n' | '\r' | '\t' => {
1348+
buf.push(' ');
1349+
1350+
while let Some(' ') = iter.peek() {
1351+
iter.next();
13481352
}
13491353
}
13501354
'\u{000b}' => buf.push_str("\\v"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const f1 = <Component on={" "} />
2+
const f2 = <Component on=" " />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const f1 = /*#__PURE__*/ React.createElement(Component, {
2+
on: " "
3+
});
4+
const f2 = /*#__PURE__*/ React.createElement(Component, {
5+
on: " "
6+
});

0 commit comments

Comments
 (0)
Please sign in to comment.