Skip to content

Commit 47c5388

Browse files
committed
fix(formatter): inconsistent CallExpression and NewExpression around member chain and logical expression
1 parent 98c89e5 commit 47c5388

File tree

7 files changed

+8
-14
lines changed

7 files changed

+8
-14
lines changed

crates/oxc_formatter/src/write/binary_like_expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ impl<'a, 'b> BinaryLikeExpression<'a, 'b> {
162162
parent.parent(),
163163
AstNodes::ReturnStatement(_)
164164
| AstNodes::ThrowStatement(_)
165-
// TODO(prettier): Why not include `NewExpression` ???
166165
| AstNodes::CallExpression(_)
166+
| AstNodes::NewExpression(_)
167167
| AstNodes::ImportExpression(_)
168168
| AstNodes::MetaProperty(_)
169169
),

crates/oxc_formatter/src/write/jsx/element.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl<'a> AnyJsxTagWithChildren<'a, '_> {
8282
AstNodes::CallExpression(call) if call.is_argument_span(self.span()) => {
8383
WrapState::NoWrap
8484
}
85+
AstNodes::NewExpression(new) if new.is_argument_span(self.span()) => WrapState::NoWrap,
8586
AstNodes::ExpressionStatement(stmt) => {
8687
// `() => <div></div>`
8788
// ^^^^^^^^^^^

crates/oxc_formatter/src/write/member_expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn layout<'a>(
150150
}
151151

152152
match first_non_static_member_ancestor {
153-
AstNodes::NewExpression(expr) if expr.is_argument_span(node.span()) => {
153+
AstNodes::NewExpression(expr) if expr.callee.span().contains_inclusive(node.span()) => {
154154
StaticMemberLayout::NoBreak
155155
}
156156
AstNodes::AssignmentExpression(assignment) => {

crates/oxc_formatter/tests/fixtures/js/logicals/indent.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ source: crates/oxc_formatter/tests/fixtures/mod.rs
1717
options.singleRun
1818
? "Infinity"
1919
: (options.cacheLifetime?.glob ??
20-
DEFAULT_TSCONFIG_CACHE_DURATION_SECONDS),
20+
DEFAULT_TSCONFIG_CACHE_DURATION_SECONDS),
2121
);
2222
}
2323

crates/oxc_formatter/tests/fixtures/ts/static-members/argument.ts.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ TelemetryTrustedValue(
2020
);
2121

2222
new TelemetryTrustedValue(
23-
instance.capabilities.get(
24-
TerminalCapability?.PromptTypeDetection,
25-
)?.promptType,
23+
instance.capabilities.get(TerminalCapability?.PromptTypeDetection)
24+
?.promptType,
2625
);
2726

2827
===================== End =====================

tasks/prettier_conformance/snapshots/prettier.js.snap.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
js compatibility: 707/758 (93.27%)
1+
js compatibility: 711/758 (93.80%)
22

33
# Failed
44

@@ -28,9 +28,6 @@ js compatibility: 707/758 (93.27%)
2828
| js/if/if_comments.js | 💥 | 76.00% |
2929
| js/if/trailing_comment.js | 💥 | 91.43% |
3030
| js/last-argument-expansion/dangling-comment-in-arrow-function.js | 💥 | 22.22% |
31-
| js/logical-assignment/inside-call/18171.js | 💥 | 90.20% |
32-
| js/method-chain/18171.js | 💥 | 82.76% |
33-
| js/new-expression/with-member-expression.js | 💥 | 73.91% |
3431
| js/object-multiline/multiline.js | 💥✨ | 22.22% |
3532
| js/quote-props/classes.js | 💥💥✨✨ | 47.06% |
3633
| js/quote-props/objects.js | 💥💥✨✨ | 45.10% |
@@ -52,6 +49,5 @@ js compatibility: 707/758 (93.27%)
5249
| jsx/fbt/test.js | 💥 | 84.06% |
5350
| jsx/ignore/spread.js | 💥 | 83.33% |
5451
| jsx/jsx/quotes.js | 💥💥💥💥 | 79.41% |
55-
| jsx/parentheses/argument.js | 💥 | 68.00% |
5652
| jsx/single-attribute-per-line/single-attribute-per-line.js | 💥✨ | 43.37% |
5753
| jsx/text-wrap/test.js | 💥 | 99.56% |

tasks/prettier_conformance/snapshots/prettier.ts.snap.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ts compatibility: 543/601 (90.35%)
1+
ts compatibility: 545/601 (90.68%)
22

33
# Failed
44

@@ -7,7 +7,6 @@ ts compatibility: 543/601 (90.35%)
77
| jsx/fbt/test.js | 💥 | 84.06% |
88
| jsx/ignore/spread.js | 💥 | 83.33% |
99
| jsx/jsx/quotes.js | 💥💥💥💥 | 79.41% |
10-
| jsx/parentheses/argument.js | 💥 | 68.00% |
1110
| jsx/single-attribute-per-line/single-attribute-per-line.js | 💥✨ | 43.37% |
1211
| jsx/text-wrap/test.js | 💥 | 99.56% |
1312
| typescript/arrow/comments.ts | 💥✨ | 44.44% |
@@ -50,7 +49,6 @@ ts compatibility: 543/601 (90.35%)
5049
| typescript/mapped-type/issue-11098.ts | 💥 | 97.03% |
5150
| typescript/mapped-type/break-mode/break-mode.ts | 💥 | 68.75% |
5251
| typescript/multiparser-css/issue-6259.ts | 💥 | 57.14% |
53-
| typescript/new/with-member-expression.ts | 💥 | 52.00% |
5452
| typescript/non-null/optional-chain.ts | 💥 | 72.22% |
5553
| typescript/object-multiline/multiline.ts | 💥✨ | 23.21% |
5654
| typescript/property-signature/consistent-with-flow/comments.ts | 💥 | 80.00% |

0 commit comments

Comments
 (0)