Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: handle optional catch bindings in no-useless-catch (#11205)
This commit prevents a crash in the no-useless-catch rule
that occurs when optional catch bindings are used.
  • Loading branch information
cjihrig authored and platinumazure committed Dec 25, 2018
1 parent 0b81fc2 commit de79f10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rules/no-useless-catch.js
Expand Up @@ -27,6 +27,7 @@ module.exports = {
return {
CatchClause(node) {
if (
node.param &&
node.param.type === "Identifier" &&
node.body.body.length &&
node.body.body[0].type === "ThrowStatement" &&
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/no-useless-catch.js
Expand Up @@ -103,6 +103,16 @@ ruleTester.run("no-useless-catch", rule, {
}
`,
parserOptions: { ecmaVersion: 8 }
},
{
code: `
try {
throw new Error('foo');
} catch {
throw new Error('foo');
}
`,
parserOptions: { ecmaVersion: 2019 }
}

],
Expand Down

0 comments on commit de79f10

Please sign in to comment.