Skip to content

Commit

Permalink
fix: arguments.spaceAround not adding spaces when an arrow function…
Browse files Browse the repository at this point in the history
… is the only argument (#606)
  • Loading branch information
Thristhart authored Feb 8, 2024
1 parent d91d876 commit 3bb079a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/generation/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7284,8 +7284,11 @@ where
items.push_info(start_ln);
items.push_info(start_lsil);
items.push_signal(Signal::PossibleNewLine);
if space_around {
items.push_signal(Signal::SpaceIfNotTrailing);
}
items.push_condition(conditions::indent_if_start_of_line(generated_node));
items.push_condition(if_true(
items.push_condition(if_true_or(
"isDifferentLineAndStartLineIndentation",
Rc::new(move |context| {
let start_ln = context.resolved_line_number(start_ln)?;
Expand All @@ -7295,6 +7298,7 @@ where
Some(is_different_line && is_different_start_line_indentation)
}),
Signal::NewLine.into(),
if space_around { Signal::SpaceIfNotTrailing.into() } else { PrintItems::new() },
));
} else {
let last_comma_token = nodes.last().and_then(|n| context.token_finder.get_next_token_if_comma(n));
Expand Down
21 changes: 21 additions & 0 deletions tests/specs/general/Arguments_SpaceAround_True.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ testing(1, 2, 3);
testing({a: 5});
testing({abcdefghijklmnop: true, bcdefg: false});
testing(123456, 123456, 123456, 123456);
then(() => ({abcdefghijklmnop: true, bcdefg: false}));
then(() => done());

[expect]
testing( true );
Expand All @@ -20,6 +22,11 @@ testing(
123456,
123456,
);
then( () => ({
abcdefghijklmnop: true,
bcdefg: false,
}) );
then( () => done() );

== should not add spaces on empty arguments ==
testing()
Expand All @@ -28,3 +35,17 @@ testing() === true;
[expect]
testing();
testing() === true;

== should not add spaces when indented ==
function test() {
then( () =>
abcdefghijklmnop()
);
}

[expect]
function test() {
then( () =>
abcdefghijklmnop()
);
}

0 comments on commit 3bb079a

Please sign in to comment.