Skip to content

Commit

Permalink
fix(is-parenthesized): don't crash on Program (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 28, 2022
1 parent 9be40ab commit f53ab06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/is-parenthesized.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export function isParenthesized(

if (
node == null ||
// `Program` can't be parenthesized
node.parent == null ||
// `CatchClause.param` can't be parenthesized, example `try {} catch (error) {}`
(node.parent.type === "CatchClause" && node.parent.param === node)
) {
Expand Down
6 changes: 6 additions & 0 deletions test/is-parenthesized.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ describe("The 'isParenthesized' function", () => {
"body.0.handler.param": false,
},
},
{
code: "foo;",
expected: {
"body.0.parent": false,
},
},
]) {
describe(`on the code \`${code}\``, () => {
for (const key of Object.keys(expected)) {
Expand Down

0 comments on commit f53ab06

Please sign in to comment.