Skip to content

Commit a53592d

Browse files
authored
fix: ensure no trailing space after colon token in conditional type (#522)
1 parent 8d28e40 commit a53592d

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/generation/generate.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5332,7 +5332,8 @@ fn gen_conditional_type<'a>(node: &'a TsConditionalType, context: &mut Context<'
53325332
let mut items = PrintItems::new();
53335333
items.extend(question_comment_items.leading_line);
53345334
if question_position == OperatorPosition::NextLine {
5335-
items.push_str("? ");
5335+
items.push_str("?");
5336+
items.push_signal(Signal::SpaceIfNotTrailing);
53365337
}
53375338
items.extend(ir_helpers::new_line_group(gen_node(node.true_type.into(), context)));
53385339
if colon_position == OperatorPosition::SameLine {
@@ -5375,7 +5376,8 @@ fn gen_conditional_type<'a>(node: &'a TsConditionalType, context: &mut Context<'
53755376
items.push_info(before_false_ln);
53765377
items.extend(colon_comment_items.leading_line);
53775378
if colon_position == OperatorPosition::NextLine {
5378-
items.push_str(": ");
5379+
items.push_str(":");
5380+
items.push_signal(Signal::SpaceIfNotTrailing);
53795381
}
53805382
items.extend(ir_helpers::new_line_group(gen_node(node.false_type.into(), context)));
53815383
items

tests/specs/issues/issue0516.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
~~ indentWidth: 2 ~~
2+
== should not have trailing space ==
3+
type Type<T = any> = T extends never ? never
4+
:
5+
& { ephemeral?: T }
6+
& (
7+
| Object_Type
8+
| Union_Type
9+
| Intersection_Type
10+
| Enum_Member_Type
11+
| Generic_Type
12+
| Primitive
13+
| Enum_Type
14+
| Array_Type
15+
| Tuple_Type
16+
| Any_Type
17+
| Custom_Type
18+
)
19+
;
20+
21+
[expect]
22+
type Type<T = any> = T extends never ? never
23+
:
24+
& { ephemeral?: T }
25+
& (
26+
| Object_Type
27+
| Union_Type
28+
| Intersection_Type
29+
| Enum_Member_Type
30+
| Generic_Type
31+
| Primitive
32+
| Enum_Type
33+
| Array_Type
34+
| Tuple_Type
35+
| Any_Type
36+
| Custom_Type
37+
);

0 commit comments

Comments
 (0)