-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dict literal syntax #6774
Add dict literal syntax #6774
Conversation
ff91945
to
9f5c415
Compare
Can you add a changelog entry? |
Could you remove the unrelated changes in belt_HashSetString.resi and belt_HashSetInt.resi? |
An attribute somehow might actually be beneficial for the editor tooling, if we want to do typed completion for values for instance. |
@zth aren't the rules the same as |
I'm also curious for the use case of the editor tooling =D Wouldn't we want to upgrade codebases automatically through the formatter? |
Just noting #6617 supports spread syntax if you want to vendor anything across. |
@bloodyowl What's the status of this PR? Would be great to get this feature merged! |
Yes, I agree. This would be a cool feature to have. |
(Ast_helper.Exp.ident ~loc | ||
(Location.mkloc | ||
(Longident.Ldot | ||
(Longident.Ldot (Longident.Lident "Js", "Dict"), "fromArray")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but this can be done independently later.
@zth Rebased |
This PR adds basic support for the
dict{}
literal syntax (#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"}
intoJs.Dict.fromArray([("foo", "bar")])
.Printing
Any
Js.Dict.fromArray
call that contains a literal array of tuples (with no spread) is now printed asdict{...}
.I think this change is safe for the upcoming stdlib change (that'll move
Js.Dict
intoDict
) 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 adict{}
expression so that we only print those back and leaveJs.Dict.fromArray
calls.