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

Fix: no-extra-parens crash when code is "((let))" #11444

Merged
merged 1 commit into from Feb 28, 2019

Conversation

not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Feb 26, 2019

What is the purpose of this pull request? (put an "X" next to item)

[x] Bug fix

The PR title contains all of the information needed to reproduce the issue.

Tell us about your environment

  • ESLint Version: master
  • Node Version: latest
  • npm Version: latest

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

rules:
  no-extra-parens: error

What did you do? Please include the actual source code causing the issue.

((let))

What did you expect to happen?

I expected an error to be reported by the no-extra-parens rule, because the identifier let is unnecessarily parenthesized twice.

What actually happened? Please include the actual, raw output from ESLint.

The rule crashed:

TypeError: Cannot read property 'value' of null
    at Object.isOpeningBracketToken (/home/travis/build/eslint/eslint/lib/util/ast-utils.js:329:18)
    at checkExpressionOrExportStatement (/home/travis/build/eslint/eslint/lib/rules/no-extra-parens.js:482:65)
    at ExpressionStatement (/home/travis/build/eslint/eslint/lib/rules/no-extra-parens.js:565:42)
    at listeners.(anonymous function).forEach.listener (/home/travis/build/eslint/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/home/travis/build/eslint/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/travis/build/eslint/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/home/travis/build/eslint/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (/home/travis/build/eslint/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (/home/travis/build/eslint/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)

What changes did you make? (Give an overview)

This fixes a broken check in the no-extra-parens rule for tokens after let identifiers.

This issue was detected by the fuzzer in https://travis-ci.org/eslint/eslint/jobs/498031437.

Is there anything you'd like reviewers to focus on?

Nothing in particular

@not-an-aardvark not-an-aardvark added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Feb 26, 2019
@aladdin-add aladdin-add self-requested a review February 26, 2019 04:47
@aladdin-add
Copy link
Member

just curious is (let) foo valid? I would have thought it will cause a parsing error.

and should we add a test (var) foo(if it is accepted).

@not-an-aardvark
Copy link
Member Author

(let)\nfoocontains two ExpressionStatements, an identifier called let and an identifier called foo. ASI inserts a semicolon after (let). (let is a valid variable name in sloppy mode.)

Without parentheses, let\nfoo is a variable declaration for a variable named foo.

@mysticatea
Copy link
Member

@aladdin-add var is a reserved word, but let is not. We can use let as a variable name.

Copy link
Member

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@not-an-aardvark not-an-aardvark merged commit 6489518 into master Feb 28, 2019
@not-an-aardvark not-an-aardvark deleted the fix-no-extra-parens-crash branch February 28, 2019 01:40
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 28, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Aug 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants