Skip to content

Commit b8820bc

Browse files
authored
🐛 fix isParenthesized() check on CatchClause.param (#16)
1 parent c5574ce commit b8820bc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/is-parenthesized.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ export function isParenthesized(
9292
sourceCode = nodeOrSourceCode
9393
}
9494

95-
if (node == null) {
95+
if (
96+
node == null ||
97+
// `CatchClause.param` can't be parenthesized, example `try {} catch (error) {}`
98+
(node.parent.type === "CatchClause" && node.parent.param === node)
99+
) {
96100
return false
97101
}
98102

test/is-parenthesized.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ describe("The 'isParenthesized' function", () => {
203203
"body.0.object": true,
204204
},
205205
},
206+
{
207+
code: "try {} catch (a) {}",
208+
expected: {
209+
"body.0.handler.param": false,
210+
},
211+
},
206212
]) {
207213
describe(`on the code \`${code}\``, () => {
208214
for (const key of Object.keys(expected)) {

0 commit comments

Comments
 (0)