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
// // Traverse through the function's funcDecs and Expression Statements
215
-
// console.log('declarationBody');
216
-
// console.log( declarationBody);
217
-
// declarationBody.forEach((elem: any) => {
218
-
// // Hooks will always be contained in a variable declaration
219
-
// console.log('elem type:', count++, elem.type);
220
-
// console.log(elem);
221
-
222
-
// if (elem.type === 'VariableDeclaration') {
223
-
// // Obtain the declarations array from elem.
224
-
// const { declarations } = elem;
225
-
// // Obtain the reactHook:
226
-
// // Due to difference in babel transpilation in browser vs for jest test, expression is stored in differen location
227
-
// const expression =
228
-
// declarations[0]?.init?.callee?.expressions || //work for browser
229
-
// declarations[0]?.init?.arguments[0]?.callee?.expressions; //work for jest test
230
-
// let reactHook: string;
231
-
// reactHook = expression[1].property?.name;
232
-
// if (reactHook === 'useState') {
233
-
// // Obtain the variable being set:
234
-
// let varName: string =
235
-
// declarations[declarations.length - 2]?.id?.name || // work react application; Mark's note: changed to point to second to last element of declarations because webpack added an extra variable and therefor declaration in the middle of the array cuz es6
236
-
// (Array.isArray(declarations[0]?.id?.elements)
237
-
// ? declarations[0]?.id?.elements[0]?.name
238
-
// : undefined); //work for nextJS application
239
-
// // Obtain the setState method:
240
-
// let hookName: string =
241
-
// declarations[declarations.length - 1]?.id?.name || // work react application; Mark's note: changed to point to last element of declarations because webpack added an extra variable and therefor declaration in the middle of the array cuz es6
242
-
// (Array.isArray(declarations[0]?.id?.elements)
243
-
// ? declarations[0]?.id?.elements[0]?.name
244
-
// : undefined); //work for nextJS & Remix
245
-
// // Push reactHook & varName to statements array
246
-
// /**
247
-
// * Mark's notes, it's interesting that they don't want to
248
-
// * pass on reactHook 'useState'. I wonder why.
249
-
// */
250
-
// statements.push({ hookName, varName });
251
-
// }
252
-
// }
253
-
// });
254
-
// });
255
-
// return statements;
256
-
// } catch (err) {
257
-
// throw new Error('getHooksNameError' + err.message);
0 commit comments