Skip to content

Commit 283319b

Browse files
author
Adam Spiers
committed
Deal gracefully with missing hook.init
It seems that in some cases, VariableDeclaration elements in the AST are missing the init property. So add a check to handle this gracefully.
1 parent 16879fb commit 283319b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/backend/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const getHooksNames = (elementType: string): Array<string> => {
113113
} else {
114114
// hook.init.object is '_useState2', '_useState4', etc.
115115
// eslint-disable-next-line no-lonely-if
116-
if (hook.init.object && hook.init.object.name) {
116+
if (hook?.init?.object?.name) {
117117
const varName: any = hook.init.object.name;
118118
if (!hooksNames[varName] && varName.match(/_use/)) {
119119
hooksNames[varName] = hook.id.name;

0 commit comments

Comments
 (0)