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 for ES2020 Optional chaining #2048

Merged
merged 1 commit into from
Apr 28, 2021
Merged

Conversation

ljqx
Copy link
Contributor

@ljqx ljqx commented Dec 5, 2020

This PR fixes #2023.

Several changes are made:

  • The new nodes (properties) defined in ESTree spec, including ChainExpression, ChainElement (optional property for MemberExpression and CallExpression)
  • Scanner logic for ?., which cannot follow a digit.
  • Parser logic for ?.
    • in CallExpression, computed MemberExpression, or static MemberExpression
    • Optional chaining cannot be assignment target
    • Optional chaining cannot work with template string (Note the error message is different for direct chaining a?.'b' with template string or indirect a?.b'c', here apostrophe is used as backtick)
    • ChainExpression is only inserted when in the chain there is optional chaining
  • Tests are updated
    • Unit tests fixtures and integration tests fixtures need to be updated to add the new optional: false property for MemberExpression and CallExpression
    • Test 262 whitelist is updated (Note test/language/expressions/optional-chaining/call-expression-super-no-base.js is whitelisted because of super() in non derived class #2000
    • api tests is updated to include the new node type

@JingleH
Copy link

JingleH commented Dec 14, 2020

When can this be merged? It would be really helpful! Thanks!

@lahma
Copy link
Contributor

lahma commented Dec 14, 2020

@ljqx has done great work with the new features, kudos! Let's give @ariya some time to check it, I know that there can be a lot going on, like work and family.

@6uliver
Copy link

6uliver commented Apr 7, 2021

When could you review and merge this PR since it's a blocking issue for other packages which are using esprima like this one: i18next/i18next-scanner#205

Can I help you somehow to speed up the process?

@jogibear9988
Copy link

@ljqx @ariya any news to this, when this could be merged?

@johnjbarton
Copy link
Contributor

We get a lot of complaints now about esprima failing on optional chaining.

@ljqx
Copy link
Contributor Author

ljqx commented Apr 26, 2021

Will be reviewed in this weekend, thanks @ariya !

Copy link
Contributor

@ariya ariya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work 🥇

@ariya ariya merged commit 0911ad8 into jquery:main Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

ES2020 Optional Chaining
7 participants