Skip to content

Commit c8b4d79

Browse files
committed
allow hookNames to be upserted with new hook information upon each recursive call
1 parent 1ac2e67 commit c8b4d79

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

package/astParser.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const JSXParser = acorn.Parser.extend(jsx());
55

66
// Helper function to recursively traverse AST of a specified component for all hook declarations
77
function getHookNames(ast) {
8+
// Initialize empty object to store the setters and getter
89
const hookState = {};
910
while (Object.hasOwnProperty.call(ast, 'body')) {
1011
// All module exports will always start off as a single 'FunctionDeclaration' type
@@ -37,9 +38,16 @@ function getHookNames(ast) {
3738
}
3839

3940
module.exports = file => {
40-
// Initialize empty object to store the setters and getter
41+
// Create an empty object to allow all invocations of getHookNames to consolidate
42+
let hookNames = {};
4143
const ast = JSXParser.parse(file);
42-
const hookNames = getHookNames(ast);
44+
console.log('Original File', file.toString());
45+
console.log('Original AST', ast);
46+
// Upsert any new/updated {_hookType#: hookName} pairs
47+
hookNames = {
48+
...hookNames,
49+
...getHookNames(ast),
50+
};
4351

4452
// Return the object with setters and getters
4553
return hookNames;

0 commit comments

Comments
 (0)