This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 659
feat(rome_js_parser): instantiation expressions #3152
Merged
MichaReiser
merged 26 commits into
rome:main
from
IWANABETHATGUY:feat/instantiation_expressions
Sep 13, 2022
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
3a40752
feat: 🎸 finish type of type
IWANABETHATGUY b5c0f29
chore: 🤖 add more type
IWANABETHATGUY 28d0daf
chore: 🤖 finish parser
IWANABETHATGUY b8a4b89
chore: 🤖 update snapshot
IWANABETHATGUY 4301c23
chore: 🤖 update snapshot
IWANABETHATGUY b4818b7
chore: 🤖 update snapshot
IWANABETHATGUY db31173
chore: 🤖 update snapshot
IWANABETHATGUY 76fa9b2
chore: 🤖 update snapshot
IWANABETHATGUY ff7c729
chore: 🤖 update snapshot
IWANABETHATGUY 2d96604
chore: 🤖 udpate snapshot
IWANABETHATGUY c4ceae4
test: 💍 new operator
IWANABETHATGUY 6a6f46a
test: 💍 update test snapshot
IWANABETHATGUY 5817eb9
feat: 🎸 js format
IWANABETHATGUY 9818ceb
fix: 🐛 lint
IWANABETHATGUY 706466a
chore: 🤖 lint
IWANABETHATGUY 2184ba1
chore: 🤖 fmt
IWANABETHATGUY e9acc5b
chore: 🤖 clean up
IWANABETHATGUY a1a4196
fix: 🐛 change expected_node to expected_token
IWANABETHATGUY 4ce75ae
chore: 🤖 cr issues
IWANABETHATGUY 10b49e5
chore: 🤖 rename ExpressionWithArguments to TsInstantiationExpr
IWANABETHATGUY 013532e
fix: 🐛 cr issues
IWANABETHATGUY 08f01a4
feat: 🎸 checkpoint
IWANABETHATGUY 3508048
feat: 🎸 more strict constraint
IWANABETHATGUY 2645de4
chore: 🤖 fmt
IWANABETHATGUY daf8695
chore: 🤖 compile error
IWANABETHATGUY 487ba17
fix: 🐛 remove lefthandsideexpression
IWANABETHATGUY File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
28 changes: 28 additions & 0 deletions
28
crates/rome_js_formatter/src/ts/expressions/instantiation_expression.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::{ | ||
parentheses::{unary_like_expression_needs_parentheses, NeedsParentheses}, | ||
prelude::*, | ||
}; | ||
use rome_formatter::write; | ||
use rome_js_syntax::{TsInstantiationExpression, TsInstantiationExpressionFields}; | ||
#[derive(Debug, Clone, Default)] | ||
pub struct FormatTsInstantiationExpression; | ||
impl FormatNodeRule<TsInstantiationExpression> for FormatTsInstantiationExpression { | ||
fn fmt_fields( | ||
&self, | ||
node: &TsInstantiationExpression, | ||
f: &mut JsFormatter, | ||
) -> FormatResult<()> { | ||
let TsInstantiationExpressionFields { | ||
expression, | ||
arguments, | ||
} = node.as_fields(); | ||
|
||
write![f, [expression.format(), arguments.format()]] | ||
} | ||
} | ||
|
||
impl NeedsParentheses for TsInstantiationExpression { | ||
fn needs_parentheses_with_parent(&self, parent: &rome_js_syntax::JsSyntaxNode) -> bool { | ||
unary_like_expression_needs_parentheses(self.syntax(), parent) | ||
} | ||
} |
This file contains 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
This file contains 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
43 changes: 0 additions & 43 deletions
43
...es/rome_js_formatter/tests/specs/prettier/typescript/instantiation-expression/new.ts.snap
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
...rome_js_formatter/tests/specs/prettier/typescript/instantiation-expression/typeof.ts.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Why I write the `needs_parenthesis_with_parent like this?
here is how typescript parse
PostUpdateExpression
https://github.dev/microsoft/TypeScript/blob/77374732df82c9d5c1319677dc595868bbc648b5/src/compiler/parser.ts#L5345-L5354, almost the same as how they parseExpressionWithTypeArguments
https://github.dev/microsoft/TypeScript/blob/77374732df82c9d5c1319677dc595868bbc648b5/src/compiler/parser.ts#L7504-L7514.So I think the
needs_parentheses_with_parent
should be the same asJsPostUpdateExpression
tools/crates/rome_js_formatter/src/js/expressions/post_update_expression.rs
Lines 26 to 30 in 1d9d7a0