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

Object and array literals via {} and [] followed by items #1575

Merged
merged 5 commits into from
Nov 5, 2024

Conversation

edemaine
Copy link
Collaborator

@edemaine edemaine commented Nov 5, 2024

Braced object literals have many more features than unbraced object literals (from CoffeeScript). This PR transforms an unbraced object literal into a braced one by adding {} in front of it, both in the inline case ({} foo, bar) and in the nested case with a layer of indentation:

{}
  foo
  bar

Overall, the syntax aligns with implicit function calls, and {} is never a function that can be called, so there's effectively no ambiguity here.

Similarly, [] constructs array literals. This isn't as important, especially given that we have bulleted arrays (which are still useful because they allow clear delineation between unbraced object literal elements), but it does allow for some fun things:

[] [] [] [] x
↓↓↓
[ [ [ [ x]]]]
consList := [] x, [] y, [] z
↓↓↓
const consList = [ x, [ y, [ z]]]

Copy link
Contributor

@STRd6 STRd6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm scared...

... scared I might like it 😨 😌

@edemaine edemaine merged commit f4cf992 into main Nov 5, 2024
4 checks passed
@edemaine edemaine deleted the brace-unbrace branch November 5, 2024 12:22
@edemaine
Copy link
Collaborator Author

edemaine commented Nov 5, 2024

Let's see how it feels! I was a bit scared about this one for a while, until I realized we're only replacing function calls that didn't make sense.

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.

2 participants