Skip to content

Commit

Permalink
fix(codegen): panic occurred when printing the comment of the right p…
Browse files Browse the repository at this point in the history
…arenthesis
  • Loading branch information
Dunqing committed Oct 15, 2024
1 parent 61dfd9a commit 65afbaa
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,13 +1383,15 @@ impl<'a> GenExpr for CallExpression<'a> {
type_parameters.print(p, ctx);
}
p.print_ascii_byte(b'(');
let has_comment = (self.span.end > 0 && p.has_comment(self.span.end - 1))
let has_comment_before_right_paren =
self.span.end > 0 && p.has_comment(self.span.end - 1);
let has_comment = has_comment_before_right_paren
|| self.arguments.iter().any(|item| p.has_comment(item.span().start));
if has_comment {
p.indent();
p.print_list_with_comments(&self.arguments, ctx);
// Handle `/* comment */);`
if !p.print_expr_comments(self.span.end - 1) {
if !has_comment_before_right_paren || !p.print_expr_comments(self.span.end - 1) {
p.print_soft_newline();
}
p.dedent();
Expand Down Expand Up @@ -1958,7 +1960,8 @@ impl<'a> GenExpr for SequenceExpression<'a> {
impl<'a> GenExpr for ImportExpression<'a> {
fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) {
let wrap = precedence >= Precedence::New || ctx.intersects(Context::FORBID_CALL);
let has_comment = (self.span.end > 0 && p.has_comment(self.span.end - 1))
let has_comment_before_right_paren = self.span.end > 0 && p.has_comment(self.span.end - 1);
let has_comment = has_comment_before_right_paren
|| p.has_comment(self.source.span().start)
|| self.arguments.first().is_some_and(|argument| p.has_comment(argument.span().start));

Expand Down

0 comments on commit 65afbaa

Please sign in to comment.