Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Add dict literal syntax #6774

wants to merge 7 commits into from

Conversation

bloodyowl
Copy link
Collaborator

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"} 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.

@IwanKaramazow
Copy link

Can you add a changelog entry?

@cknitt
Copy link
Member

cknitt commented May 26, 2024

Could you remove the unrelated changes in belt_HashSetString.resi and belt_HashSetInt.resi?

@cknitt cknitt mentioned this pull request May 26, 2024
2 tasks
@zth
Copy link
Collaborator

zth commented May 26, 2024

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.

An attribute somehow might actually be beneficial for the editor tooling, if we want to do typed completion for values for instance.

@bloodyowl
Copy link
Collaborator Author

@zth aren't the rules the same as (Js.)Dict.fromArray? couldn't we generalize autocompletion here?

@IwanKaramazow
Copy link

I'm also curious for the use case of the editor tooling =D Wouldn't we want to upgrade codebases automatically through the formatter?

@JonoPrest
Copy link
Contributor

Just noting #6617 supports spread syntax if you want to vendor anything across.

@cknitt
Copy link
Member

cknitt commented Jun 27, 2024

@bloodyowl What's the status of this PR? Would be great to get this feature merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants