Skip to content

Commit 74593cb

Browse files
authored
fix(regression): call expr with/without optional chain should not format differently in tpl lit (#557)
1 parent d062bed commit 74593cb

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/generation/generate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,7 @@ fn gen_template_literal<'a>(quasis: Vec<Node<'a>>, exprs: Vec<Node<'a>>, context
30173017

30183018
fn get_possible_surround_newlines(node: Node) -> bool {
30193019
match node {
3020+
Node::OptChainExpr(expr) => get_possible_surround_newlines(expr.base.as_node()),
30203021
Node::CondExpr(_) => true,
30213022
Node::BinExpr(_) => true,
30223023
Node::MemberExpr(expr) => !keep_member_expr_on_one_line(expr),

tests/specs/issues/issue0556.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
~~ lineWidth: 1000, indentWidth: 4, operatorPosition: sameLine ~~
2+
== should format same as the below ==
3+
// these should both format the same, regardless of whether there is an
4+
// optional chain or not at symbol.declarations?.map
5+
function getSymbolParentOrFail() {
6+
return `Declarations: ${
7+
symbol.declarations?.map(d => {
8+
return true;
9+
}).join(", ")
10+
}.`;
11+
}
12+
13+
[expect]
14+
// these should both format the same, regardless of whether there is an
15+
// optional chain or not at symbol.declarations?.map
16+
function getSymbolParentOrFail() {
17+
return `Declarations: ${
18+
symbol.declarations?.map(d => {
19+
return true;
20+
}).join(", ")
21+
}.`;
22+
}
23+
24+
== should format this the same as the above ==
25+
function getSymbolParentOrFail() {
26+
return `Declarations: ${
27+
symbol.declarations.map(d => {
28+
return true;
29+
}).join(", ")
30+
}.`;
31+
}
32+
33+
[expect]
34+
function getSymbolParentOrFail() {
35+
return `Declarations: ${
36+
symbol.declarations.map(d => {
37+
return true;
38+
}).join(", ")
39+
}.`;
40+
}

0 commit comments

Comments
 (0)