Skip to content

Commit b2e3720

Browse files
authored
fix: jsx.bracketPosition - Was adding an extra space when single line (#447)
1 parent e029fab commit b2e3720

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/generation/generate.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,13 +3611,9 @@ fn gen_jsx_opening_element<'a>(node: &'a JSXOpeningElement, context: &mut Contex
36113611
items.extend(gen_node(type_args.into(), context));
36123612
}
36133613

3614-
let single_line_space_at_end = node.self_closing() && space_before_self_closing_tag_slash;
36153614
if node.attrs.len() == 1 && node.type_args.is_none() && is_jsx_attr_with_string(&node.attrs[0]) {
36163615
items.push_str(" ");
36173616
items.extend(gen_node(node.attrs[0].into(), context));
3618-
if single_line_space_at_end {
3619-
items.push_str(" ");
3620-
}
36213617
} else if !node.attrs.is_empty() {
36223618
let mut multi_line_options = ir_helpers::MultiLineOptions::surround_newlines_indented();
36233619
multi_line_options.newline_at_end = prefer_newline_before_close_bracket;
@@ -3629,7 +3625,7 @@ fn gen_jsx_opening_element<'a>(node: &'a JSXOpeningElement, context: &mut Contex
36293625
allow_blank_lines: false,
36303626
separator: Separator::none(),
36313627
single_line_space_at_start: true,
3632-
single_line_space_at_end,
3628+
single_line_space_at_end: false,
36333629
custom_single_line_separator: None,
36343630
multi_line_options,
36353631
force_possible_newline_at_start: false,
@@ -3653,7 +3649,7 @@ fn gen_jsx_opening_element<'a>(node: &'a JSXOpeningElement, context: &mut Contex
36533649
}
36543650

36553651
if node.self_closing() {
3656-
if (node.attrs.is_empty() || !prefer_newline_before_close_bracket) && space_before_self_closing_tag_slash {
3652+
if space_before_self_closing_tag_slash {
36573653
items.push_str(""); // force current line indentation
36583654
items.extend(space_if_not_start_line());
36593655
}

tests/specs/jsx/JsxElement/JsxElement_BracketPosition_Maintain.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ const x = (
6262
prop={5}
6363
other={10} />
6464
);
65+
66+
== should maintain for single line ==
67+
const t = <MyComponent someProp={value} />;
68+
const u = <MyComponent></MyComponent>;
69+
70+
[expect]
71+
const t = <MyComponent someProp={value} />;
72+
const u = <MyComponent></MyComponent>;

tests/specs/jsx/JsxElement/JsxElement_BracketPosition_NextLine.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ const w = (
5353
other={10}
5454
/>
5555
);
56+
57+
== should maintain for single line ==
58+
const t = <MyComponent someProp={value} />;
59+
const u = <MyComponent></MyComponent>;
60+
61+
[expect]
62+
const t = <MyComponent someProp={value} />;
63+
const u = <MyComponent></MyComponent>;

tests/specs/jsx/JsxElement/JsxElement_BracketPosition_SameLine.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@ const w = (
5050
prop={5}
5151
other={10} />
5252
);
53+
54+
== should maintain for single line ==
55+
const t = <MyComponent someProp={value} />;
56+
const u = <MyComponent></MyComponent>;
57+
58+
[expect]
59+
const t = <MyComponent someProp={value} />;
60+
const u = <MyComponent></MyComponent>;

0 commit comments

Comments
 (0)