Skip to content

Commit

Permalink
refactor(probe): allow array of validateNode functions (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxken authored Dec 21, 2023
1 parent 64b8350 commit 1002d8c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/probes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,23 @@ const kListOfProbes = [
const kSymBreak = Symbol.for("breakWalk");
const kSymSkip = Symbol.for("skipWalk");

export function runOnProbes(node, analysis) {
export function runOnProbes(node, sourceFile) {
const breakedGroups = new Set();

for (const probe of kListOfProbes) {
if (breakedGroups.has(probe.breakGroup)) {
continue;
}

const [isMatching, data = null] = probe.validateNode(node, analysis);
if (isMatching) {
const result = probe.main(node, { analysis, data });
const validationFns = Array.isArray(probe.validateNode) ?
probe.validateNode : [probe.validateNode];
for (const validateNode of validationFns) {
const [isMatching, data = null] = validateNode(node, sourceFile);
if (!isMatching) {
continue;
}

const result = probe.main(node, { analysis: sourceFile, data });

if (result === kSymSkip) {
return "skip";
Expand Down

0 comments on commit 1002d8c

Please sign in to comment.