Skip to content

Commit 36308b8

Browse files
committed
fix(formatter): Fix indent for new expression with type cast (#16380)
Fixes #16346
1 parent c51a380 commit 36308b8

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

crates/oxc_formatter/src/write/as_or_satisfies_expression.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ fn is_callee_or_object_context(span: Span, parent: &AstNodes<'_>) -> bool {
8181
// Static member
8282
AstNodes::StaticMemberExpression(_) => true,
8383
AstNodes::ComputedMemberExpression(member) => member.object.span() == span,
84-
_ => parent.is_call_like_callee_span(span),
84+
// Or CallExpression callee (Not NewExpression, to align with Prettier)
85+
// https://github.com/prettier/prettier/blob/fdfa6701767f5140a85902ecc9fb6444f5b4e3f8/src/language-js/print/cast-expression.js#L28-L33
86+
// NOTE: We may revert this if resolved: https://github.com/prettier/prettier/issues/18406
87+
// _ => parent.is_call_like_callee_span(span),
88+
AstNodes::CallExpression(call) => call.callee.span() == span,
89+
_ => false,
8590
}
8691
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
new ((
2+
require('./webpack/plugins/next-trace-entrypoints-plugin')
3+
)
4+
.TraceEntryPointsPlugin as P)(
5+
{
6+
rootDir: dir,
7+
}
8+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
new ((
6+
require('./webpack/plugins/next-trace-entrypoints-plugin')
7+
)
8+
.TraceEntryPointsPlugin as P)(
9+
{
10+
rootDir: dir,
11+
}
12+
)
13+
14+
==================== Output ====================
15+
------------------
16+
{ printWidth: 80 }
17+
------------------
18+
new (require("./webpack/plugins/next-trace-entrypoints-plugin")
19+
.TraceEntryPointsPlugin as P)({
20+
rootDir: dir,
21+
});
22+
23+
-------------------
24+
{ printWidth: 100 }
25+
-------------------
26+
new (require("./webpack/plugins/next-trace-entrypoints-plugin").TraceEntryPointsPlugin as P)({
27+
rootDir: dir,
28+
});
29+
30+
===================== End =====================

0 commit comments

Comments
 (0)