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

Parser fail on errorRecovery mode #12074

Closed
1 task done
fisker opened this issue Sep 18, 2020 · 3 comments · Fixed by #12076
Closed
1 task done

Parser fail on errorRecovery mode #12074

fisker opened this issue Sep 18, 2020 · 3 comments · Fixed by #12076
Assignees
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser

Comments

@fisker
Copy link
Contributor

fisker commented Sep 18, 2020

Bug Report

  • I would like to work on a fix!

Current behavior

node -p "require('@babel/parser').parse('const a = {set name(){}}', {errorRecovery: true})"
    if (method.kind === "set" && method.params[method.params.length - 1].type === "RestElement") {
                                                                         ^

TypeError: Cannot read property 'type' of undefined
    at Parser.checkGetterSetterParams (@babel\parser\lib\index.js:10792:74)
    at Parser.parseObjectMethod (@babel\parser\lib\index.js:10800:12)
    at Parser.parseObjPropValue (@babel\parser\lib\index.js:10841:23)
    at Parser.parsePropertyDefinition (@babel\parser\lib\index.js:10772:10)
    at Parser.parseObjectLike (@babel\parser\lib\index.js:10664:25)
    at Parser.parseExprAtom (@babel\parser\lib\index.js:10198:23)
    at Parser.parseExprSubscripts (@babel\parser\lib\index.js:9844:23)
    at Parser.parseUpdate (@babel\parser\lib\index.js:9824:21)
    at Parser.parseMaybeUnary (@babel\parser\lib\index.js:9813:17)
    at Parser.parseExprOps (@babel\parser\lib\index.js:9683:23)

With errorRecovery: true parser didn't throw syntax error

Input Code

const a = {set name(){}}

Expected behavior

Should throw a SyntaxError or continue parse.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

N/A

Environment

- Babel version(s): 7.11.5
- Node/npm version: Node.js 12
- OS: Windows 10
- Monorepo: no
- How you are using Babel: parser api

Possible Solution

N/A

Additional context

Context: prettier/prettier#9226

@babel-bot
Copy link
Collaborator

Hey @fisker! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo
Copy link
Member

Thanks for the report! Probably using ?. there would be enough.

@fisker
Copy link
Contributor Author

fisker commented Sep 18, 2020

This one seems simple, I'm tring to fix it.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 20, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants