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
8 changes: 8 additions & 0 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ impl Gen for SwitchStatement<'_> {
impl Gen for SwitchCase<'_> {
fn r#gen(&self, p: &mut Codegen, ctx: Context) {
p.print_semicolon_if_needed();
p.print_comments_at(self.span.start);
p.print_indent();
p.add_source_mapping(self.span);
match &self.test {
Expand Down Expand Up @@ -1907,6 +1908,13 @@ impl GenExpr for ConditionalExpression<'_> {
p.print_soft_space();
p.print_colon();
p.print_soft_space();
if let Some(comments) = p.get_comments(self.alternate.span().start) {
p.print_comments(&comments);
if p.print_next_indent_as_space {
p.print_hard_space();
p.print_next_indent_as_space = false;
}
}
self.alternate.print_expr(p, Precedence::Yield, ctx & Context::FORBID_IN);
});
}
Expand Down
10 changes: 10 additions & 0 deletions crates/oxc_codegen/tests/integration/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ catch (err) /* c8 ignore next */ /* istanbul ignore next */ { handle(err); }",
"try { something(); }
catch (err) // v8 ignore next
{ handle(err); }",
// Coverage comment before ConditionalExpression alternate
// https://github.com/oxc-project/oxc/issues/20549
"const a = Math.random() ? 1 : /* istanbul ignore next */ 2;",
// Coverage comment between SwitchStatement cases
// https://github.com/oxc-project/oxc/issues/20549
"switch (Math.random()) {
case 0.5: break;
/* istanbul ignore next */
default: break;
}",
];

snapshot("coverage", &cases);
Expand Down
18 changes: 18 additions & 0 deletions crates/oxc_codegen/tests/integration/snapshots/coverage.snap
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,21 @@ try {
} catch (err) {
handle(err);
}

########## 23
const a = Math.random() ? 1 : /* istanbul ignore next */ 2;
----------
const a = Math.random() ? 1 : /* istanbul ignore next */ 2;

########## 24
switch (Math.random()) {
case 0.5: break;
/* istanbul ignore next */
default: break;
}
----------
switch (Math.random()) {
case .5: break;
/* istanbul ignore next */
default: break;
}
Loading