@@ -262,6 +262,7 @@ fn parse_node_with_inner_parse<'a>(node: Node<'a>, context: &mut Context<'a>, in
262
262
Node::TsRestType(node) => parse_rest_type(node, context),
263
263
Node::TsThisType(_) => "this".into(),
264
264
Node::TsTupleType(node) => parse_tuple_type(node, context),
265
+ Node::TsTupleElement(node) => parse_tuple_element(node, context),
265
266
Node::TsTypeAnn(node) => parse_type_ann(node, context),
266
267
Node::TsTypeParam(node) => parse_type_param(node, context),
267
268
Node::TsTypeParamDecl(node) => parse_type_parameters(TypeParamNode::Decl(node), context),
@@ -271,7 +272,6 @@ fn parse_node_with_inner_parse<'a>(node: Node<'a>, context: &mut Context<'a>, in
271
272
Node::TsTypeQuery(node) => parse_type_query(node, context),
272
273
Node::TsTypeRef(node) => parse_type_reference(node, context),
273
274
Node::TsUnionType(node) => parse_union_type(node, context),
274
- Node::TsTupleElement(node) => parse_node((&node.ty).into(), context),
275
275
/* unknown */
276
276
_ => parse_raw_string(node.text(context).into()),
277
277
}
@@ -4069,6 +4069,17 @@ fn parse_tuple_type<'a>(node: &'a TsTupleType, context: &mut Context<'a>) -> Pri
4069
4069
}, context)
4070
4070
}
4071
4071
4072
+ fn parse_tuple_element<'a>(node: &'a TsTupleElement, context: &mut Context<'a>) -> PrintItems {
4073
+ if let Some(label) = &node.label {
4074
+ let mut items = PrintItems::new();
4075
+ items.extend(parse_node(label.into(), context));
4076
+ items.extend(parse_type_ann_with_colon_for_type(&node.ty, context));
4077
+ items
4078
+ } else {
4079
+ parse_node((&node.ty).into(), context)
4080
+ }
4081
+ }
4082
+
4072
4083
fn parse_type_ann<'a>(node: &'a TsTypeAnn, context: &mut Context<'a>) -> PrintItems {
4073
4084
parse_node((&node.type_ann).into(), context)
4074
4085
}
@@ -5055,18 +5066,24 @@ fn parse_node_with_semi_colon<'a>(value: Option<Node<'a>>, parsed_semi_colon: Pr
5055
5066
}
5056
5067
}
5057
5068
5058
- /// For some reason, some nodes don't have a TsTypeAnn, but instead of a Box<TsType>
5069
+ /// Some nodes don't have a TsTypeAnn, but instead a Box<TsType>
5059
5070
fn parse_type_ann_with_colon_if_exists_for_type<'a>(type_ann: &'a Option<Box<TsType>>, context: &mut Context<'a>) -> PrintItems {
5060
- let mut items = PrintItems::new();
5061
5071
if let Some(type_ann) = type_ann {
5062
- if context.config.type_annotation_space_before_colon {
5063
- items.push_str(" ");
5064
- }
5065
- let colon_token = context.token_finder.get_previous_token_if_colon(&**type_ann);
5066
- #[cfg(debug_assertions)]
5067
- assert_has_op(":", colon_token, context);
5068
- items.extend(parse_type_ann_with_colon(type_ann.into(), colon_token, context));
5072
+ parse_type_ann_with_colon_for_type(type_ann, context)
5073
+ } else {
5074
+ PrintItems::new()
5069
5075
}
5076
+ }
5077
+
5078
+ fn parse_type_ann_with_colon_for_type<'a>(type_ann: &'a TsType, context: &mut Context<'a>) -> PrintItems {
5079
+ let mut items = PrintItems::new();
5080
+ if context.config.type_annotation_space_before_colon {
5081
+ items.push_str(" ");
5082
+ }
5083
+ let colon_token = context.token_finder.get_previous_token_if_colon(type_ann);
5084
+ #[cfg(debug_assertions)]
5085
+ assert_has_op(":", colon_token, context);
5086
+ items.extend(parse_type_ann_with_colon(type_ann.into(), colon_token, context));
5070
5087
items
5071
5088
}
5072
5089
0 commit comments