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 ast = await exports.parseCode(source, options);
|
||||||
const buildFiles = [];
|
const buildFiles = [];
|
||||||
const configs = [];
|
const configs = [];
|
||||||
const hookBases = [];
|
|
||||||
const hookImplementations = [];
|
const hookImplementations = [];
|
||||||
const hookInvocations = [];
|
const hookInvocations = [];
|
||||||
const todos = [];
|
const todos = [];
|
||||||
|
@ -99,7 +98,6 @@ exports.parseNormalSource = async (path, source, root, request, options) => {
|
||||||
return {
|
return {
|
||||||
buildFiles,
|
buildFiles,
|
||||||
config: configs,
|
config: configs,
|
||||||
hookBases,
|
|
||||||
hookImplementations,
|
hookImplementations,
|
||||||
hookInvocations,
|
hookInvocations,
|
||||||
todos,
|
todos,
|
||||||
|
|
|
@ -24,6 +24,29 @@ function visitProperties(properties, fn) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test Flecks.hooks(require.context(...))
|
||||||
|
function testRight(right, fn) {
|
||||||
|
if (isCallExpression(right)) {
|
||||||
|
if (isMemberExpression(right.callee)) {
|
||||||
|
if (
|
||||||
|
isIdentifier(right.callee.object) && 'Flecks' === right.callee.object.name
|
||||||
|
&& isIdentifier(right.callee.property) && 'hooks' === right.callee.property.name
|
||||||
|
) {
|
||||||
|
if (isCallExpression(right.arguments[0])) {
|
||||||
|
if (
|
||||||
|
isIdentifier(right.arguments[0].callee.object)
|
||||||
|
&& 'require' === right.arguments[0].callee.object.name
|
||||||
|
&& isIdentifier(right.arguments[0].callee.property)
|
||||||
|
&& 'context' === right.arguments[0].callee.property.name
|
||||||
|
) {
|
||||||
|
fn(right.arguments[0].arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.hookBaseVisitor = (fn) => ({
|
exports.hookBaseVisitor = (fn) => ({
|
||||||
// exports.hooks = Flecks.hooks(require.context(...))
|
// exports.hooks = Flecks.hooks(require.context(...))
|
||||||
AssignmentExpression(path) {
|
AssignmentExpression(path) {
|
||||||
|
@ -31,39 +54,19 @@ exports.hookBaseVisitor = (fn) => ({
|
||||||
if (isMemberExpression(left)) {
|
if (isMemberExpression(left)) {
|
||||||
if (isIdentifier(left.object) && 'exports' === left.object.name) {
|
if (isIdentifier(left.object) && 'exports' === left.object.name) {
|
||||||
if (isIdentifier(left.property) && 'hooks' === left.property.name) {
|
if (isIdentifier(left.property) && 'hooks' === left.property.name) {
|
||||||
if (isCallExpression(right)) {
|
testRight(right, fn);
|
||||||
if (isMemberExpression(right.callee)) {
|
|
||||||
if (
|
|
||||||
isIdentifier(right.callee.object) && 'Flecks' === right.callee.object.name
|
|
||||||
&& isIdentifier(right.callee.property) && 'hooks' === right.callee.property.name
|
|
||||||
) {
|
|
||||||
if (isCallExpression(right.arguments[0])) {
|
|
||||||
if (
|
|
||||||
isIdentifier(right.arguments[0].callee.object)
|
|
||||||
&& 'require' === right.arguments[0].callee.object.name
|
|
||||||
&& isIdentifier(right.arguments[0].callee.property)
|
|
||||||
&& 'context' === right.arguments[0].callee.property.name
|
|
||||||
) {
|
|
||||||
fn(right.arguments[0].arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// export const hooks = Flecks.hooks(...)
|
// export const hooks = Flecks.hooks(require.context(...))
|
||||||
ExportNamedDeclaration(path) {
|
ExportNamedDeclaration(path) {
|
||||||
const {declaration} = path.node;
|
const {declaration} = path.node;
|
||||||
if (isVariableDeclaration(declaration)) {
|
if (isVariableDeclaration(declaration)) {
|
||||||
const {declarations} = declaration;
|
const {declarations} = declaration;
|
||||||
declarations.forEach((declarator) => {
|
declarations.forEach((declarator) => {
|
||||||
if ('hooks' === declarator.id.name) {
|
if ('hooks' === declarator.id.name) {
|
||||||
if (isObjectExpression(declarator.init)) {
|
testRight(declarator.init, fn);
|
||||||
visitProperties(declarator.init.properties, fn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user