Support optional chaining operator
See original GitHub issueGreat 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:
- Created 3 years ago
- Comments:11 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
Optional chaining works in Node 14+, would be a great addition to lebab