Skip to content

Commit 96ef15c

Browse files
committed
Represent equality as == and ===.
1 parent cda76d2 commit 96ef15c

37 files changed

+172
-151
lines changed

analysis/examples/larger-project/src/res_comments_table.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,8 @@ and walkExpr = (expr, t, comments) => {
12361236
":="
12371237
| "||"
12381238
| "&&"
1239-
| "="
12401239
| "=="
1240+
| "==="
12411241
| "<"
12421242
| ">"
12431243
| "!="

analysis/src/Xform.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ module IfThenElse = struct
9393
{
9494
pexp_desc =
9595
Pexp_ident
96-
{txt = Longident.Lident (("=" | "<>") as op)};
96+
{txt = Longident.Lident (("==" | "!=") as op)};
9797
};
9898
args = [(Nolabel, arg1); (Nolabel, arg2)];
9999
};
100100
},
101101
e1,
102102
Some e2 )
103103
when Loc.hasPos ~pos e.pexp_loc -> (
104-
let e1, e2 = if op = "=" then (e1, e2) else (e2, e1) in
104+
let e1, e2 = if op = "==" then (e1, e2) else (e2, e1) in
105105
let mkMatch ~arg ~pat =
106106
let cases =
107107
[

compiler/ml/ast_mapper_from0.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,19 @@ module E = struct
324324
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}}
325325
| ( Pexp_ident ({txt = Longident.Lident "!="} as lid),
326326
[(Nolabel, _); (Nolabel, _)] ) ->
327-
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!=="}}
327+
{
328+
e with
329+
pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!=="};
330+
}
331+
| ( Pexp_ident ({txt = Longident.Lident "="} as lid),
332+
[(Nolabel, _); (Nolabel, _)] ) ->
333+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "=="}}
334+
| ( Pexp_ident ({txt = Longident.Lident "=="} as lid),
335+
[(Nolabel, _); (Nolabel, _)] ) ->
336+
{
337+
e with
338+
pexp_desc = Pexp_ident {lid with txt = Longident.Lident "==="};
339+
}
328340
| _ -> e
329341
in
330342
let process_partial_app_attribute attrs =

compiler/ml/ast_mapper_to0.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ module E = struct
336336
| ( Pexp_ident ({txt = Longident.Lident "!=="} as lid),
337337
[(Nolabel, _); (Nolabel, _)] ) ->
338338
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}}
339+
| ( Pexp_ident ({txt = Longident.Lident "==="} as lid),
340+
[(Nolabel, _); (Nolabel, _)] ) ->
341+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "=="}}
342+
| ( Pexp_ident ({txt = Longident.Lident "=="} as lid),
343+
[(Nolabel, _); (Nolabel, _)] ) ->
344+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "="}}
339345
| _ -> e
340346
in
341347
let attrs =

compiler/ml/error_message_utils.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ let type_clash_context_from_function sexp sfunct =
204204
in
205205
match sfunct.Parsetree.pexp_desc with
206206
| Pexp_ident
207-
{txt = Lident ("=" | "==" | "<>" | "!=" | ">" | ">=" | "<" | "<=")} ->
207+
{txt = Lident ("==" | "===" | "!=" | "!==" | ">" | ">=" | "<" | "<=")} ->
208208
Some ComparisonOperator
209209
| Pexp_ident {txt = Lident "++"} -> Some StringConcat
210210
| Pexp_ident {txt = Lident (("/." | "*." | "+." | "-.") as operator)} ->

