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.

Support optional chaining operator

See original GitHub issue

Great job here.

I want to suggest adding support for the optional chaining operator e.g

Code:

'use strict';

function greet(name) {
  name = name  || 'World'
  var isJohn = name && name.includes && name.includes('John')
  alert(isJohn ? 'Hello Admin' : 'Hello ' + name)
}

Current Output:

function greet(name = 'World') {
  const isJohn = name && name.includes && name.includes('John')
  alert(isJohn ? 'Hello Admin' : `Hello ${name}`)
}

Expected Output:

function greet(name = 'World') {
  const isJohn = name?.includes('John')
  alert(isJohn ? 'Hi Admin' : `Hello ${name}`)
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
uniibucommented, Jul 23, 2020

@frank-dspeed thanks for clarifying, although I never said that a stage 3 proposals have a chance to not be implemented. In fact, I don’t think there has ever been a stage 3 proposal that was eventually withdrawn/rejected. You are also correct that browsers indeed are implementing most of the stage 3 proposals, however, Lebab does not rely on browsers as its parser. It uses Espree and during the time i wrote that comment, optional chaining was still not implemented.

Going back, I would say this is now possible to do since Espree have already implemented it on their latest release v7.2.0 which includes PR #446 and was only released 6 days ago.

2reactions
DiegoRBaquerocommented, May 13, 2021

Optional chaining works in Node 14+, would be a great addition to lebab

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
The optional chaining ( ?. ) operator accesses an object's property or calls a function. If the object accessed or function called is ......
Read more >
Optional chaining operator (`?.`) | Can I use... Support tables ...
JavaScript operator: Optional chaining operator ( ?. ) Usage % of. all users, all tracked, tracked desktop, tracked mobile.
Read more >
JavaScript Optional Chaining Operator (?.)
In this tutorial, you'll learn about the optional chaining operator (?.) that simplifies the way to access values through connected objects.
Read more >
How to Use Optional Chaining in JavaScript - freeCodeCamp
Optional chaining is a safe and concise way to perform access checks for nested object properties. The optional chaining operator ?. takes ...
Read more >
Optional chaining '?.' - The Modern JavaScript Tutorial
The optional chaining ?. is not an operator, but a special syntax construct, that also works with functions and square brackets. For example,...
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