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

Braced object literal shorthand #276

Merged
merged 4 commits into from
Jan 23, 2023
Merged

Braced object literal shorthand #276

merged 4 commits into from
Jan 23, 2023

Conversation

edemaine
Copy link
Collaborator

Implements the following braced object literal shorthand (the first part of #238):

  • {props.name}{name: props.name} (and name={props.name} in JSX context)
  • {computed()}{computed: computed()}
  • {x.y?.z?()}{z: x.y?.z?()}

This PR newly forbids methods with no body. However, method(){} specifies an empty body.

Some potentially confusing behavior is that { console.log('hello', name) } is now potentially an object literal (or a block), namely { log: console.log('hello', name) }. This broke one test case that used a weird mix of for loop notation: no parens around the condition, but braces around the block:

for [i, j] of x {
  console.log(i)
}

This is still broken: doesn't parse, because for loop has no body. Proposal is that for loops should use parens and braces, or neither.

@edemaine edemaine temporarily deployed to build January 23, 2023 16:15 — with GitHub Actions Inactive
@@ -1166,6 +1184,15 @@ Arrow
return { $loc, token: $1}

ExplicitBlock
__ OpenBrace __ CloseBrace ->
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been starting to replace the loose leading __ with ( Samedent / _ )?. The __ in between open and close in fine.

Not something that needs to be done in this PR just something I wanted to share as we move towards more strict/robust indenting.

@edemaine edemaine merged commit 47afecf into main Jan 23, 2023
@edemaine edemaine deleted the object-literal-shorthand branch January 23, 2023 16:57
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