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

Require curly braces for same-name key-value shorthand #873

Closed
TrevorBurnham opened this issue Nov 25, 2010 · 6 comments
Closed

Require curly braces for same-name key-value shorthand #873

TrevorBurnham opened this issue Nov 25, 2010 · 6 comments

Comments

@TrevorBurnham
Copy link
Collaborator

This has been discussed a bit in other issues, but I don't think anyone has raised the matter directly.

{a} is shorthand for {a: a}. That's cool. And in a function call, I can write

foo a, b: 2

as shorthand for

foo a, {b: 2}

Also cool. But if I write

foo b: 2, a

then this is parsed as

foo {b: 2, a: a}

I see this as seriously ambiguous. I'd prefer that only consecutive explicit key: value pairs without curly braces be interpreted as object declarations. Do others agree?

@ghost
Copy link

ghost commented Nov 26, 2010

I agree 100%.

I have 6969 lines of CoffeeScript code in my current project and never, ever, had a need for the a to {a: a} expansion.

The change TrevorBurnham proposes however, allows us to have, for example, string parameters after the implicit key: value pairs...

...This alone, in my current project, would allow the removal of curly braces in over 30 places.

Furthermore, whenever I'm rereading my code, those curly braces always stop me in my tracks, making me think: "Why are these here? Why haven't I removed them?"

Food for thought.

@satyr
Copy link
Collaborator

satyr commented Nov 26, 2010

ref. #618

@hen-x
Copy link

hen-x commented Nov 26, 2010

I love the {a}{a: a} expansion, but agree that it should only happen inside of explicit curly braces. Otherwise, when a bare expression follows a colon-separted pair and a comma, it should always indicate the end of the implicit hash.

@jashkenas
Copy link
Owner

Yep, I'm afraid this is a duplicate of #618 -- meaning that I don't know how to make it parseable. If anyone can come up with a patch or an idea for how to fix it, please post it to that ticket; closing this one.

@ghost
Copy link

ghost commented Nov 29, 2010

Oh, well, this makes me sad... But only a bit -- programming in CoffeeScript is still a joy. :)

@jashkenas
Copy link
Owner

A patch to fix this issue is now on master, as of #1061. Please give it a try and see if it works for your use cases.

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

No branches or pull requests

4 participants