Conversation
ematipico
approved these changes
Nov 17, 2023
Member
ematipico
left a comment
There was a problem hiding this comment.
The fix looks good to me. Although could you try something? Try to commit the suggested fix with JsIdentifierExpression::needs_parentheses_with_parent, and bench the result. And then bench this solution. If there aren't big differences, we could use the needs_parentheses_with_parent solution, which is more idiomatic against our architecture.
Remember to add a comment to #739 once this is merged
Member
Author
|
!bench_formatter |
Contributor
Formatter Benchmark Results |
c08ea3f to
bb5f62b
Compare
Member
Author
|
Good news: we no longer diverge from prettier. This was addressed in prettier#15514. |
Member
Author
|
!bench_formatter |
bb5f62b to
c1626f5
Compare
Contributor
Formatter Benchmark Results |
Member
Author
|
!bench_formatter |
Contributor
Formatter Benchmark Results |
f7a7693 to
26b67cb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes the parse error for
typescript/as/expression-statement.ts.Unfortunately we have to diverge from prettier here. Thus, this does not improve the compatibility score. However, this should not make it worse.
The following code is valid in TypeScript:
Prettier and Biome currently format this code into an invalid code:
I added an edge case check in the formatting code of
asexpressions.It adds parens when the parent node is a statement and the expression is the identifier
type.Alternatively, this logic could be implemented in
JsIdnetifierExpression::needs_parentheses. However, tis could incur a perf regression because identifier expression are more common thanasexpressions.Test Plan
Updated tests.