Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codegen): panic occurred when printing the comment of the right parenthesis #6593

Merged
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
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
Loading