Skip to content

Implement proposal-optional-chaining - #2572

Merged
azz merged 2 commits into
prettier:masterfrom
azz:elvis
Aug 3, 2017
Merged

azz merged 2 commits into
prettier:masterfrom
azz:elvis

Conversation

@azz

@azz azz commented Aug 1, 2017

Copy link
Copy Markdown
Member

https://github.com/tc39/proposal-optional-chaining

I had to add code to more places that I would have liked. Might need to clean this up a bit.

Closes #2568

cc. @bakkot @existentialism want to give this a sanity check?

@vjeux Think it is too early to add support for this?

@vjeux

vjeux commented Aug 1, 2017

Copy link
Copy Markdown
Contributor

Omg <3

I've been lobbying for someone at Facebook to champion it at tc39 for at least 4 years, I'm so happy that it's moving along :)

If prettier support can do even a tiny bit at making it move forward, I'm supportive!

obj?.[expr];
func?.(...args);

a?.();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this the actual syntax? It looks weird, I would have written it as a?()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's the syntax currently in the proposal, but there is no "actual syntax" here - this is a stage 1 proposal, which amounts to "someone on the committee thought something kinda vaguely like this might be a good idea". Its syntax and semantics are likely to change radically and repeatedly before it makes it into the language, if it ever does.

That said, a?() in particular is unlikely because it's ambiguous: a?(0) could be a call, or could be the first two thirds of a ternary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coffeescript somehow made it work :)

img_0790

@bakkot bakkot Aug 1, 2017 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CoffeeScript made it work by not having ternaries at all. (This has the amusing effect that some code, like a=b?(c,d)+e:f, is both valid CoffeeScript and valid JS but with totally different semantics in each case.)

Life is much easier when you don't have to worry about old code.

@azz

azz commented Aug 1, 2017

Copy link
Copy Markdown
Member Author

Attempted to clean it up a bit by decreasing the overall number of code branches, not sure if I made it better or worse. 🤷‍♂️ f06318b

@azz
azz merged commit e378f5e into prettier:master Aug 3, 2017
@azz
azz deleted the elvis branch August 3, 2017 07:38
@azz

azz commented Aug 3, 2017 •

Copy link
Copy Markdown
Member Author

@bterlson merged this. (context)

@azz azz mentioned this pull request Aug 27, 2017
4 of 6 tasks
@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 19, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants