You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
declarations[0]?.init?.callee?.expressions||//work for browser
140
-
//Mark's notes: so this was where the app was breaking. ES6 functions (e.g. const handleClick = () => {}) inside functional components were hitting this line and crashing when it tried to access arguments[0] and arguments didn't exist.
141
120
declarations[0]?.init?.arguments?.[0]?.callee?.expressions;//work for jest test;
142
-
143
-
console.log('looked for expression, found:',expression);
144
-
//Mark's Note: for a functional definition that isn't a hook, it won't have the callee being searched for above. This line will cause this forEach execution to stop here in this case.
121
+
// A functional declaration within a component that isn't a hook won't have the callee being searched for above. This line will cause this forEach execution to stop here in this case.
145
122
if(expression===undefined)return;
146
123
letreactHook: string;
147
124
reactHook=expression[1].property?.name;
148
125
if(reactHook==='useState'){
149
126
// Obtain the variable being set:
150
-
//Mark's note: changed to point to second to last element of declarations because webpack adds an extra variable when converting files that use ES6, so the previous pointer wasn't working for this case
127
+
// Points to second to last element of declarations because webpack adds an extra variable when converting files that use ES6, so the previous pointer wasn't working for this case
151
128
letvarName: string=
152
129
declarations[declarations.length-2]?.id?.name||// work react application;
153
130
(Array.isArray(declarations[0]?.id?.elements)
154
131
? declarations[0]?.id?.elements[0]?.name
155
132
: undefined);//work for nextJS application
156
133
// Obtain the setState method:
157
-
//Mark's note: changed to point to last element of declarations because webpack adds an extra variable when converting files that use ES6, so the previous pointer wasn't working for this case
134
+
// Points to last element of declarations because webpack adds an extra variable when converting files that use ES6, so the previous pointer wasn't working for this case
158
135
lethookName: string=
159
136
declarations[declarations.length-1]?.id?.name||// work react application;
160
137
(Array.isArray(declarations[0]?.id?.elements)
161
138
? declarations[0]?.id?.elements[0]?.name
162
139
: undefined);//work for nextJS & Remix
163
140
// Push reactHook & varName to statements array
164
-
/**
165
-
* Mark's notes, I'd like to alter the structure of the data
166
-
* to pass on the reactHook 'useState'. That way the user will
167
-
* eventually be able to view the difference between variables
0 commit comments