Skip to content

Commit c3827a1

Browse files
changes reflect updates to support useEffect and context API
1 parent 85e7716 commit c3827a1

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

package/astParser.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,34 @@ module.exports = elementType => {
1111
// All module exports will always start off as a single 'FunctionDeclaration' type
1212
while (Object.hasOwnProperty.call(ast, 'body')) {
1313
// Traverse down .body once before invoking parsing logic and will loop through any .body after
14-
ast = ast.body;
14+
// depending on the type of state mgmt, ast will have varying levels where
15+
// body array appears in the hierarchy. console.log(ast) on various apps to see this.
16+
if (ast.body[0].expression) {
17+
ast = ast.body[0].expression.body.body;
18+
} else {
19+
ast = ast.body[0].body.body;
20+
}
1521
// Iterate through AST of every function declaration
1622
// Check within each function declaration if there are hook declarations
17-
ast.forEach(functionDec => {
18-
const { body } = functionDec.body;
19-
const statements = [];
20-
// Traverse through the function's funcDecs and Expression Statements
21-
body.forEach(program => {
22-
// Hook Declarations will only be under 'VariableDeclaration' type
23-
if (program.type === 'VariableDeclaration') {
24-
program.declarations.forEach(dec => {
25-
statements.push(dec.id.name);
26-
});
27-
}
28-
});
29-
// Iterate through the array and determine getter/setters based on pattern
30-
for (let i = 0; i < statements.length; i += 1) {
31-
if (statements[i].match(/_use/)) {
32-
hookState[statements[i]] = statements[i + 2];
33-
}
23+
// ast.forEach(functionDec => { // removed 11/6 to account for change on line 16
24+
// const { body } = functionDec.body; // removed 11/6 to account for change on line 16
25+
const statements = [];
26+
// Traverse through the function's funcDecs and Expression Statements
27+
ast.forEach(program => { // changed from body to ast 11/6 to account for change on line 16
28+
// Hook Declarations will only be under 'VariableDeclaration' type
29+
if (program.type === 'VariableDeclaration') {
30+
program.declarations.forEach(dec => {
31+
statements.push(dec.id.name);
32+
});
3433
}
3534
});
35+
// Iterate through the array and determine getter/setters based on pattern
36+
for (let i = 0; i < statements.length; i += 1) {
37+
if (statements[i].match(/_use/)) {
38+
hookState[statements[i]] = statements[i + 2];
39+
}
40+
}
41+
// });
3642
}
3743
return hookState;
3844
};

package/linkFiber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = (snap, mode) => {
7171
astHooks = Object.values(astHooks);
7272
// while memoizedState is truthy, save the value to the object
7373
while (memoizedState && memoizedState.queue) { // prevents useEffect from crashing on load
74-
if (memoizedState.next.queue === null) { // prevents double pushing snapshot updates
74+
if (memoizedState.next && memoizedState.next.queue === null) { // prevents double pushing snapshot updates
7575
changeUseState(memoizedState);
7676
}
7777
// memoized[astHooks[index]] = memoizedState.memoizedState;

0 commit comments

Comments
 (0)