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:
Donny/강동윤 2022-09-28 22:40:07 +09:00 committed by GitHub
parent a3d8e4c8bc
commit bc2c0f4133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 632 additions and 1 deletions

View File

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

View File

@ -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 }

View 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;
}

View 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