esbuild gives comparison to -0 compiling firestore (original) (raw)

esbuild gives the following error compiling firestore:

node_modules/@firebase/firestore/dist/index.cjs.js:718:11: warning: Comparison with -0 using the === operator will also match 0
    return -0 === t && 1 / t == -1 / 0;

Technically both 0 and -0 work the same with === operator. The esbuild warning seems reasonable in general. Can we change the -0 to a 0? In some ways that's also more clear since -0 indicates that it needs to be -0 for the code to work.

Looks like this was added in 4f1f303, which points to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is, which does not use -0.

So the proposal is to change the current code:

export function isNegativeZero(value: number) : boolean {
  return value === -0 && 1 / value === 1 / -0;
}

To the following:

export function isNegativeZero(value: number) : boolean {
  return value === 0 && 1 / value === 1 / -0;
}