Skip to content

Commit 10cb04b

Browse files
author
Rocky Lin
committed
useState-useContext
1 parent b886d12 commit 10cb04b

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

package/astParser.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-inner-declarations */
12
const acorn = require('acorn'); // javascript parser
23
// eslint-disable-next-line import/newline-after-import
34
const jsx = require('acorn-jsx');
@@ -14,6 +15,22 @@ module.exports = elementType => {
1415
ast = ast.body;
1516
const statements = [];
1617

18+
function stMent(st) {
19+
st.forEach((el, i) => {
20+
if (el.match(/_use/)) hookState[el] = statements[i + 2];
21+
});
22+
}
23+
24+
function hookDeclare(astVal) {
25+
astVal.forEach(elem => {
26+
if (elem.type === 'VariableDeclaration') {
27+
elem.declarations.forEach(decClar => {
28+
statements.push(decClar.id.name);
29+
});
30+
}
31+
});
32+
}
33+
1734
// handle useState useContext
1835
if (ast[0].expression.body.body) {
1936
ast = ast[0].expression.body.body;
@@ -33,22 +50,5 @@ module.exports = elementType => {
3350
});
3451
}
3552
}
36-
37-
function stMent(st) {
38-
st.forEach((el, i) => {
39-
if (el.match(/_use/)) hookState[el] = statements[i + 2];
40-
});
41-
}
42-
43-
function hookDeclare(astVal) {
44-
astVal.forEach(elem => {
45-
if (elem.type === 'VariableDeclaration') {
46-
elem.declarations.forEach(decClar => {
47-
statements.push(decClar.id.name);
48-
});
49-
}
50-
});
51-
}
52-
5353
return hookState;
5454
};

0 commit comments

Comments
 (0)