compiler/syntax/src/res_comments_table.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ and walk_expression expr t comments =
13381338
{
13391339
txt =
13401340
Longident.Lident
1341-
( ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!="
1341+
( ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!="
13421342
| "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-."
13431343
| "++" | "^" | "*" | "*." | "/" | "/." | "**" | "->"
13441344
| "<>" );

compiler/syntax/src/res_core.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,6 @@ let make_infix_operator (p : Parser.t) token start_pos end_pos =
396396
Parser.err ~start_pos ~end_pos p
397397
(Diagnostics.message "Did you mean `==` here?");
398398
"=")
399-
else if token = Token.EqualEqual then "="
400-
else if token = Token.EqualEqualEqual then "=="
401399
else Token.to_string token
402400
in
403401
let loc = mk_loc start_pos end_pos in

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ let operator_precedence operator =
270270
| ":=" -> 1
271271
| "||" -> 2
272272
| "&&" -> 3
273-
| "=" | "==" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4
273+
| "==" | "===" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4
274274
| "+" | "+." | "-" | "-." | "++" -> 5
275275
| "*" | "*." | "/" | "/." | "%" -> 6
276276
| "**" -> 7
@@ -296,7 +296,7 @@ let is_unary_expression expr =
296296
(* TODO: tweak this to check for ghost ^ as template literal *)
297297
let is_binary_operator operator =
298298
match operator with
299-
| ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">="
299+
| ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!=" | "!==" | "<=" | ">="
300300
| "|>" | "+" | "+." | "-" | "-." | "++" | "*" | "*." | "/" | "/." | "**"
301301
| "->" | "<>" | "%" ->
302302
true
@@ -321,7 +321,7 @@ let is_binary_expression expr =
321321

322322
let is_equality_operator operator =
323323
match operator with
324-
| "=" | "==" | "!=" | "!==" -> true
324+
| "==" | "===" | "!=" | "!==" -> true
325325
| _ -> false
326326

327327
let is_rhs_binary_operator operator =

compiler/syntax/src/res_printer.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,12 +3662,6 @@ and print_unary_expression ~state expr cmt_tbl =
36623662

36633663
and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
36643664
let print_binary_operator ~inline_rhs operator =
3665-
let operator_txt =
3666-
match operator with
3667-
| "=" -> "=="
3668-
| "==" -> "==="
3669-
| txt -> txt
3670-
in
36713665
let spacing_before_operator =
36723666
if operator = "->" then Doc.soft_line
36733667
else if operator = "|>" then Doc.line
@@ -3680,7 +3674,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
36803674
else Doc.line
36813675
in
36823676
Doc.concat
3683-
[spacing_before_operator; Doc.text operator_txt; spacing_after_operator]
3677+
[spacing_before_operator; Doc.text operator; spacing_after_operator]
36843678
in
36853679
let print_operand ~is_lhs ~is_multiline expr parent_operator =
36863680
let rec flatten ~is_lhs ~is_multiline expr parent_operator =

runtime/Pervasives.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ external mod: ('a, 'a) => 'a = "%mod"
5555
/* Comparisons */
5656
/* Note: Later comparisons will be converted to unified operations too */
5757

58-
external \"=": ('a, 'a) => bool = "%equal"
58+
external \"==": ('a, 'a) => bool = "%equal"
5959
external \"!=": ('a, 'a) => bool = "%notequal"
6060
external \"<": ('a, 'a) => bool = "%lessthan"
6161
external \">": ('a, 'a) => bool = "%greaterthan"
@@ -64,7 +64,7 @@ external \">=": ('a, 'a) => bool = "%greaterequal"
6464
external compare: ('a, 'a) => int = "%compare"
6565
external min: ('a, 'a) => 'a = "%min"
6666
external max: ('a, 'a) => 'a = "%max"
67-
external \"==": ('a, 'a) => bool = "%eq"
67+
external \"===": ('a, 'a) => bool = "%eq"
6868
external \"!==": ('a, 'a) => bool = "%noteq"
6969

7070
/* Boolean operations */

runtime/Pervasives_mini.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ external mod: (int, int) => int = "%modint"
3434
/* Comparisons */
3535
/* Note: Later comparisons will be converted to unified operations too */
3636

37-
external \"=": ('a, 'a) => bool = "%equal"
37+
external \"==": ('a, 'a) => bool = "%equal"
3838
external \"!=": ('a, 'a) => bool = "%notequal"
3939
external \"<": ('a, 'a) => bool = "%lessthan"
4040
external \">": ('a, 'a) => bool = "%greaterthan"
@@ -43,7 +43,7 @@ external \">=": ('a, 'a) => bool = "%greaterequal"
4343
external compare: ('a, 'a) => int = "%compare"
4444
external min: ('a, 'a) => 'a = "%min"
4545
external max: ('a, 'a) => 'a = "%max"
46-
external \"==": ('a, 'a) => bool = "%eq"
46+
external \"===": ('a, 'a) => bool = "%eq"
4747
external \"!==": ('a, 'a) => bool = "%noteq"
4848

4949
/* Boolean operations */

tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ let findThreadByIdLinearScan [arity:2]~threads:((threads)[@res.namedArgLoc ])
7575
| Group { id } -> id
7676
| Unknown { id } ->
7777
(unknown.id -> Js.String.make) -> FBID.ofStringUnsafe in
78-
thisId == id)
78+
thisId === id)
7979
[@res.braces ])))
8080
[@res.braces ])
8181
let x = ((loop 0 (Nil -> (push doc)))[@res.braces ])

tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
let rightResource =
101101
(ur.resources).find
102-
(fun [arity:1]r -> r.account_id == ((connection.left).account).id)
102+
(fun [arity:1]r -> r.account_id === ((connection.left).account).id)
103103
let x = ((let field = p -> parseFieldDeclaration in field)[@res.braces ])
104104
let t = ((let (_, _, token) = scanner -> scan in token)[@res.braces ])
105105
let (keyTable : int Belt.Map.String.t) = [%rescript.exprhole ]

tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ let f [arity:4]~a:((a)[@res.namedArgLoc ][@attr ]) ((b)[@attrOnB ])
5252
let f [arity:1]list = list ()
5353
;;match colour with
5454
| Red when
55-
(l = l') ||
55+
(l == l') ||
5656
(Clflags.classic.contents &&
57-
((l = Nolabel) && (not (is_optional l'))))
57+
((l == Nolabel) && (not (is_optional l'))))
5858
-> (t1, t2)
5959
| _ -> ()
6060
let arr =

tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
;;node := (if newBalance == 2 then avl -> (rotateRight node) else node)
2-
;;node := ((if newBalance == 2 then avl -> (rotateRight node) else node)
1+
;;node := (if newBalance === 2 then avl -> (rotateRight node) else node)
2+
;;node := ((if newBalance === 2 then avl -> (rotateRight node) else node)
33
[@attr ])
44
let x = (match z with | _ -> false) z
55
let x = ((match z with | _ -> false)[@attr ]) z
@@ -13,7 +13,7 @@ let x = while condition do () done z
1313
let x = ((while condition do () done)[@attr ]) z
1414
let x = (a + (-1)) + (-2)
1515
let x = (a + (((-1))[@attr ])) + (((-2))[@attr ])
16-
let x = (a % a) = 0
16+
let x = (a % a) == 0
1717
let x = a - b
1818
let x = a -. b
1919
;;Constructor (a, b)

tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
;;if (color == Black) && ((sibling == None) || (parent == None)) then ()
1+
;;if (color === Black) && ((sibling === None) || (parent === None)) then ()
22
;;if
3-
((color == Black) && ((!==) color Red)) &&
4-
((sibling == None) || (parent == None))
3+
((color === Black) && ((!==) color Red)) &&
4+
((sibling === None) || (parent === None))
55
then ()
6-
;;match (color == Black) && ((sibling == None) || (parent == None)) with
6+
;;match (color === Black) && ((sibling === None) || (parent === None)) with
77
| _ -> ()
8-
;;match ((color == Black) && ((!==) color Red)) &&
9-
((sibling == None) || (parent == None))
8+
;;match ((color === Black) && ((!==) color Red)) &&
9+
((sibling === None) || (parent === None))
1010
with
1111
| _ -> ()
12-
;;try (color == Black) && ((sibling == None) || (parent == None))
12+
;;try (color === Black) && ((sibling === None) || (parent === None))
1313
with | _ -> ()
1414
;;try
15-
((color == Black) && (color == Red)) &&
16-
((sibling == None) || (parent == None))
15+
((color === Black) && (color === Red)) &&
16+
((sibling === None) || (parent === None))
1717
with | _ -> ()
18-
;;while (color == Black) && ((sibling == None) || (parent == None)) do ()
18+
;;while (color === Black) && ((sibling === None) || (parent === None)) do ()
1919
done
2020
;;while
21-
((color == Black) && (color == Red)) &&
22-
((sibling == None) || (parent == None))
21+
((color === Black) && (color === Red)) &&
22+
((sibling === None) || (parent === None))
2323
do () done
2424
;;((div
2525
~onClick:((fun [arity:1]event ->

tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ let res =
4040
[@res.braces ])
4141
let nestedLet = ((let _ = 1 in ())[@res.braces ])
4242
let nestedLet = ((let _ = 1 in 2)[@res.braces ])
43-
let init [arity:1]() = ((foo (1 == 1); [%assert 1 == 2])[@res.braces ])
44-
let init [arity:1]() = (([%assert 1 == 2]; foo (1 == 1); [%assert 1 == 2])
43+
let init [arity:1]() = ((foo (1 === 1); [%assert 1 === 2])[@res.braces ])
44+
let init [arity:1]() = (([%assert 1 === 2]; foo (1 === 1); [%assert 1 === 2])
4545
[@res.braces ])
4646
let f [arity:1]() = ((let x = 1 in fun [arity:1]_ -> ())[@res.braces ])
4747
let reifyStyle (type a) [arity:1](x : 'a) =
@@ -55,7 +55,7 @@ let reifyStyle (type a) [arity:1](x : 'a) =
5555
(({js|function(x,y) {return +(x instanceof y)}|js})
5656
[@res.template ])] : 'a -> constructor -> bool (a:2))
5757
end in
58-
((if (Js.typeof x) = {js|string|js}
58+
((if (Js.typeof x) == {js|string|js}
5959
then Obj.magic String
6060
else
6161
if Internal.instanceOf x Internal.canvasGradient
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
;;if foo then true else false
2-
;;if foo = 2 then let bar = 1 in let foo = 2 in bar + foo
2+
;;if foo == 2 then let bar = 1 in let foo = 2 in bar + foo
33
let ifThenElse = if foo then lala else doStuff x y z
44
let ifElseIfThen =
5-
if foo = bar
5+
if foo == bar
66
then f ()
7-
else if foo = bar2 then f1 () else if foo = bar3 then f2 () else f3 ()
7+
else if foo == bar2 then f1 () else if foo == bar3 then f2 () else f3 ()
88
let x = (if true then 1 else 2) + (if false then 2 else 3)

tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
;;{js|string1|js} ++ {js|string2|js}
33
;;a != b
44
;;(!==) a b
5-
;;a = b
6-
;;a == b
5+
;;a == b
6+
;;a === b

tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ let y =
159159
let pathFromState =
160160
Routes.stateToPath
161161
latestComponentBag.state in
162-
((if currentActualPath = pathFromState
162+
((if currentActualPath == pathFromState
163163
then None
164164
else
165165
dispatchEventless
@@ -220,7 +220,7 @@ let icon =
220220
[@JSX ])
221221
let _ =
222222
((MessengerSharedPhotosAlbumViewPhotoReact.createElement
223-
?ref:((if foo#bar == baz
223+
?ref:((if foo#bar === baz
224224
then Some (foooooooooooooooooooooooo setRefChild)
225225
else None)[@res.namedArgLoc ][@res.ternary ])
226226
~key:((node#legacy_attachment_id)[@res.namedArgLoc ]) ~children:[] ())

tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let incr [arity:1]~v:((v)[@res.namedArgLoc ]) = v + 1
99
let l1 = List.length (List.map (fun [arity:1]__x -> incr ~v:__x) [1; 2; 3])
1010
let l2 = List.length (List.map (fun [arity:1]__x -> incr ~v:__x) [1; 2; 3])
1111
let optParam [arity:2]?v:((v)[@res.namedArgLoc ]) () =
12-
((if v = None then 0 else 1)[@res.ternary ])
12+
((if v == None then 0 else 1)[@res.ternary ])
1313
let l1 =
1414
List.length
1515
(List.map (fun [arity:1]__x -> optParam ?v:__x ()) [Some 1; None; Some 2])

0 commit comments

Comments
 (0)