Skip to content

Commit b00ab0a

Browse files
committed
Removed console logs and comments
1 parent 2ea4f60 commit b00ab0a

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

src/backend/controllers/statePropExtractors.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ export function getHooksNames(elementType: string): { hookName: string; varName:
9595
let AST: any;
9696
try {
9797
AST = JSXParser.parse(elementType).body;
98-
console.log('AST');
99-
console.log(AST);
100-
let count = 0;
10198
// Begin search for hook names, only if ast has a body property.
10299
// Statements get all the names of the hooks. For example: useCount, useWildcard, ...
103100
const statements: { hookName: string; varName: string }[] = [];
@@ -106,67 +103,42 @@ export function getHooksNames(elementType: string): { hookName: string; varName:
106103
* Iterate through AST of every function(al component) declaration
107104
* Check within each function(al component) declaration if there are hook declarations & variable name declaration */
108105
AST.forEach((functionDec: any) => {
109-
// console.log('functionDec');
110-
// console.log(functionDec);
111106
let declarationBody: any;
112107
if (functionDec.expression?.body) declarationBody = functionDec.expression.body.body;
113108
// check if functionDec.expression.body exists, then set declarationBody to functionDec's body
114109
else declarationBody = functionDec.body?.body ?? [];
115110
// Traverse through the function's funcDecs and Expression Statements
116-
console.log('declarationBody');
117-
console.log( declarationBody);
118111
declarationBody.forEach((elem: any) => {
119112
// Hooks will always be contained in a variable declaration
120-
console.log('elem type:', count++, elem.type);
121-
console.log(elem);
122-
123113
if (elem.type === 'VariableDeclaration') {
124114
// Obtain the declarations array from elem.
125115
const { declarations } = elem;
126116
// Obtain the reactHook:
127117
// Due to difference in babel transpilation in browser vs for jest test, expression is stored in differen location
128-
console.log('Found variable declaration, elem declarations:', declarations)
129-
// console.log('dec[0]', declarations[0]);
130-
// console.log('init',declarations[0]?.init);
131-
// console.log('callee',declarations[0]?.init?.callee);
132-
// console.log('expressions', declarations[0]?.init?.callee?.expressions);
133-
// console.log('Line 2!');
134-
// console.log('args', declarations[0]?.init?.arguments);
135-
// console.log('args[0]', declarations[0]?.init?.arguments?.arguments[0]);
136-
// console.log('callee', declarations[0]?.init?.arguments?.arguments[0]?.callee);
137-
// console.log('expression', declarations[0]?.init?.arguments?.arguments[0]?.callee?.expressions);
138118
const expression =
139119
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.
141120
declarations[0]?.init?.arguments?.[0]?.callee?.expressions; //work for jest test;
142121

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.
145123
if (expression === undefined) return;
146124
let reactHook: string;
147125
reactHook = expression[1].property?.name;
148126
if (reactHook === 'useState') {
149127
// 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
151129
let varName: string =
152130
declarations[declarations.length - 2]?.id?.name || // work react application;
153131
(Array.isArray(declarations[0]?.id?.elements)
154132
? declarations[0]?.id?.elements[0]?.name
155133
: undefined); //work for nextJS application
156134
// 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
158136
let hookName: string =
159137
declarations[declarations.length - 1]?.id?.name || // work react application;
160138
(Array.isArray(declarations[0]?.id?.elements)
161139
? declarations[0]?.id?.elements[0]?.name
162140
: undefined); //work for nextJS & Remix
163141
// 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
168-
* stored via useState and useContext
169-
*/
170142
statements.push({ hookName, varName });
171143
}
172144
}

0 commit comments

Comments
 (0)