Skip to content

Commit 3217499

Browse files
Removed console logs for dev
Co-authored-by: Mark Teets <MarkTeets@users.noreply.github.com>
1 parent c8ff050 commit 3217499

File tree

2 files changed

+5
-39
lines changed

2 files changed

+5
-39
lines changed

src/app/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
/* eslint-disable react/jsx-filename-extension */
22
import React from 'react';
3-
// import ReactDOM from 'react-dom';
43
import { createRoot } from 'react-dom/client';
54
import App from './components/App';
65
import './styles/main.scss';
76

8-
// Old way of rendering that was locking Reactime into React 17
9-
// Left for testing purposes
10-
// ReactDOM.render(<App />, document.getElementById('root'));
11-
12-
//New way of rendering that allows us to use React 18
7+
//Updated rendering sytax for React 18
138
const root = createRoot(document.getElementById("root"));
149
root.render(
15-
//Strict mode is for developers, it throws extra errors
10+
// Strict mode is for developers to better track best practices
1611
// <StrictMode>
1712
<App/>
1813
// </StrictMode>

src/backend/controllers/statePropExtractors.ts

Lines changed: 3 additions & 32 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,41 @@ 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;
142-
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.
121+
// 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.
145122
if (expression === undefined) return;
146123
let reactHook: string;
147124
reactHook = expression[1].property?.name;
148125
if (reactHook === 'useState') {
149126
// 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
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
151128
let varName: string =
152129
declarations[declarations.length - 2]?.id?.name || // work react application;
153130
(Array.isArray(declarations[0]?.id?.elements)
154131
? declarations[0]?.id?.elements[0]?.name
155132
: undefined); //work for nextJS application
156133
// 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
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
158135
let hookName: string =
159136
declarations[declarations.length - 1]?.id?.name || // work react application;
160137
(Array.isArray(declarations[0]?.id?.elements)
161138
? declarations[0]?.id?.elements[0]?.name
162139
: undefined); //work for nextJS & Remix
163140
// 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-
*/
170141
statements.push({ hookName, varName });
171142
}
172143
}

0 commit comments

Comments
 (0)