fix(es/ast): Fix EqIgnoreSpan impl of Number (#7112)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7111.
This commit is contained in:
Donny/강동윤 2023-03-21 17:46:22 +09:00 committed by GitHub
parent 39d47b8c62
commit 6a570a334c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 3 deletions

View File

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

View File

@ -0,0 +1 @@
console.log(Math.random() > 0.5 ? -0 : 0)

View File

@ -0,0 +1 @@
console.log(Math.random() > 0.5 ? -0 : 0);

View File

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