Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(minifier): use to_js_string() instead of fs64::to_string (#6597)
  • Loading branch information
Boshen committed Oct 15, 2024
commit 16bea12f9c4f8f7e54d1b7274323b8a9395c3909
16 changes: 8 additions & 8 deletions crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use oxc_ecmascript::{
};
use oxc_span::{GetSpan, Span, SPAN};
use oxc_syntax::{
number::NumberBase,
number::{NumberBase, ToJsString},
operator::{BinaryOperator, LogicalOperator, UnaryOperator},
};
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
Expand Down Expand Up @@ -487,9 +487,9 @@ impl<'a, 'b> PeepholeFoldConstants {
{
return false;
}
let result_str = result.to_string().len();
let result_str = result.to_js_string().len();
let original_str =
left.to_string().len() + right.to_string().len() + length_of_operator;
left.to_js_string().len() + right.to_js_string().len() + length_of_operator;
result_str <= original_str
}
if !operation.operator.is_arithmetic() {
Expand Down Expand Up @@ -538,7 +538,7 @@ impl<'a, 'b> PeepholeFoldConstants {
Some(ctx.ast.expression_numeric_literal(
operation.span,
result,
result.to_string(),
result.to_js_string(),
number_base,
))
}
Expand Down Expand Up @@ -582,7 +582,7 @@ impl<'a, 'b> PeepholeFoldConstants {
_ => ctx.ast.expression_numeric_literal(
SPAN,
result,
result.to_string(),
result.to_js_string(),
if is_exact_int64(result) { NumberBase::Decimal } else { NumberBase::Float },
),
})
Expand Down Expand Up @@ -676,7 +676,7 @@ impl<'a, 'b> PeepholeFoldConstants {
let number_literal_expr = ctx.ast.expression_numeric_literal(
right_expr.span(),
num,
num.to_string(),
num.to_js_string(),
if num.fract() == 0.0 { NumberBase::Decimal } else { NumberBase::Float },
);

Expand All @@ -699,7 +699,7 @@ impl<'a, 'b> PeepholeFoldConstants {
let number_literal_expr = ctx.ast.expression_numeric_literal(
left_expr.span(),
num,
num.to_string(),
num.to_js_string(),
if num.fract() == 0.0 { NumberBase::Decimal } else { NumberBase::Float },
);

Expand Down Expand Up @@ -967,7 +967,7 @@ impl<'a, 'b> PeepholeFoldConstants {
return Some(ctx.ast.expression_numeric_literal(
span,
result_val,
result_val.to_string(),
result_val.to_js_string(),
NumberBase::Decimal,
));
}
Expand Down