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`.
This commit is contained in:
overlookmotel 2024-11-15 02:56:49 +00:00
parent 8da23692fc
commit 33ec4e6182

View file

@ -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();