Skip to content

Commit 0193ead

Browse files
committed
Preserve parens starting with explicit newline (fixes dprint#519).
1 parent 4283426 commit 0193ead

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/generation/generate.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,6 +2878,12 @@ fn should_skip_paren_expr<'a>(node: &'a ParenExpr<'a>, context: &Context<'a>) ->
28782878
return is_jsx_paren_expr_handled_node(node.expr.into(), context);
28792879
}
28802880

2881+
// keep when there is an explicit newline after the paren
2882+
let node_text = node.text_fast(context.program);
2883+
if !utils::has_no_new_lines_in_leading_whitespace(&node_text[1..]) {
2884+
return false;
2885+
}
2886+
28812887
if let Node::AssignExpr(assign_expr) = parent {
28822888
if assign_expr.right.range().contains(&node.range()) {
28832889
return true;

tests/specs/issues/issue0519.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
== should keep parens when starting with an explicit newline ==
2+
const mathResult = (
3+
1 + 2);
4+
const mathResult = (1 + 2
5+
);
6+
7+
[expect]
8+
const mathResult = (
9+
1 + 2
10+
);
11+
const mathResult = 1 + 2;

0 commit comments

Comments
 (0)