Skip to content

Commit 4786ce8

Browse files
committed
fix(formatter): should not indent BinaryLikeExpression when its parent is NewExpression
1 parent 2144496 commit 4786ce8

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

crates/oxc_formatter/src/write/binary_like_expression.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,18 @@ impl<'a, 'b> BinaryLikeExpression<'a, 'b> {
165165
false
166166
}
167167
}
168-
AstNodes::ConditionalExpression(conditional) => !matches!(
169-
parent.parent(),
170-
AstNodes::ReturnStatement(_)
171-
| AstNodes::ThrowStatement(_)
172-
| AstNodes::CallExpression(_)
173-
| AstNodes::ImportExpression(_)
174-
| AstNodes::Argument(_)
175-
| AstNodes::MetaProperty(_)
176-
),
168+
AstNodes::ConditionalExpression(conditional) => {
169+
!matches!(
170+
parent.parent(),
171+
AstNodes::ReturnStatement(_)
172+
| AstNodes::ThrowStatement(_)
173+
| AstNodes::CallExpression(_)
174+
| AstNodes::ImportExpression(_)
175+
| AstNodes::MetaProperty(_)
176+
) &&
177+
// TODO(prettier): Why not include `NewExpression` ???
178+
!matches!(parent.parent(), AstNodes::Argument(argument) if matches!(argument.parent, AstNodes::CallExpression(_)))
179+
}
177180
_ => false,
178181
}
179182
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
RESOLUTION_CACHE = new ExpiringCache(
3+
options.singleRun
4+
? 'Infinity'
5+
: (options.cacheLifetime?.glob ??
6+
DEFAULT_TSCONFIG_CACHE_DURATION_SECONDS),
7+
);
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
{
6+
RESOLUTION_CACHE = new ExpiringCache(
7+
options.singleRun
8+
? 'Infinity'
9+
: (options.cacheLifetime?.glob ??
10+
DEFAULT_TSCONFIG_CACHE_DURATION_SECONDS),
11+
);
12+
}
13+
14+
==================== Output ====================
15+
{
16+
RESOLUTION_CACHE = new ExpiringCache(
17+
options.singleRun
18+
? "Infinity"
19+
: (options.cacheLifetime?.glob ??
20+
DEFAULT_TSCONFIG_CACHE_DURATION_SECONDS),
21+
);
22+
}
23+
24+
===================== End =====================

0 commit comments

Comments
 (0)