Skip to content

Commit 0d0041c

Browse files
authored
Edited comments for clarity
1 parent 8e93b5f commit 0d0041c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/backend/controllers/statePropExtractors.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ export function getHooksStateAndUpdateMethod(
8383

8484
// ---------------------GET STATE VAR NAME & HOOK NAME--------------------------
8585
/**
86-
* This function receive a string representation of a functional component.
87-
* This function then uses JSX parser to traverse through the function string,
88-
* and extract the state variable name and its corresponding setState method.
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.
8987
* @param elementType - The string representation of a functional component
9088
* @returns - An array of objects with key: hookName (the name of setState method) | value: varName (the state variable name)
9189
*/
@@ -100,8 +98,8 @@ export function getHooksNames(elementType: string): { hookName: string; varName:
10098
const statements: { hookName: string; varName: string }[] = [];
10199
/** All module exports always start off as a single 'FunctionDeclaration' type
102100
* Other types: "BlockStatement" / "ExpressionStatement" / "ReturnStatement"
103-
* Iterate through AST of every function(al component) declaration
104-
* Check within each function(al component) declaration if there are hook declarations & variable name declaration */
101+
* Iterate through AST of every functional component declaration
102+
* Check within each functional component declaration if there are hook declarations & variable name declaration */
105103
AST.forEach((functionDec: any) => {
106104
let declarationBody: any;
107105
if (functionDec.expression?.body) declarationBody = functionDec.expression.body.body;
@@ -124,15 +122,15 @@ export function getHooksNames(elementType: string): { hookName: string; varName:
124122
reactHook = expression[1].property?.name;
125123
if (reactHook === 'useState') {
126124
// Obtain the variable being set:
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
128125
let varName: string =
126+
// Points to second to last element of declarations because webpack adds an extra variable when converting files that use ES6
129127
declarations[declarations.length - 2]?.id?.name || // work react application;
130128
(Array.isArray(declarations[0]?.id?.elements)
131129
? declarations[0]?.id?.elements[0]?.name
132130
: undefined); //work for nextJS application
133131
// Obtain the setState method:
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
135132
let hookName: string =
133+
//Points to last element of declarations because webpack adds an extra variable when converting files that use ES6
136134
declarations[declarations.length - 1]?.id?.name || // work react application;
137135
(Array.isArray(declarations[0]?.id?.elements)
138136
? declarations[0]?.id?.elements[0]?.name

0 commit comments

Comments
 (0)