File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const JSXParser = acorn.Parser.extend(jsx());
5
5
6
6
// Helper function to recursively traverse AST of a specified component for all hook declarations
7
7
function getHookNames ( ast ) {
8
+ // Initialize empty object to store the setters and getter
8
9
const hookState = { } ;
9
10
while ( Object . hasOwnProperty . call ( ast , 'body' ) ) {
10
11
// All module exports will always start off as a single 'FunctionDeclaration' type
@@ -37,9 +38,16 @@ function getHookNames(ast) {
37
38
}
38
39
39
40
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 = { } ;
41
43
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
+ } ;
43
51
44
52
// Return the object with setters and getters
45
53
return hookNames ;
You can’t perform that action at this time.
0 commit comments