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
Copy file name to clipboardExpand all lines: src/backend/controllers/statePropExtractors.ts
-32Lines changed: 0 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -78,17 +78,11 @@ export function getHooksStateAndUpdateMethod(
78
78
}
79
79
memoizedState=memoizedState.next;
80
80
}
81
-
// console.log('hooksStates from getHooksStateAndUpdateMethod');
82
-
// console.log(hooksStates);
83
-
//confirmed Sudoku home data successfully in hooksStates via console log
84
81
returnhooksStates;
85
82
}
86
83
87
84
// ---------------------GET STATE VAR NAME & HOOK NAME--------------------------
88
85
/**
89
-
* This function receive a string representation of a functional component.
90
-
* This function then uses JSX parser to traverse through the function string,
91
-
* and extract the state variable name and its corresponding setState method.
92
86
* This function receive a string representation of a functional component. This function then use JSX parser to traverse through the function string, and extract the state variable name and its corresponding setState method.
93
87
* @param elementType - The string representation of a functional component
94
88
* @returns - An array of objects with key: hookName (the name of setState method) | value: varName (the state variable name)
declarations[0]?.init?.callee?.expressions||//work for browser
136
-
//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.
137
118
declarations[0]?.init?.arguments?.[0]?.callee?.expressions;//work for jest test;
138
-
139
-
console.log('looked for expression, found:',expression);
140
-
//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.
141
-
if(expression===undefined)return;
142
-
declarations[0]?.init?.arguments?.[0]?.callee?.expressions;//work for jest test;
143
119
// 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.
144
120
if(expression===undefined)return;
145
121
letreactHook: string;
146
122
reactHook=expression[1].property?.name;
147
123
if(reactHook==='useState'){
148
124
// Obtain the variable being set:
149
125
letvarName: string=
150
-
declarations[declarations.length-2]?.id?.name||// work react application;
151
126
// Points to second to last element of declarations because webpack adds an extra variable when converting files that use ES6
152
127
declarations[declarations.length-2]?.id?.name||// work react application;
153
128
(Array.isArray(declarations[0]?.id?.elements)
154
129
? declarations[0]?.id?.elements[0]?.name
155
130
: undefined);//work for nextJS application
156
131
// Obtain the setState method:
157
132
lethookName: string=
158
-
declarations[declarations.length-1]?.id?.name||// work react application;
159
133
//Points to last element of declarations because webpack adds an extra variable when converting files that use ES6
160
134
declarations[declarations.length-1]?.id?.name||// work react application;
161
135
(Array.isArray(declarations[0]?.id?.elements)
162
136
? declarations[0]?.id?.elements[0]?.name
163
137
: undefined);//work for nextJS & Remix
164
138
// Push reactHook & varName to statements array
165
-
/**
166
-
* Mark's notes, I'd like to alter the structure of the data
167
-
* to pass on the reactHook 'useState'. That way the user will
168
-
* eventually be able to view the difference between variables
0 commit comments