jquery / esprima

ECMAScript parsing infrastructure for multipurpose analysis
http://esprima.org
BSD 2-Clause "Simplified" License
7.04k stars 786 forks source link

Feature request: Optional chaining operator #2112

Open Rosuav opened 2 years ago

Rosuav commented 2 years ago

Steps to reproduce

esprima.parse('foo?.bar')

Expected output

Some indication that this is optional chaining (if foo exists, it's the same as foo.bar, else it's undefined)

Actual output

"Unexpected token ."

Relevant references

https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#prod-OptionalExpression

This is supported in all major browsers and Node.js.

jmelvin commented 2 years ago

We started using more ES6 syntax recently and also ran into the optional chaining failure. It guess we will have to be more selective until this is supported.

sergey-v9 commented 2 years ago

we have had to move to nightly-esprima because of this

mariocampacci commented 2 years ago

it is not implemented (?) although it seems limited to template literal as suggested by the comment

however I cannot understend why: ES6 shouldn't be handled? 57dc451e6d5dc9d692697561e402d532c9f432d0 and as far as i know the proposal passed

jogibear9988 commented 2 years ago

you can also try my esprima fork esprima-next wich is in es6 and should work with ES6 code https://github.com/node-projects/esprima-next

Rosuav commented 2 years ago

Does that work with the Python bindings?

jogibear9988 commented 2 years ago

don't know

lmh-justdo commented 1 year ago

Object deconstruction like ... not support

Nefcanto commented 1 year ago

we have had to move to nightly-esprima because of this

@sergey-v9 what is that nightly-esprima? I searched it and it takes me back to the esprima repository itself.

sergey-v9 commented 1 year ago

@Nefcanto yes, it is the same, but bult from the latest version of the code in this repo from 2021 year (while the official last version was 4.0.1 from 2018 year)