Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 16 additions & 29 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3087,16 +3087,14 @@ impl Gen for TSTupleType<'_> {

impl Gen for TSUnionType<'_> {
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
if self.types.len() == 1 {
self.types[0].print(p, ctx);
let Some((first, rest)) = self.types.split_first() else {
return;
}
for (index, item) in self.types.iter().enumerate() {
if index != 0 {
p.print_soft_space();
p.print_str("|");
p.print_soft_space();
}
};
first.print(p, ctx);
for item in rest {
p.print_soft_space();
p.print_str("|");
p.print_soft_space();
item.print(p, ctx);
}
}
Expand All @@ -3112,16 +3110,14 @@ impl Gen for TSParenthesizedType<'_> {

impl Gen for TSIntersectionType<'_> {
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
if self.types.len() == 1 {
self.types[0].print(p, ctx);
let Some((first, rest)) = self.types.split_first() else {
return;
}
for (index, item) in self.types.iter().enumerate() {
if index != 0 {
p.print_soft_space();
p.print_str("&");
p.print_soft_space();
}
};
first.print(p, ctx);
for item in rest {
p.print_soft_space();
p.print_str("&");
p.print_soft_space();
item.print(p, ctx);
}
}
Expand Down Expand Up @@ -3219,17 +3215,8 @@ impl Gen for TSQualifiedName<'_> {

impl Gen for TSTypeOperator<'_> {
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
match self.operator {
TSTypeOperatorOperator::Keyof => {
p.print_str("keyof ");
}
TSTypeOperatorOperator::Unique => {
p.print_str("unique ");
}
TSTypeOperatorOperator::Readonly => {
p.print_str("readonly ");
}
}
p.print_str(self.operator.to_str());
p.print_hard_space();
self.type_annotation.print(p, ctx);
}
}
Expand Down
29 changes: 20 additions & 9 deletions crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,18 @@ impl<'a> Codegen<'a> {
}

fn print_list_with_comments(&mut self, items: &[Argument<'_>], ctx: Context) {
for (index, item) in items.iter().enumerate() {
if index != 0 {
self.print_comma();
}
let Some((first, rest)) = items.split_first() else {
return;
};
if self.print_expr_comments(first.span().start) {
self.print_indent();
} else {
self.print_soft_newline();
self.print_indent();
}
first.print(self, ctx);
for item in rest {
self.print_comma();
if self.print_expr_comments(item.span().start) {
self.print_indent();
} else {
Expand All @@ -483,12 +491,15 @@ impl<'a> Codegen<'a> {
}
}

#[inline]
fn print_expressions<T: GenExpr>(&mut self, items: &[T], precedence: Precedence, ctx: Context) {
for (index, item) in items.iter().enumerate() {
if index != 0 {
self.print_comma();
self.print_soft_space();
}
let Some((first, rest)) = items.split_first() else {
return;
};
first.print_expr(self, precedence, ctx);
for item in rest {
self.print_comma();
self.print_soft_space();
item.print_expr(self, precedence, ctx);
}
}
Expand Down
Loading