diff --git a/lib/binding_web/binding.js b/lib/binding_web/binding.js index c70dcdab..82f72046 100644 --- a/lib/binding_web/binding.js +++ b/lib/binding_web/binding.js @@ -855,8 +855,7 @@ class Language { if (steps[1].type !== 'capture') throw new Error( `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}"` ); - let eqMatchAll = !operator.startsWith('any-'); - let eqIsPositive = isPositive; + matchAll = !operator.startsWith('any-'); if (steps[2].type === 'capture') { const captureName1 = steps[1].name; const captureName2 = steps[2].name; @@ -872,9 +871,9 @@ class Language { n1.text === n2.text : n1.text !== n2.text; }; - return eqMatchAll - ? nodes_1.every(n1 => nodes_2.some(n2 => compare(n1, n2, eqIsPositive))) - : nodes_1.some(n1 => nodes_2.some(n2 => compare(n1, n2, eqIsPositive))); + return matchAll + ? nodes_1.every(n1 => nodes_2.some(n2 => compare(n1, n2, isPositive))) + : nodes_1.some(n1 => nodes_2.some(n2 => compare(n1, n2, isPositive))); }); } else { captureName = steps[1].name; @@ -886,8 +885,8 @@ class Language { for (const c of captures) { if (c.name === captureName) nodes.push(c.node); } - let test = eqIsPositive ? matches : doesNotMatch; - return eqMatchAll + let test = isPositive ? matches : doesNotMatch; + return matchAll ? nodes.every(test) : nodes.some(test); }); @@ -910,8 +909,7 @@ class Language { ); captureName = steps[1].name; const regex = new RegExp(steps[2].value); - let matchIsPositive = isPositive; - let matchMatchAll = !operator.startsWith('any-'); + matchAll = !operator.startsWith('any-'); textPredicates[i].push(function (captures) { const nodes = []; for (const c of captures) { @@ -922,10 +920,10 @@ class Language { regex.test(text) : !regex.test(text); }; - if (nodes.length === 0) return !matchIsPositive; - return matchMatchAll - ? nodes.every(text => test(text, matchIsPositive)) - : nodes.some(text => test(text, matchIsPositive)) + if (nodes.length === 0) return !isPositive; + return matchAll + ? nodes.every(text => test(text, isPositive)) + : nodes.some(text => test(text, isPositive)) }); break;