question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement optional chaining and nullish coalescing

See original GitHub issue

a?.ba && a.b Ok or fork?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
alangpiercecommented, Nov 11, 2019

Yep, agreed! I’ve been thinking about this more over the last few days since the TS release, and I’ll reopen this issue and repurpose it to built-in support in Sucrase. I’ll add some more detail when I get a chance.

Chrome Canary now has optional chaining available by default, and in Chrome Beta it’s available behind the “Experimental JavaScript” flag, so it’s already reasonable to use it in development with Sucrase (which will emit it unchanged) for running code in the browser. My team runs tests in Node, though, and it looks like Node 14 (to be released next year) will be the first version with support. We also lag behind the latest Node, so it will be a while before we have native support for the syntax in tests. It seems like a high-enough value syntax that it can be an exception to the “Sucrase is hesitant to implement upcoming JS features” rule.

Sucrase transforms require a lot more thought and care than Babel transforms since Sucrase makes the parser as minimal as possible and transforms code in a left-to-right scan, so it’s tricky, but I think there will be a way to make it work.

3reactions
alangpiercecommented, Dec 27, 2019

I worked through the details and different options by writing up a technical plan at https://github.com/alangpierce/sucrase/wiki/Sucrase-Optional-Chaining-and-Nullish-Coalescing-Technical-Plan . I’ll get started on the implementation soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional chaining and nullish coalescing in TypeScript
Optional chaining is often used together with nullish coalescing, which is the ability to fall back to a default value when the primary ......
Read more >
What is Nullish Coalescing and Optional Chaining in ...
Nullish Coalescing is a way in which you use the Nullish Coalescing Operator in JavaScript to determine whether a value is nullish or...
Read more >
Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
The nullish coalescing operator may be used after optional chaining in order to build a default value when none was found:.
Read more >
How can I use optional chaining and nullish coalescing in my ...
The optional chaining operator ( ?. ) allows us to access deeply nested object properties without having to validate each reference in the ......
Read more >
Optional Chaining and Nullish Coalescing in TypeScript
Optional chaining allows you to write code that will immediately stop running expressions if it hits a null or undefined . ... A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found