Skip to content

Commit

Permalink
fix: +ve part
Browse files Browse the repository at this point in the history
  • Loading branch information
imranbarbhuiya committed Jul 12, 2024
1 parent 4ce5fe1 commit f67918f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
25 changes: 7 additions & 18 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,15 +702,8 @@ where

self.emit_leading_comments_of_span(num.span(), false)?;

let mut striped_raw = None;
let mut value = String::default();

srcmap!(self, num, true);

if self.cfg.minify {

// Handle infinity
if num.value.is_infinite() {
if num.value.is_infinite() && !num.raw.is_some() {
if num.value.is_sign_negative() {
self.wr.write_str_lit(num.span, "-")?;
}
Expand All @@ -719,6 +712,12 @@ where
return Ok(false);
}

let mut striped_raw = None;
let mut value = String::default();

srcmap!(self, num, true);

if self.cfg.minify {
value = minify_number(num.value);
self.wr.write_str_lit(DUMMY_SP, &value)?;
} else {
Expand Down Expand Up @@ -755,16 +754,6 @@ where
}
}

// Handle infinity
if num.value.is_infinite() {
if num.value.is_sign_negative() {
self.wr.write_str_lit(num.span, "-")?;
}
self.wr.write_str_lit(num.span, "Infinity")?;

return Ok(false);
}

// fast return
if !detect_dot {
return Ok(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,12 @@ fn test_fold_arithmetic_infinity() {
fold("x = Infinity ** -2", "x = 0");
}

#[test]
fn test_fold_arithmetic_large_number() {
fold("x = -1e999", "x = -1e999");
fold("x = 1e999", "x = 1e999");
}

#[test]
fn test_fold_arithmetic_string_comp() {
fold("x = 10 - 20", "x = -10");
Expand Down

0 comments on commit f67918f

Please sign in to comment.