-
Notifications
You must be signed in to change notification settings - Fork 664
Fix(rome_js_formatter):🐛 fix parenthesis expression bad case #2564
Fix(rome_js_formatter):🐛 fix parenthesis expression bad case #2564
Conversation
I believe this fix is too specific to member expressions. What about computed member assignments? Or any other place where expressions can appear. This is prettier's rule for formatting string literal expressions The way I understand this is that:
This should simplify the logic a bit. |
Addressed that issue. |
@@ -3,6 +3,4 @@ nock(/test/) | |||
[httpMethodNock(method)]('/foo') | |||
.reply(200, { | |||
foo: 'bar', | |||
}); | |||
|
|||
a[("test")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove this, due to this case has been added in another test file.
!bench_formatter |
Formatter Benchmark Results
|
// if expression is a StringLiteralExpression, we could not just return false, here is once case: | ||
// ```js | ||
// a[("test")] | ||
// ``` | ||
// parent_precedence should be `High` due to the parenthesized_expression's parent is ComputedMemberExpression, | ||
// and node_precedence should be `Low` due to expression is StringLiteralExpression. | ||
// the parenthesis should be omitted. | ||
if parent_precedence > node_precedence | ||
&& !matches!( | ||
expression, | ||
JsAnyExpression::JsAnyLiteralExpression( | ||
JsAnyLiteralExpression::JsStringLiteralExpression(_) | ||
) | ||
) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The easiest is probably to handle StringLiteralExpressions
before this line because the precedence isn't relevant for string literals, so there's no point in computing the precedence first.
!bench_formatter |
Formatter Benchmark Results
|
Summary
Fix #2558
Test Plan
fix the bad case