fix: visitor and tests
This commit is contained in:
parent
477bb740e9
commit
696c0c885a
|
@ -30,7 +30,6 @@ exports.parseNormalSource = async (path, source, root, request, options) => {
|
|||
const ast = await exports.parseCode(source, options);
|
||||
const buildFiles = [];
|
||||
const configs = [];
|
||||
const hookBases = [];
|
||||
const hookImplementations = [];
|
||||
const hookInvocations = [];
|
||||
const todos = [];
|
||||
|
@ -99,7 +98,6 @@ exports.parseNormalSource = async (path, source, root, request, options) => {
|
|||
return {
|
||||
buildFiles,
|
||||
config: configs,
|
||||
hookBases,
|
||||
hookImplementations,
|
||||
hookInvocations,
|
||||
todos,
|
||||
|
|
|
@ -24,13 +24,8 @@ function visitProperties(properties, fn) {
|
|||
});
|
||||
}
|
||||
|
||||
exports.hookBaseVisitor = (fn) => ({
|
||||
// exports.hooks = Flecks.hooks(require.context(...))
|
||||
AssignmentExpression(path) {
|
||||
const {left, right} = path.node;
|
||||
if (isMemberExpression(left)) {
|
||||
if (isIdentifier(left.object) && 'exports' === left.object.name) {
|
||||
if (isIdentifier(left.property) && 'hooks' === left.property.name) {
|
||||
// Test Flecks.hooks(require.context(...))
|
||||
function testRight(right, fn) {
|
||||
if (isCallExpression(right)) {
|
||||
if (isMemberExpression(right.callee)) {
|
||||
if (
|
||||
|
@ -50,20 +45,28 @@ exports.hookBaseVisitor = (fn) => ({
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.hookBaseVisitor = (fn) => ({
|
||||
// exports.hooks = Flecks.hooks(require.context(...))
|
||||
AssignmentExpression(path) {
|
||||
const {left, right} = path.node;
|
||||
if (isMemberExpression(left)) {
|
||||
if (isIdentifier(left.object) && 'exports' === left.object.name) {
|
||||
if (isIdentifier(left.property) && 'hooks' === left.property.name) {
|
||||
testRight(right, fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
// export const hooks = Flecks.hooks(...)
|
||||
// export const hooks = Flecks.hooks(require.context(...))
|
||||
ExportNamedDeclaration(path) {
|
||||
const {declaration} = path.node;
|
||||
if (isVariableDeclaration(declaration)) {
|
||||
const {declarations} = declaration;
|
||||
declarations.forEach((declarator) => {
|
||||
if ('hooks' === declarator.id.name) {
|
||||
if (isObjectExpression(declarator.init)) {
|
||||
visitProperties(declarator.init.properties, fn);
|
||||
}
|
||||
testRight(declarator.init, fn);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user