fix(es/react): Fix handling of whitespaces (#6935)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6931.
This commit is contained in:
Donny/강동윤 2023-02-13 06:35:55 +09:00 committed by GitHub
parent 5a598140c1
commit a9b25aaf4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -1336,15 +1336,19 @@ fn count_children(children: &[JSXElementChild]) -> usize {
fn transform_jsx_attr_str(v: &str) -> String {
let single_quote = false;
let mut buf = String::with_capacity(v.len());
let mut iter = v.chars().peekable();
for c in v.chars() {
while let Some(c) = iter.next() {
match c {
'\u{0008}' => buf.push_str("\\b"),
'\u{000c}' => buf.push_str("\\f"),
' ' | '\n' | '\r' | '\t' => {
if buf.ends_with(' ') {
} else {
buf.push(' ')
' ' => buf.push(' '),
'\n' | '\r' | '\t' => {
buf.push(' ');
while let Some(' ') = iter.peek() {
iter.next();
}
}
'\u{000b}' => buf.push_str("\\v"),

View File

@ -0,0 +1,2 @@
const f1 = <Component on={" "} />
const f2 = <Component on=" " />

View File

@ -0,0 +1,6 @@
const f1 = /*#__PURE__*/ React.createElement(Component, {
on: " "
});
const f2 = /*#__PURE__*/ React.createElement(Component, {
on: " "
});