Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/codegen): Fix codegen of a negative number #5980

Merged
merged 9 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions crates/swc_ecma_codegen/tests/fixture/issue-5912/output.js
Original file line number Diff line number Diff line change
@@ -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;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.