Skip to content

Commit f53ab06

Browse files
authored
fix(is-parenthesized): don't crash on Program (mysticatea#31)
1 parent 9be40ab commit f53ab06

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/is-parenthesized.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export function isParenthesized(
9494

9595
if (
9696
node == null ||
97+
// `Program` can't be parenthesized
98+
node.parent == null ||
9799
// `CatchClause.param` can't be parenthesized, example `try {} catch (error) {}`
98100
(node.parent.type === "CatchClause" && node.parent.param === node)
99101
) {

test/is-parenthesized.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ describe("The 'isParenthesized' function", () => {
209209
"body.0.handler.param": false,
210210
},
211211
},
212+
{
213+
code: "foo;",
214+
expected: {
215+
"body.0.parent": false,
216+
},
217+
},
212218
]) {
213219
describe(`on the code \`${code}\``, () => {
214220
for (const key of Object.keys(expected)) {

0 commit comments

Comments
 (0)