From 1002d8c9d2ab23541f7b9a87be373d17bd922214 Mon Sep 17 00:00:00 2001 From: "Thomas.G" Date: Thu, 21 Dec 2023 21:56:21 +0100 Subject: [PATCH] refactor(probe): allow array of validateNode functions (#191) --- src/probes/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/probes/index.js b/src/probes/index.js index 0e2f649..df7cbe6 100644 --- a/src/probes/index.js +++ b/src/probes/index.js @@ -39,7 +39,7 @@ 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) { @@ -47,9 +47,15 @@ export function runOnProbes(node, analysis) { 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";