Skip to content

Commit

Permalink
fix(es/ast): Fix EqIgnoreSpan impl of Number (#7112)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #7111.
  • Loading branch information
kdy1 authored Mar 21, 2023
1 parent 39d47b8 commit 6a570a3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/swc_ecma_ast/src/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl Eq for Number {}

impl EqIgnoreSpan for Number {
fn eq_ignore_span(&self, other: &Self) -> bool {
self.value == other.value
self.value == other.value && self.value.is_sign_positive() == other.value.is_sign_positive()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(Math.random() > 0.5 ? -0 : 0)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(Math.random() > 0.5 ? -0 : 0);
Original file line number Diff line number Diff line change
Expand Up @@ -7207,7 +7207,7 @@
if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);
(isModExp = !nIsNeg && x.isInteger() && m.isInteger()) && (x = x.mod(m));
} else {
if (n.e > 9 && (x.e > 0 || x.e < -1 || (0 == x.e ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) return x.s < 0 && isOdd(n), k = -0, x.e > -1 && (k = 1 / k), new BigNumber(nIsNeg ? 1 / k : k);
if (n.e > 9 && (x.e > 0 || x.e < -1 || (0 == x.e ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) return k = x.s < 0 && isOdd(n) ? -0 : 0, x.e > -1 && (k = 1 / k), new BigNumber(nIsNeg ? 1 / k : k);
POW_PRECISION && (k = mathceil(POW_PRECISION / LOG_BASE + 2));
}
for(nIsBig ? (half = new BigNumber(0.5), nIsNeg && (n.s = 1), nIsOdd = isOdd(n)) : nIsOdd = (i = Math.abs(+valueOf(n))) % 2, y = new BigNumber(ONE);;){
Expand Down Expand Up @@ -7258,7 +7258,7 @@
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
if (!xe || !ye) {
if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);
if (!xc[0] || !yc[0]) return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x : -0);
if (!xc[0] || !yc[0]) return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x : 3 == ROUNDING_MODE ? -0 : 0);
}
if (xe = bitFloor(xe), ye = bitFloor(ye), xc = xc.slice(), a = xe - ye) {
for((xLTy = a < 0) ? (a = -a, t = xc) : (ye = xe, t = yc), t.reverse(), b = a; b--; t.push(0));
Expand Down

1 comment on commit 6a570a3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 6a570a3 Previous: a4d1af1 Ratio
es/full/bugs-1 308982 ns/iter (± 12851) 303470 ns/iter (± 7193) 1.02
es/full/minify/libraries/antd 1509098988 ns/iter (± 25567382) 1651678293 ns/iter (± 17708860) 0.91
es/full/minify/libraries/d3 294821266 ns/iter (± 5355869) 304455719 ns/iter (± 5566221) 0.97
es/full/minify/libraries/echarts 1181272480 ns/iter (± 16933530) 1276663756 ns/iter (± 23267189) 0.93
es/full/minify/libraries/jquery 89468378 ns/iter (± 726133) 91174928 ns/iter (± 2275961) 0.98
es/full/minify/libraries/lodash 104893898 ns/iter (± 866355) 107189564 ns/iter (± 2280617) 0.98
es/full/minify/libraries/moment 51803015 ns/iter (± 368491) 53170144 ns/iter (± 562227) 0.97
es/full/minify/libraries/react 18962921 ns/iter (± 100587) 19208651 ns/iter (± 165308) 0.99
es/full/minify/libraries/terser 242798360 ns/iter (± 3768651) 248685741 ns/iter (± 4189138) 0.98
es/full/minify/libraries/three 425140826 ns/iter (± 4257261) 453847624 ns/iter (± 6749987) 0.94
es/full/minify/libraries/typescript 2912627912 ns/iter (± 30771190) 3100016773 ns/iter (± 23163296) 0.94
es/full/minify/libraries/victory 683560931 ns/iter (± 14845645) 681186427 ns/iter (± 18649532) 1.00
es/full/minify/libraries/vue 131228347 ns/iter (± 1389708) 130921131 ns/iter (± 1286261) 1.00
es/full/codegen/es3 26456 ns/iter (± 160) 26327 ns/iter (± 53) 1.00
es/full/codegen/es5 26549 ns/iter (± 66) 26360 ns/iter (± 43) 1.01
es/full/codegen/es2015 26548 ns/iter (± 58) 26416 ns/iter (± 63) 1.00
es/full/codegen/es2016 26552 ns/iter (± 57) 26396 ns/iter (± 57) 1.01
es/full/codegen/es2017 26601 ns/iter (± 66) 26409 ns/iter (± 44) 1.01
es/full/codegen/es2018 26538 ns/iter (± 67) 26390 ns/iter (± 35) 1.01
es/full/codegen/es2019 26564 ns/iter (± 52) 26373 ns/iter (± 52) 1.01
es/full/codegen/es2020 26499 ns/iter (± 49) 26393 ns/iter (± 38) 1.00
es/full/all/es3 181433356 ns/iter (± 2969983) 183354316 ns/iter (± 2415405) 0.99
es/full/all/es5 171471625 ns/iter (± 2132023) 175157074 ns/iter (± 1811542) 0.98
es/full/all/es2015 137861930 ns/iter (± 2289316) 139314325 ns/iter (± 1613877) 0.99
es/full/all/es2016 137970242 ns/iter (± 2539681) 135515728 ns/iter (± 2010467) 1.02
es/full/all/es2017 135433618 ns/iter (± 2008203) 135935049 ns/iter (± 1791912) 1.00
es/full/all/es2018 131660832 ns/iter (± 1267670) 130764930 ns/iter (± 2087137) 1.01
es/full/all/es2019 129949389 ns/iter (± 1412630) 129194438 ns/iter (± 1087271) 1.01
es/full/all/es2020 119447120 ns/iter (± 483312) 121040090 ns/iter (± 1432201) 0.99
es/full/parser 542644 ns/iter (± 9108) 540517 ns/iter (± 9713) 1.00
es/full/base/fixer 22533 ns/iter (± 40) 22591 ns/iter (± 44) 1.00
es/full/base/resolver_and_hygiene 84407 ns/iter (± 121) 85473 ns/iter (± 119) 0.99
serialization of ast node 124 ns/iter (± 0) 124 ns/iter (± 0) 1
serialization of serde 126 ns/iter (± 0) 126 ns/iter (± 0) 1
css/minify/libraries/bootstrap 28418358 ns/iter (± 76067) 28804225 ns/iter (± 87483) 0.99
css/visitor/compare/clone 2088777 ns/iter (± 9923) 2101206 ns/iter (± 12009) 0.99
css/visitor/compare/visit_mut_span 2268514 ns/iter (± 7379) 2292566 ns/iter (± 3754) 0.99
css/visitor/compare/visit_mut_span_panic 2325539 ns/iter (± 8703) 2302371 ns/iter (± 2175) 1.01
css/visitor/compare/fold_span 3061889 ns/iter (± 11607) 3040279 ns/iter (± 16611) 1.01
css/visitor/compare/fold_span_panic 3196808 ns/iter (± 20648) 3204036 ns/iter (± 23862) 1.00
css/lexer/bootstrap_5_1_3 5139514 ns/iter (± 4668) 5131055 ns/iter (± 11448) 1.00
css/lexer/foundation_6_7_4 4333283 ns/iter (± 1587) 4320450 ns/iter (± 14963) 1.00
css/lexer/tailwind_3_1_1 825109 ns/iter (± 425) 821026 ns/iter (± 492) 1.00
css/parser/bootstrap_5_1_3 21950704 ns/iter (± 149116) 21843531 ns/iter (± 115526) 1.00
css/parser/foundation_6_7_4 17454411 ns/iter (± 40045) 17412023 ns/iter (± 22693) 1.00
css/parser/tailwind_3_1_1 3345885 ns/iter (± 2571) 3348339 ns/iter (± 6056) 1.00
es/codegen/colors 329518 ns/iter (± 184413) 329658 ns/iter (± 183715) 1.00
es/codegen/large 1190449 ns/iter (± 604595) 1193593 ns/iter (± 604405) 1.00
es/codegen/with-parser/colors 47267 ns/iter (± 446) 47532 ns/iter (± 437) 0.99
es/codegen/with-parser/large 521409 ns/iter (± 1474) 521742 ns/iter (± 1152) 1.00
es/minify/libraries/antd 1333879542 ns/iter (± 14865708) 1426137462 ns/iter (± 24055059) 0.94
es/minify/libraries/d3 250736353 ns/iter (± 3372939) 260591790 ns/iter (± 3304212) 0.96
es/minify/libraries/echarts 1018615982 ns/iter (± 12491511) 1092178823 ns/iter (± 16396280) 0.93
es/minify/libraries/jquery 78532730 ns/iter (± 536246) 78867356 ns/iter (± 637884) 1.00
es/minify/libraries/lodash 94305656 ns/iter (± 963257) 94413206 ns/iter (± 845936) 1.00
es/minify/libraries/moment 45544433 ns/iter (± 122054) 45723214 ns/iter (± 435743) 1.00
es/minify/libraries/react 17217494 ns/iter (± 48988) 16917448 ns/iter (± 190000) 1.02
es/minify/libraries/terser 208738118 ns/iter (± 3604953) 208926719 ns/iter (± 1130193) 1.00
es/minify/libraries/three 365137158 ns/iter (± 5836696) 368643411 ns/iter (± 7785964) 0.99
es/minify/libraries/typescript 2477268237 ns/iter (± 8521738) 2634168675 ns/iter (± 19754652) 0.94
es/minify/libraries/victory 547371254 ns/iter (± 7276105) 576422673 ns/iter (± 12893103) 0.95
es/minify/libraries/vue 114780651 ns/iter (± 289658) 117490176 ns/iter (± 694122) 0.98
es/visitor/compare/clone 2362603 ns/iter (± 13331) 2345776 ns/iter (± 14710) 1.01
es/visitor/compare/visit_mut_span 2709230 ns/iter (± 6134) 2744266 ns/iter (± 3773) 0.99
es/visitor/compare/visit_mut_span_panic 2771317 ns/iter (± 4641) 2780619 ns/iter (± 9398) 1.00
es/visitor/compare/fold_span 3837625 ns/iter (± 9880) 3816961 ns/iter (± 5322) 1.01
es/visitor/compare/fold_span_panic 3987201 ns/iter (± 10023) 3995145 ns/iter (± 6340) 1.00
es/lexer/colors 15239 ns/iter (± 21) 15261 ns/iter (± 17) 1.00
es/lexer/angular 7359666 ns/iter (± 8350) 7364338 ns/iter (± 4944) 1.00
es/lexer/backbone 978509 ns/iter (± 1097) 979975 ns/iter (± 1196) 1.00
es/lexer/jquery 5518811 ns/iter (± 4901) 5531690 ns/iter (± 8120) 1.00
es/lexer/jquery mobile 8479325 ns/iter (± 8672) 8467388 ns/iter (± 6607) 1.00
es/lexer/mootools 4374775 ns/iter (± 2214) 4369780 ns/iter (± 6518) 1.00
es/lexer/underscore 822997 ns/iter (± 721) 824950 ns/iter (± 422) 1.00
es/lexer/three 25960000 ns/iter (± 40295) 25924683 ns/iter (± 25646) 1.00
es/lexer/yui 4633345 ns/iter (± 5076) 4626997 ns/iter (± 2680) 1.00
es/parser/colors 29732 ns/iter (± 54) 29984 ns/iter (± 31) 0.99
es/parser/angular 15415791 ns/iter (± 77406) 15488282 ns/iter (± 141098) 1.00
es/parser/backbone 2219253 ns/iter (± 13338) 2224081 ns/iter (± 12734) 1.00
es/parser/jquery 12111120 ns/iter (± 100486) 12098025 ns/iter (± 110914) 1.00
es/parser/jquery mobile 19203993 ns/iter (± 246610) 19268258 ns/iter (± 182229) 1.00
es/parser/mootools 9188542 ns/iter (± 35505) 9204671 ns/iter (± 25894) 1.00
es/parser/underscore 1882099 ns/iter (± 12195) 1881896 ns/iter (± 10391) 1.00
es/parser/three 55451040 ns/iter (± 526086) 56580771 ns/iter (± 856708) 0.98
es/parser/yui 9377345 ns/iter (± 62335) 9388140 ns/iter (± 82584) 1.00
es/preset-env/usage/builtin_type 136860 ns/iter (± 31400) 139378 ns/iter (± 32587) 0.98
es/preset-env/usage/property 21199 ns/iter (± 58) 21271 ns/iter (± 82) 1.00
es/resolver/typescript 114726059 ns/iter (± 3590714) 122735175 ns/iter (± 2436488) 0.93
es/fixer/typescript 80167471 ns/iter (± 1678748) 88136132 ns/iter (± 1623675) 0.91
es/hygiene/typescript 168247587 ns/iter (± 2571792) 180775018 ns/iter (± 1790740) 0.93
es/resolver_with_hygiene/typescript 307901607 ns/iter (± 3453971) 327949430 ns/iter (± 3727742) 0.94
es/visitor/base-perf/module_clone 79558 ns/iter (± 991) 79142 ns/iter (± 1234) 1.01
es/visitor/base-perf/fold_empty 88624 ns/iter (± 1273) 90654 ns/iter (± 1048) 0.98
es/visitor/base-perf/fold_noop_impl_all 88983 ns/iter (± 1592) 90560 ns/iter (± 1368) 0.98
es/visitor/base-perf/fold_noop_impl_vec 88866 ns/iter (± 1537) 91501 ns/iter (± 1398) 0.97
es/visitor/base-perf/boxing_boxed_clone 57 ns/iter (± 0) 57 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed_clone 54 ns/iter (± 0) 54 ns/iter (± 0) 1
es/visitor/base-perf/boxing_boxed 103 ns/iter (± 0) 103 ns/iter (± 0) 1
es/visitor/base-perf/boxing_unboxed 99 ns/iter (± 0) 106 ns/iter (± 0) 0.93
es/visitor/base-perf/visit_contains_this 3559 ns/iter (± 73) 3481 ns/iter (± 55) 1.02
es/base/parallel/resolver/typescript 6721382406 ns/iter (± 350507822) 6289909444 ns/iter (± 231840345) 1.07
es/base/parallel/hygiene/typescript 1955853526 ns/iter (± 25296552) 2155693156 ns/iter (± 22523292) 0.91
misc/visitors/time-complexity/time 5 100 ns/iter (± 0) 100 ns/iter (± 0) 1
misc/visitors/time-complexity/time 10 345 ns/iter (± 3) 365 ns/iter (± 8) 0.95
misc/visitors/time-complexity/time 15 673 ns/iter (± 3) 694 ns/iter (± 0) 0.97
misc/visitors/time-complexity/time 20 1257 ns/iter (± 15) 1281 ns/iter (± 1) 0.98
misc/visitors/time-complexity/time 40 6747 ns/iter (± 26) 6773 ns/iter (± 4) 1.00
misc/visitors/time-complexity/time 60 17270 ns/iter (± 36) 17300 ns/iter (± 45) 1.00
es/full-target/es2016 251480 ns/iter (± 335) 250388 ns/iter (± 494) 1.00
es/full-target/es2017 243568 ns/iter (± 515) 242846 ns/iter (± 323) 1.00
es/full-target/es2018 232618 ns/iter (± 417) 231904 ns/iter (± 380) 1.00
es2020_nullish_coalescing 91633 ns/iter (± 312) 92124 ns/iter (± 239) 0.99
es2020_optional_chaining 124383 ns/iter (± 526) 124895 ns/iter (± 518) 1.00
es2022_class_properties 147389 ns/iter (± 456) 147585 ns/iter (± 313) 1.00
es2018_object_rest_spread 95545 ns/iter (± 170) 95578 ns/iter (± 240) 1.00
es2019_optional_catch_binding 84734 ns/iter (± 221) 85158 ns/iter (± 150) 1.00
es2017_async_to_generator 85535 ns/iter (± 148) 85793 ns/iter (± 204) 1.00
es2016_exponentiation 89550 ns/iter (± 202) 87724 ns/iter (± 245) 1.02
es2015_arrow 93811 ns/iter (± 225) 91786 ns/iter (± 228) 1.02
es2015_block_scoped_fn 91375 ns/iter (± 284) 90202 ns/iter (± 308) 1.01
es2015_block_scoping 169146 ns/iter (± 486) 165246 ns/iter (± 295) 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.