rescript-compiler
rescript-compiler copied to clipboard
Add dict literal syntax
This PR adds basic support for the dict{}
literal syntax (https://github.com/rescript-lang/rescript-compiler/issues/6545).
Parsing
Semantics within the braces are similar to the record with string keys (as dict keys can be any string).
It then turns dict{"foo": "bar"}
into Js.Dict.fromArray([("foo", "bar")])
.
Printing
Any Js.Dict.fromArray
call that contains a literal array of tuples (with no spread) is now printed as dict{...}
.
I think this change is safe for the upcoming stdlib change (that'll move Js.Dict
into Dict
) as the change will be invisible once using this syntax. If that's something we don't want, we can add an attribute when parsing a dict{}
expression so that we only print those back and leave Js.Dict.fromArray
calls.