mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 20:28:58 +00:00
fix(codegen): panic occurred when printing the comment of the right parenthesis (#6593)
fix: https://github.com/oxc-project/monitor-oxc/actions/runs/11349185798/job/31564783192 It's hard to add a test for this because I haven't figured out caused by which plugin
This commit is contained in:
parent
e7c89a596b
commit
ba385fc9c1
1 changed files with 6 additions and 3 deletions
|
|
@ -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();
|
||||
|
|
@ -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));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue