Skip to content

esbuild gives comparison to -0 compiling firestore #3814

Closed
@ojanvafai

Description

  • Operating System version: N/A
  • Browser version: N/A
  • Firebase SDK version: 7.16.0
  • Firebase Product: firestore

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions