Skip to content

Parsing: strictly enforce the produced AST matches the spec and enforce most "error recovery" parsing errors #1852

@steelbrain

Description

@steelbrain
{ "rules": { "no-throw-literal": "error" } }
throw

Just that in a file somewhere

Expected Result

This should be a parse-error and should not be linted on.

Actual Result

Parser creates a ThrowStatement with argument set to null, which breaks rules downstream, see eslint/eslint#13143 for context

Additional Info

[Error - 1:41:32 PM] TypeError: Cannot read property 'type' of null Occurred while linting [fileName].ts:132 at Object.couldBeError (eslint/lib/rules/utils/ast-utils.js:1262:22) at ThrowStatement (eslint/lib/rules/no-throw-literal.js:38:31) at eslint/lib/linter/safe-emitter.js:45:58 at Array.forEach (<anonymous>) at Object.emit (eslint/lib/linter/safe-emitter.js:45:38) at NodeEventGenerator.applySelector (eslint/lib/linter/node-event-generator.js:254:26) at NodeEventGenerator.applySelectors (eslint/lib/linter/node-event-generator.js:283:22) at NodeEventGenerator.enterNode (eslint/lib/linter/node-event-generator.js:297:14) at CodePathAnalyzer.enterNode (eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23) at eslint/lib/linter/linter.js:936:32 

Versions

package version
@typescript-eslint/parser ^2.13.0
TypeScript ^3.8.2
ESLint 5.16.0
node 12.16.0
npm 6.13.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    ASTPRs and Issues about the AST structureaccepting prsGo ahead, send a pull request that resolves this issuebreaking changeThis change will require a new major version to be releasedenhancementNew feature or requestpackage: parserIssues related to @typescript-eslint/parser

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions