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

feat: Support extends constraints on infer type #4018

Merged
Merged
36 changes: 28 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.

9 changes: 8 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.

76 changes: 38 additions & 38 deletions crates/rome_js_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8065,6 +8065,44 @@ impl IntoFormat<JsFormatContext> for rome_js_syntax::TsTypeParameterName {
)
}
}
impl FormatRule<rome_js_syntax::TsTypeConstraintClause>
for crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause
{
type Context = JsFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &rome_js_syntax::TsTypeConstraintClause,
f: &mut JsFormatter,
) -> FormatResult<()> {
FormatNodeRule::<rome_js_syntax::TsTypeConstraintClause>::fmt(self, node, f)
}
}
impl AsFormat<JsFormatContext> for rome_js_syntax::TsTypeConstraintClause {
type Format<'a> = FormatRefWithRule<
'a,
rome_js_syntax::TsTypeConstraintClause,
crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause::default(),
)
}
}
impl IntoFormat<JsFormatContext> for rome_js_syntax::TsTypeConstraintClause {
type Format = FormatOwnedWithRule<
rome_js_syntax::TsTypeConstraintClause,
crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause::default(),
)
}
}
impl FormatRule<rome_js_syntax::TsPredicateReturnType>
for crate::ts::types::predicate_return_type::FormatTsPredicateReturnType
{
Expand Down Expand Up @@ -8213,44 +8251,6 @@ impl IntoFormat<JsFormatContext> for rome_js_syntax::TsTypeParameter {
)
}
}
impl FormatRule<rome_js_syntax::TsTypeConstraintClause>
for crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause
{
type Context = JsFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &rome_js_syntax::TsTypeConstraintClause,
f: &mut JsFormatter,
) -> FormatResult<()> {
FormatNodeRule::<rome_js_syntax::TsTypeConstraintClause>::fmt(self, node, f)
}
}
impl AsFormat<JsFormatContext> for rome_js_syntax::TsTypeConstraintClause {
type Format<'a> = FormatRefWithRule<
'a,
rome_js_syntax::TsTypeConstraintClause,
crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause::default(),
)
}
}
impl IntoFormat<JsFormatContext> for rome_js_syntax::TsTypeConstraintClause {
type Format = FormatOwnedWithRule<
rome_js_syntax::TsTypeConstraintClause,
crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::ts::auxiliary::type_constraint_clause::FormatTsTypeConstraintClause::default(),
)
}
}
impl FormatRule<rome_js_syntax::TsDefaultTypeClause>
for crate::ts::auxiliary::default_type_clause::FormatTsDefaultTypeClause
{
Expand Down
19 changes: 17 additions & 2 deletions crates/rome_js_formatter/src/ts/types/infer_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,24 @@ impl FormatNodeRule<TsInferType> for FormatTsInferType {
fn fmt_fields(&self, node: &TsInferType, f: &mut JsFormatter) -> FormatResult<()> {
let TsInferTypeFields {
infer_token,
type_parameter,
name,
constraint,
} = node.as_fields();
write![f, [infer_token.format(), space(), type_parameter.format()]]

if constraint.is_none() {
write![f, [infer_token.format(), space(), name.format()]]
} else {
write![
f,
[
infer_token.format(),
space(),
name.format(),
space(),
constraint.format()
]
]
}
MichaReiser marked this conversation as resolved.
Show resolved Hide resolved
}

fn needs_parentheses(&self, item: &TsInferType) -> bool {
Expand Down

This file was deleted.

Loading