Skip to content

Commit 1ac2e67

Browse files
committed
refactored astParser.js and introduced getHookNames function to clean up module.exports
1 parent 9d316d2 commit 1ac2e67

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

package/astParser.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ const jsx = require('acorn-jsx');
33

44
const JSXParser = acorn.Parser.extend(jsx());
55

6-
const hookState = {};
7-
8-
module.exports = file => {
9-
// Initialize empty object to store the setters and getter
10-
let ast = JSXParser.parse(file);
6+
// Helper function to recursively traverse AST of a specified component for all hook declarations
7+
function getHookNames(ast) {
8+
const hookState = {};
119
while (Object.hasOwnProperty.call(ast, 'body')) {
1210
// All module exports will always start off as a single 'FunctionDeclaration' type
1311
// Traverse down .body once before invoking parsing logic and will loop through any .body after
@@ -35,6 +33,14 @@ module.exports = file => {
3533
}
3634
});
3735
}
38-
// Return the object with setters and getters
3936
return hookState;
37+
}
38+
39+
module.exports = file => {
40+
// Initialize empty object to store the setters and getter
41+
const ast = JSXParser.parse(file);
42+
const hookNames = getHookNames(ast);
43+
44+
// Return the object with setters and getters
45+
return hookNames;
4046
};

package/linkFiber.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,6 @@ module.exports = (snap, mode) => {
147147
// const testFunction = consoleLoggerTest('Hello from reactime');
148148
// return testFunction;
149149
// }
150+
return "This is reactime's return statement";
150151
};
151152
};

0 commit comments

Comments
 (0)