Skip to content

Commit

Permalink
Suggest using Number.isNaN instead of isNaN (#2471)
Browse files Browse the repository at this point in the history
  • Loading branch information
kidonng committed Aug 15, 2022
1 parent 13587ce commit 5e085f5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/bundler/bundler_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4019,7 +4019,7 @@ delete-super.js: WARNING: Attempting to delete a property of "super" will throw
dup-case.js: WARNING: This case clause will never be evaluated because it duplicates an earlier case clause
dup-case.js: NOTE: The earlier case clause is here:
equals-nan.js: WARNING: Comparison with NaN using the "===" operator here is always false
NOTE: Floating-point equality is defined such that NaN is never equal to anything, so "x === NaN" always returns false. You need to use "isNaN(x)" instead to test for NaN.
NOTE: Floating-point equality is defined such that NaN is never equal to anything, so "x === NaN" always returns false. You need to use "Number.isNaN(x)" instead to test for NaN.
equals-neg-zero.js: WARNING: Comparison with -0 using the "===" operator will also match 0
NOTE: Floating-point equality is defined such that 0 and -0 are equal, so "x === -0" returns true for both 0 and -0. You need to use "Object.is(x, -0)" instead to test for -0.
equals-object.js: WARNING: Comparison using the "===" operator here is always false
Expand Down
2 changes: 1 addition & 1 deletion internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11135,7 +11135,7 @@ func (p *parser) warnAboutEqualityCheck(op string, value js_ast.Expr, afterOpLoc
}
p.log.AddIDWithNotes(logger.MsgID_JS_EqualsNaN, kind, &p.tracker, r, text,
[]logger.MsgData{{Text: "Floating-point equality is defined such that NaN is never equal to anything, so \"x === NaN\" always returns false. " +
"You need to use \"isNaN(x)\" instead to test for NaN."}})
"You need to use \"Number.isNaN(x)\" instead to test for NaN."}})
return true
}

Expand Down
2 changes: 1 addition & 1 deletion internal/js_parser/js_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2769,7 +2769,7 @@ func TestWarningEqualsNewObject(t *testing.T) {

func TestWarningEqualsNaN(t *testing.T) {
note := "NOTE: Floating-point equality is defined such that NaN is never equal to anything, so \"x === NaN\" always returns false. " +
"You need to use \"isNaN(x)\" instead to test for NaN.\n"
"You need to use \"Number.isNaN(x)\" instead to test for NaN.\n"

expectParseError(t, "x === NaN", "<stdin>: WARNING: Comparison with NaN using the \"===\" operator here is always false\n"+note)
expectParseError(t, "x !== NaN", "<stdin>: WARNING: Comparison with NaN using the \"!==\" operator here is always true\n"+note)
Expand Down

0 comments on commit 5e085f5

Please sign in to comment.