Skip to content

Commit

Permalink
🐛 fix isParenthesized() check on CatchClause.param (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored May 14, 2021
1 parent c5574ce commit b8820bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/is-parenthesized.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ export function isParenthesized(
sourceCode = nodeOrSourceCode
}

if (node == null) {
if (
node == null ||
// `CatchClause.param` can't be parenthesized, example `try {} catch (error) {}`
(node.parent.type === "CatchClause" && node.parent.param === node)
) {
return false
}

Expand Down
6 changes: 6 additions & 0 deletions test/is-parenthesized.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ describe("The 'isParenthesized' function", () => {
"body.0.object": true,
},
},
{
code: "try {} catch (a) {}",
expected: {
"body.0.handler.param": false,
},
},
]) {
describe(`on the code \`${code}\``, () => {
for (const key of Object.keys(expected)) {
Expand Down

0 comments on commit b8820bc

Please sign in to comment.