Skip to content

Commit cc6e635

Browse files
authored
fix: jsx line breaks should respect quote config (#302)
1 parent d4a12e7 commit cc6e635

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/parsing/parser.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7941,11 +7941,18 @@ fn jsx_space_separator(previous_node: &Node, current_node: &Node, context: &Cont
79417941
}
79427942
}
79437943

7944+
fn get_quote_char(context: &Context) -> String {
7945+
return match context.config.quote_style {
7946+
QuoteStyle::PreferDouble | QuoteStyle::AlwaysDouble => "\"".to_string(),
7947+
QuoteStyle::PreferSingle | QuoteStyle::AlwaysSingle => "'".to_string()
7948+
};
7949+
}
7950+
79447951
fn jsx_force_space_with_newline_if_either_node_multi_line(previous_node: &Node, current_node: &Node, context: &Context) -> PrintItems {
79457952
let previous_node_info_range = get_node_info_range(previous_node, context);
79467953
let current_node_info_range = get_node_info_range(current_node, context);
79477954
let spaces_between_count = node_helpers::count_spaces_between_jsx_children(previous_node, current_node, &context.module);
7948-
let jsx_space_expr_text = format!("{{\"{}\"}}", " ".repeat(spaces_between_count));
7955+
let jsx_space_expr_text = format!("{{{}{}{}}}", get_quote_char(context), " ".repeat(spaces_between_count), get_quote_char(context));
79497956
if_true_or(
79507957
"jsxIsLastChildMultiLine",
79517958
move |condition_context| {
@@ -7992,7 +7999,7 @@ fn jsx_space_separator(previous_node: &Node, current_node: &Node, context: &Cont
79927999

79938000
if spaces_between_count > 1 {
79948001
items.push_signal(Signal::PossibleNewLine);
7995-
items.push_string(format!("{{\"{}\"}}", " ".repeat(spaces_between_count)));
8002+
items.push_string(format!("{{{}{}{}}}", get_quote_char(context), " ".repeat(spaces_between_count), get_quote_char(context)));
79968003
items.push_signal(Signal::PossibleNewLine);
79978004
return items;
79988005
}
@@ -8032,7 +8039,7 @@ fn jsx_space_separator(previous_node: &Node, current_node: &Node, context: &Cont
80328039
true_path: {
80338040
let mut items = PrintItems::new();
80348041
items.push_signal(Signal::PossibleNewLine);
8035-
items.push_str("{\" \"}");
8042+
items.push_string(format!("{{{} {}}}", get_quote_char(context), get_quote_char(context)));
80368043
items.push_signal(Signal::NewLine);
80378044
Some(items)
80388045
},

tests/specs/literals/StringLiteral/StringLiteral_QuoteStyle_AlwaysSingle_Jsx.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@ const test = <div test="'"></div>;
55

66
[expect]
77
const test = <div test="'"></div>;
8+
9+
== should use correct quote style when breaking jsx text ==
10+
const test = <>This is a really long line that should be broken up, with a space: {value} and the space should use the configured quote style</>;
11+
12+
[expect]
13+
const test = (
14+
<>
15+
This is a really long line that should be broken up, with a space: {value}{' '}
16+
and the space should use the configured quote style
17+
</>
18+
);

0 commit comments

Comments
 (0)