Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
🩹 Make === and !== a β†’ a β†’ bool
Browse files Browse the repository at this point in the history
a β†’ b β†’ bool doesn't make sense, because when a and b are different
types, `===` is a contradiction and `!==` a tautology.
  • Loading branch information
CharString committed Nov 14, 2023
1 parent cb064cf commit dacfea5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const defaultContext = makeContext({
// forcing === and !== isn't a eslint rule for nothing...
'==': forall([a, b], f(a, b, bool)),
'!=': forall([a, b], f(a, b, bool)),
'===': forall([a, b], f(a, b, bool)),
'!==': forall([a, b], f(a, b, bool)),
'===': forall([a], f(a, a, bool)),
'!==': forall([a], f(a, a, bool)),
'!': forall([a], f(a, bool)),
'!!': forall([a], f(a, bool)),
or: forall([a, b], f(a, b, bool)),
Expand Down
6 changes: 3 additions & 3 deletions test-d/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
[ {"==":[1,"1"]}, {}, true ],
[ {"==":[1,2]}, {}, false ],
[ {"===":[1,1]}, {}, true ],
[ {"===":[1,"1"]}, {}, false ],
[ {"===":[1,"1"]}, {}, false, "Number and String" ],
[ {"===":[1,2]}, {}, false ],
[ {"!=":[1,2]}, {}, true ],
[ {"!=":[1,1]}, {}, false ],
[ {"!=":[1,"1"]}, {}, false ],
[ {"!==":[1,2]}, {}, true ],
[ {"!==":[1,1]}, {}, false ],
[ {"!==":[1,"1"]}, {}, true ],
[ {"!==":[1,"1"]}, {}, true, "Number and String" ],
[ {">":[2,1]}, {}, true ],
[ {">":[1,1]}, {}, false ],
[ {">":[1,2]}, {}, false ],
Expand Down Expand Up @@ -156,7 +156,7 @@
[{"if":[ "0", "apple", "banana"]}, null, "apple"],

"You can cast a string to numeric with a unary + ",
[{"===":[0,"0"]}, null, false],
[{"===":[0,"0"]}, null, false, "Number and String" ],
[{"===":[0,{"+":"0"}]}, null, true],
[{"if":[ {"+":"0"}, "apple", "banana"]}, null, "banana"],
[{"if":[ {"+":"1"}, "apple", "banana"]}, null, "apple"],
Expand Down

0 comments on commit dacfea5

Please sign in to comment.