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
121
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.
122
+
//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.
145
123
if(expression===undefined)return;
146
124
letreactHook: string;
147
125
reactHook=expression[1].property?.name;
148
126
if(reactHook==='useState'){
149
127
// 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
128
+
//This 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
129
letvarName: string=
152
130
declarations[declarations.length-2]?.id?.name||// work react application;
153
131
(Array.isArray(declarations[0]?.id?.elements)
154
132
? declarations[0]?.id?.elements[0]?.name
155
133
: undefined);//work for nextJS application
156
134
// 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
135
+
//This 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
136
lethookName: string=
159
137
declarations[declarations.length-1]?.id?.name||// work react application;
160
138
(Array.isArray(declarations[0]?.id?.elements)
161
139
? declarations[0]?.id?.elements[0]?.name
162
140
: undefined);//work for nextJS & Remix
163
141
// 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