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

Nullish Coalescing (Stage 3) #14

Closed
2 tasks
hzoo opened this issue Jul 21, 2017 · 8 comments
Closed
2 tasks

Nullish Coalescing (Stage 3) #14

hzoo opened this issue Jul 21, 2017 · 8 comments

Comments

@hzoo
Copy link
Member

hzoo commented Jul 21, 2017

Champions: @gisenberg
Spec Repo: https://github.com/gisenberg/proposal-nullary-coalescing
First presented at the July 2017 meeting: slides
Moved to Stage 1 at the Sept 2017 meeting: slides

Syntax

a ?? b

When performing optional property access in a nested structure in conjunction with the optional chaining operator, it is often desired to provide a default value if the result of that property access is null or undefined. At present, a typical way to express this intent in JavaScript is by using the || operator.

so most use const variable = a || b but a falsy value like 0 or '' or false will unintentionally return b as the value.

Notes:

While this proposal specifically calls out null and undefined values, the intent is to provide a complementary operator to the optional chaining operator. This proposal will update to match the semantics of that operator.

Parsing

  • a new node type name (operator)?
  • pluginName?

https://twitter.com/littledan/status/908032146484469761
https://github.com/babel/babylon/pull/742/files#r142008197

@jridgewell
Copy link
Member

logicalCOALESCE? Too much of a mouthful? logicalQQ?

@gisenberg
Copy link
Member

I started referring to this as the existential operator in the slides.

@hzoo
Copy link
Member Author

hzoo commented Jul 27, 2017

@gisenberg feel free to edit the title/etc (if your in the tc39 team it gives you write access to this repo)

@ljharb
Copy link
Member

ljharb commented Jul 27, 2017

@hzoo hzoo changed the title Nullary Coalescing (Stage 0) Nullary Coalescing (Stage 1) Sep 28, 2017
@hzoo hzoo mentioned this issue Sep 28, 2017
11 tasks
@azz
Copy link
Member

azz commented Oct 15, 2017

Parser PR: babel/babylon#761, follow-up: babel/babylon#762
Transform PR: babel/babel#6483

@ljharb ljharb changed the title Nullary Coalescing (Stage 1) Nullish Coalescing (Stage 1) Oct 15, 2017
@vjpr
Copy link

vjpr commented May 7, 2018

What is the status of this? Is it ready to use?

@azz
Copy link
Member

azz commented May 7, 2018

Yes, just enable the @babel/plugin-proposal-nullish-coalescing-operator plugin.

https://www.npmjs.com/package/@babel/plugin-proposal-nullish-coalescing-operator

@hzoo hzoo changed the title Nullish Coalescing (Stage 1) Nullish Coalescing (Stage 3) Oct 3, 2019
@hzoo
Copy link
Member Author

hzoo commented Oct 3, 2019

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

6 participants