From 059fd494a17ab9d79223b537f7fbbf3d1cd96ebd Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 15 Nov 2024 02:56:49 +0000 Subject: [PATCH] fix(codegen): fix arithmetic overflow printing unspanned `NewExpression` (#7289) `self.span.end - 1` overflows if the `NewExpression` is generated in transformer and has no span, so `self.span.end == 0`. --- crates/oxc_codegen/src/gen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 41c95d908fd593..3568417077daf9 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -2067,7 +2067,7 @@ impl<'a> GenExpr for NewExpression<'a> { p.print_str("new "); self.callee.print_expr(p, Precedence::New, Context::FORBID_CALL); p.print_ascii_byte(b'('); - let has_comment = p.has_comment(self.span.end - 1) + let has_comment = (!self.span.is_unspanned() && p.has_comment(self.span.end - 1)) || self.arguments.iter().any(|item| p.has_comment(item.span().start)); if has_comment { p.indent();