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 ChainExpression type for optional chaining #383

Closed
mjhenkes opened this issue Aug 3, 2020 · 3 comments · Fixed by #399
Closed

Support ChainExpression type for optional chaining #383

mjhenkes opened this issue Aug 3, 2020 · 3 comments · Fixed by #399

Comments

@mjhenkes
Copy link

mjhenkes commented Aug 3, 2020

Feature request or bug?

babelParser@7.11.0 changed how optional chaining gets represented in an AST. Previously the optional chain was represented as an OptionalMemberExpression, now the optional chain is broken into two nodes a ChainExpression and a MemberExpression.

I asked babel if this was a breaking change and they clarified that this is an intentional change. See Babel issue #11908

I stumbled upon this while trying to use react-doc-gen against a component with optional chanining and the ast-types library that it uses fails when it tries to understand the 'ChainExpression' type. See react-doc-gen issue #463

I'm currently working around this issue by locking in the projects babel dependencies in the package.json

For example:

  "devDependencies": {
-    "@babel/core": "^7.5.0",
+    "@babel/core": "7.10.5",
+    "@babel/parser": "7.10.5",

However this isn't a good long term fix. I would be ideal if ast-types was updated to support the chainExpression type.

@jquense
Copy link

jquense commented Aug 21, 2020

🙏 anything i can do to help with this?

@ethancrook99
Copy link
Contributor

I made a PR for a possible fix here.

@mjhenkes
Copy link
Author

Thank you @ethancrook99 and @benjamn ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants