mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
fix(es/codegen): Fix codegen of a negative number (#5980)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/5912.
This commit is contained in:
parent
a3d8e4c8bc
commit
bc2c0f4133
@ -3652,7 +3652,11 @@ fn minify_number(num: f64) -> String {
|
||||
let mut original = printed.clone();
|
||||
|
||||
if num.fract() == 0.0 && (i64::MIN as f64) <= num && num <= (i64::MAX as f64) {
|
||||
let hex = format!("{:#x}", num as i64);
|
||||
let hex = format!(
|
||||
"{}{:#x}",
|
||||
if num.is_sign_negative() { "-" } else { "" },
|
||||
num as i64
|
||||
);
|
||||
|
||||
if hex.len() < printed.len() {
|
||||
printed = hex;
|
||||
|
@ -0,0 +1 @@
|
||||
function te(a) { var b, c, d, e, f; if (isNaN(a)) { return Qe(), Pe } if (a < -9223372036854775808) { return Qe(), Ne } if (a >= 9223372036854775807) { return Qe(), Me } e = false; if (a < 0) { e = true; a = -a } d = 0; if (a >= 17592186044416) { d = Bc(a / 17592186044416); a -= d * 17592186044416 } c = 0; if (a >= 4194304) { c = Bc(a / 4194304); a -= c * 4194304 } b = Bc(a); f = de(b, c, d); e && je(f); return f }
|
31
crates/swc_ecma_codegen/tests/fixture/issue-5912/output.js
Normal file
31
crates/swc_ecma_codegen/tests/fixture/issue-5912/output.js
Normal file
@ -0,0 +1,31 @@
|
||||
function te(a) {
|
||||
var b, c, d, e, f;
|
||||
if (isNaN(a)) {
|
||||
return Qe(), Pe;
|
||||
}
|
||||
if (a < -9223372036854775808) {
|
||||
return Qe(), Ne;
|
||||
}
|
||||
if (a >= 9223372036854775807) {
|
||||
return Qe(), Me;
|
||||
}
|
||||
e = false;
|
||||
if (a < 0) {
|
||||
e = true;
|
||||
a = -a;
|
||||
}
|
||||
d = 0;
|
||||
if (a >= 17592186044416) {
|
||||
d = Bc(a / 17592186044416);
|
||||
a -= d * 17592186044416;
|
||||
}
|
||||
c = 0;
|
||||
if (a >= 4194304) {
|
||||
c = Bc(a / 4194304);
|
||||
a -= c * 4194304;
|
||||
}
|
||||
b = Bc(a);
|
||||
f = de(b, c, d);
|
||||
e && je(f);
|
||||
return f;
|
||||
}
|
1
crates/swc_ecma_codegen/tests/fixture/issue-5912/output.min.js
vendored
Normal file
1
crates/swc_ecma_codegen/tests/fixture/issue-5912/output.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
function te(a){var b,c,d,e,f;if(isNaN(a)){return Qe(),Pe}if(a<-0x7fffffffffffffff){return Qe(),Ne}if(a>=0x7fffffffffffffff){return Qe(),Me}e=false;if(a<0){e=true;a=-a}d=0;if(a>=17592186044416){d=Bc(a/17592186044416);a-=d*17592186044416}c=0;if(a>=4194304){c=Bc(a/4194304);a-=c*4194304}b=Bc(a);f=de(b,c,d);e&&je(f);return f}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user