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

Support optional chaining operator #311

Open
devhammed opened this issue May 20, 2020 · 11 comments
Open

Support optional chaining operator #311

devhammed opened this issue May 20, 2020 · 11 comments

Comments

@devhammed
Copy link

devhammed commented May 20, 2020

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}`)
}
@devhammed devhammed changed the title Support null-coalescing operator Support Safe navigation operator May 20, 2020
@devhammed devhammed changed the title Support Safe navigation operator Support optional chaining operator May 20, 2020
@uniibu
Copy link
Contributor

uniibu commented May 26, 2020

Good suggestion, however, even tho the proposal is already on Stage 4(finished), we would still need to wait around July where the schedule(if schedules are followed) of the new standard by the ECMA General Assembly will get approved.

@frank-dspeed
Copy link

@uniibu thats not correct you can assume every stage 3 feature will get implemented even browsers have implemented it already stage 3 is save to impl

@uniibu
Copy link
Contributor

uniibu commented 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.

@frank-dspeed
Copy link

@uniibu espree now uses acron anyway now under the hood so it supports everything

@frank-dspeed
Copy link

@uniibu even top level await

@uniibu
Copy link
Contributor

uniibu commented Jul 23, 2020

For me, I have nothing against adding new features and supporting latest proposals. But we have to keep in mind that Lebab wasn't made only for codes that runs on browsers in general. For example, implementing a top level await must be put on a separate transform option to be able to disable it as it does not work on nodejs environment.

Fwiw, I do not decide which new feature to add or edit for this library. @nene would be the right person for that.

@frank-dspeed
Copy link

@uniibu we have TOP LEVEL AWAIT inside nodejs :)

@frank-dspeed
Copy link

@uniibu
Copy link
Contributor

uniibu commented Aug 4, 2020

TLA on nodejs is still under experimental. I don't see it being implemented fully to nodejs at stage 3 (https://github.com/tc39/proposal-top-level-await), maybe when v15 LTS comes out on October, or maybe not. Besides, to make it work on nodejs at this time, a flag --harmony-top-level-await must be used along with "type": "module". From a production stand point, I don't see my self using it until it comes out of experimental stage.

On another point, I think the project is dead or is dying/forgotten. @nene has been inactive for a long time now and I don't think owner really cares much at this point. My PR which updates the dependencies including espree, has not seen the light of day for 2 months already. It's sad imo, the project had its potential.

@frank-dspeed
Copy link

@uniibu i will fork lebab now and turn it into codemods

@DiegoRBaquero
Copy link

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

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

5 participants