Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_parser): instantiation expressions #3152

Merged
merged 26 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
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 Sep 2, 2022
b5c0f29
chore: 🤖 add more type
IWANABETHATGUY Sep 2, 2022
28d0daf
chore: 🤖 finish parser
IWANABETHATGUY Sep 3, 2022
b8a4b89
chore: 🤖 update snapshot
IWANABETHATGUY Sep 3, 2022
4301c23
chore: 🤖 update snapshot
IWANABETHATGUY Sep 3, 2022
b4818b7
chore: 🤖 update snapshot
IWANABETHATGUY Sep 3, 2022
db31173
chore: 🤖 update snapshot
IWANABETHATGUY Sep 3, 2022
76fa9b2
chore: 🤖 update snapshot
IWANABETHATGUY Sep 3, 2022
ff7c729
chore: 🤖 update snapshot
IWANABETHATGUY Sep 3, 2022
2d96604
chore: 🤖 udpate snapshot
IWANABETHATGUY Sep 3, 2022
c4ceae4
test: 💍 new operator
IWANABETHATGUY Sep 3, 2022
6a6f46a
test: 💍 update test snapshot
IWANABETHATGUY Sep 3, 2022
5817eb9
feat: 🎸 js format
IWANABETHATGUY Sep 4, 2022
9818ceb
fix: 🐛 lint
IWANABETHATGUY Sep 4, 2022
706466a
chore: 🤖 lint
IWANABETHATGUY Sep 4, 2022
2184ba1
chore: 🤖 fmt
IWANABETHATGUY Sep 4, 2022
e9acc5b
chore: 🤖 clean up
IWANABETHATGUY Sep 8, 2022
a1a4196
fix: 🐛 change expected_node to expected_token
IWANABETHATGUY Sep 10, 2022
4ce75ae
chore: 🤖 cr issues
IWANABETHATGUY Sep 10, 2022
10b49e5
chore: 🤖 rename ExpressionWithArguments to TsInstantiationExpr
IWANABETHATGUY Sep 10, 2022
013532e
fix: 🐛 cr issues
IWANABETHATGUY Sep 10, 2022
08f01a4
feat: 🎸 checkpoint
IWANABETHATGUY Sep 11, 2022
3508048
feat: 🎸 more strict constraint
IWANABETHATGUY Sep 12, 2022
2645de4
chore: 🤖 fmt
IWANABETHATGUY Sep 12, 2022
daf8695
chore: 🤖 compile error
IWANABETHATGUY Sep 12, 2022
487ba17
fix: 🐛 remove lefthandsideexpression
IWANABETHATGUY Sep 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions crates/rome_js_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion crates/rome_js_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions crates/rome_js_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2786,6 +2786,38 @@ impl IntoFormat<crate::JsFormatContext> for rome_js_syntax::TsNonNullAssertionEx
FormatOwnedWithRule :: new (self , crate :: ts :: expressions :: non_null_assertion_expression :: FormatTsNonNullAssertionExpression :: default ())
}
}
impl FormatRule<rome_js_syntax::TsInstantiationExpression>
for crate::ts::expressions::instantiation_expression::FormatTsInstantiationExpression
{
type Context = JsFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &rome_js_syntax::TsInstantiationExpression,
f: &mut JsFormatter,
) -> FormatResult<()> {
FormatNodeRule::<rome_js_syntax::TsInstantiationExpression>::fmt(self, node, f)
}
}
impl<'a> AsFormat<'a> for rome_js_syntax::TsInstantiationExpression {
type Format = FormatRefWithRule<
'a,
rome_js_syntax::TsInstantiationExpression,
crate::ts::expressions::instantiation_expression::FormatTsInstantiationExpression,
>;
fn format(&'a self) -> Self::Format {
FormatRefWithRule :: new (self , crate :: ts :: expressions :: instantiation_expression :: FormatTsInstantiationExpression :: default ())
}
}
impl IntoFormat<crate::JsFormatContext> for rome_js_syntax::TsInstantiationExpression {
type Format = FormatOwnedWithRule<
rome_js_syntax::TsInstantiationExpression,
crate::ts::expressions::instantiation_expression::FormatTsInstantiationExpression,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule :: new (self , crate :: ts :: expressions :: instantiation_expression :: FormatTsInstantiationExpression :: default ())
}
}
impl FormatRule<rome_js_syntax::JsxTagExpression>
for crate::jsx::expressions::tag_expression::FormatJsxTagExpression
{
Expand Down
1 change: 1 addition & 0 deletions crates/rome_js_formatter/src/js/any/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl FormatRule<JsAnyExpression> for FormatJsAnyExpression {
JsAnyExpression::TsTypeAssertionExpression(node) => node.format().fmt(f),
JsAnyExpression::TsAsExpression(node) => node.format().fmt(f),
JsAnyExpression::TsNonNullAssertionExpression(node) => node.format().fmt(f),
JsAnyExpression::TsInstantiationExpression(node) => node.format().fmt(f),
JsAnyExpression::JsxTagExpression(node) => node.format().fmt(f),
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/rome_js_formatter/src/parentheses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl NeedsParentheses for JsAnyExpression {
JsAnyExpression::TsTypeAssertionExpression(type_assertion) => {
type_assertion.needs_parentheses()
}
JsAnyExpression::TsInstantiationExpression(arguments) => arguments.needs_parentheses(),
}
}

Expand Down Expand Up @@ -252,6 +253,9 @@ impl NeedsParentheses for JsAnyExpression {
JsAnyExpression::TsTypeAssertionExpression(type_assertion) => {
type_assertion.needs_parentheses_with_parent(parent)
}
JsAnyExpression::TsInstantiationExpression(expr) => {
expr.needs_parentheses_with_parent(parent)
}
}
}
}
Expand Down
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)
Copy link
Contributor Author

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?

  1. 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 parse ExpressionWithTypeArguments https://github.dev/microsoft/TypeScript/blob/77374732df82c9d5c1319677dc595868bbc648b5/src/compiler/parser.ts#L7504-L7514.

  2. So I think the needs_parentheses_with_parent should be the same as JsPostUpdateExpression

    impl NeedsParentheses for JsPostUpdateExpression {
    fn needs_parentheses_with_parent(&self, parent: &JsSyntaxNode) -> bool {
    unary_like_expression_needs_parentheses(self.syntax(), parent)
    }
    }

}
}
1 change: 1 addition & 0 deletions crates/rome_js_formatter/src/ts/expressions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

pub(crate) mod as_expression;
pub(crate) mod instantiation_expression;
pub(crate) mod name_with_type_arguments;
pub(crate) mod non_null_assertion_expression;
pub(crate) mod template_chunk_element;
Expand Down
8 changes: 7 additions & 1 deletion crates/rome_js_formatter/src/ts/types/typeof_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ pub struct FormatTsTypeofType;
impl FormatNodeRule<TsTypeofType> for FormatTsTypeofType {
fn fmt_fields(&self, node: &TsTypeofType, f: &mut JsFormatter) -> FormatResult<()> {
let TsTypeofTypeFields {
type_arguments,
typeof_token,
expression_name,
} = node.as_fields();

write![
f,
[typeof_token.format(), space(), expression_name.format()]
[
typeof_token.format(),
space(),
expression_name.format(),
IWANABETHATGUY marked this conversation as resolved.
Show resolved Hide resolved
type_arguments.format()
]
]
}

Expand Down

This file was deleted.

This file was deleted.

Loading