@@ -7,11 +7,10 @@ const JSXParser = acorn.Parser.extend(jsx());
7
7
function getHookNames ( ast ) {
8
8
// Initialize empty object to store the setters and getter
9
9
const hookState = { } ;
10
+ // All module exports will always start off as a single 'FunctionDeclaration' type
10
11
while ( Object . hasOwnProperty . call ( ast , 'body' ) ) {
11
- // All module exports will always start off as a single 'FunctionDeclaration' type
12
12
// Traverse down .body once before invoking parsing logic and will loop through any .body after
13
13
ast = ast . body ;
14
- console . log ( 'AST Tree' , ast ) ;
15
14
// Iterate through AST of every function declaration
16
15
// Check within each function declaration if there are hook declarations
17
16
ast . forEach ( functionDec => {
@@ -39,16 +38,16 @@ function getHookNames(ast) {
39
38
40
39
module . exports = file => {
41
40
// Create an empty object to allow all invocations of getHookNames to consolidate
42
- let hookNames = { } ;
41
+ let allHookNames = { } ;
43
42
const ast = JSXParser . parse ( file ) ;
44
- console . log ( 'Original File' , file . toString ( ) ) ;
45
- console . log ( 'Original AST' , ast ) ;
43
+ // console.log('Original File', file.toString());
44
+ // console.log('Original AST', ast);
46
45
// Upsert any new/updated {_hookType#: hookName} pairs
47
- hookNames = {
48
- ...hookNames ,
46
+ allHookNames = {
47
+ ...allHookNames ,
49
48
...getHookNames ( ast ) ,
50
49
} ;
51
50
52
51
// Return the object with setters and getters
53
- return hookNames ;
52
+ return allHookNames ;
54
53
} ;
0 commit comments