Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ function createPanel(context) {
// null,
// vscode.Disposable
// );


}

// getNonce generates a new random string each time ext is used to prevent external injection of foreign code into the html
Expand Down
104 changes: 90 additions & 14 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,103 @@ class Parser {
// input: ast.program.body
// output: boolean
getCallee(body) {
// does useStore count as a client component functionality?
const hooksArray = ['useState', 'useContext', 'useRef', 'useImperativeHandle', 'useNavigate', 'useLayoutEffect', 'useInsertionEffect', 'useMemo', 'useCallback', 'useTransition', 'useDeferredValue', 'useEffect', 'useReducer', 'useDispatch', 'useActions', 'useSelector', 'bindActionCreators'];
const defaultErr = (err,) => {
return {
method: 'Error in getCallee method of Parser:',
log: err,
}
};

//! console.log('ast.program.body', body);
// console.log('ast.program.body', body);
const bodyCallee = body.filter((item) => item.type === 'VariableDeclaration');
const calleeArr = bodyCallee[0].declarations[0].init.body.body // gives us an array of callee nodes

console.log('calleArr:', calleeArr);
for (let i = 0; i < calleeArr.length; i++) {
if (calleeArr[i].type === 'VariableDeclaration') {
if (hooksArray.includes(calleeArr[i].declarations[0].init.callee.name) || calleeArr[i].declarations[0].init.callee.name.startsWith('use')) {
return true;
if (bodyCallee.length === 0) return false;
// console.log('bodyCallee', bodyCallee);
// console.log('bodyCallee.length', bodyCallee.length)

const calleeHelper = (item) => {
const hooksObj = {
useState: 0,
useContext: 0,
useRef: 0,
useImperativeHandle: 0,
useNavigate: 0,
useLocation: 0,
useLayoutEffect: 0,
useInsertionEffect: 0,
useMemo: 0,
useCallback: 0,
useTransition: 0,
useDeferredValue: 0,
useEffect: 0,
useReducer: 0,
useDispatch: 0,
useActions: 0,
useSelector: 0,
bindActionCreators: 0,
}
if (item.type === 'VariableDeclaration') {
try {
let calleeName = item.declarations[0]?.init?.callee?.name;
if (hooksObj.hasOwnProperty(calleeName) || (typeof calleeName === 'string' && calleeName.startsWith('use'))) {
return true;
}
}
catch (err) {
const error = defaultErr(err);
console.error(error.method, '\n', error.log);
}
}
if (calleeArr[i].type === 'ExpressionStatement') {
if (hooksArray.includes(calleeArr[i].expression.callee.name) || calleeArr[i].expression.callee.name.startsWith('use')) {
return true;
else if (item.type === 'ExpressionStatement') {
try {
const calleeName = item.expression?.callee?.name;
if (calleeName === undefined) return false;
if (hooksObj.hasOwnProperty(calleeName) || (typeof calleeName === 'string' && calleeName.startsWith('use'))) {
return true;
}
}
catch (err) {
const error = defaultErr(err);
console.error(error.method, '\n', error.log);
}
}
return false;
}

if (bodyCallee.length === 1) {
const calleeArr = bodyCallee[0].declarations[0]?.init?.body?.body;
if (calleeArr === undefined) return false;

// console.log('calleArr:', calleeArr);
let checkTrue = false;
for (let i = 0; i < calleeArr.length; i++) {
if (checkTrue) return true;
checkTrue = calleeHelper(calleeArr[i]);
}
return checkTrue;
}
else if (bodyCallee.length > 1) {
let calleeArr;
for (let i = 0; i < bodyCallee.length; i++) {
try {
if (bodyCallee[i].declarations[0]?.init?.body?.body) {
calleeArr = bodyCallee[i].declarations[0].init.body.body;
console.log('calleeArr from body', calleeArr);
}
}
catch (err) {
const error = defaultErr(err);
console.error(error.method, '\n', error.log);
}
}

if (calleeArr === undefined) return false;
let checkTrue = false;
for (let i = 0; i < calleeArr.length; i++) {
if (checkTrue) return true;
checkTrue = calleeHelper(calleeArr[i]);
}
return checkTrue;
}
return false;
}

// Finds JSX React Components in current file
Expand Down
1 change: 1 addition & 0 deletions src/webview/Flow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const OverviewFlow = () => {
);

useEffect(() => {
// does not work currently
window.addEventListener('message', (e) => {
const msg = e.data;
switch (msg.type) {
Expand Down