Skip to content

Commit

Permalink
fix(codegen): fix arithmetic overflow printing unspanned `NewExpressi…
Browse files Browse the repository at this point in the history
…on` (#7289)

`self.span.end - 1` overflows if the `NewExpression` is generated in transformer and has no span, so `self.span.end == 0`.
  • Loading branch information
overlookmotel authored and Dunqing committed Nov 18, 2024
1 parent cb0aaa4 commit 059fd49
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 059fd49

Please sign in to comment.