@reteps/tree-sitter-htmlmustache 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1685,11 +1685,16 @@ function hasDescendantMatch(node, selector) {
1685
1685
  }
1686
1686
  return false;
1687
1687
  }
1688
- function checkSelfNegations(node, negations, rootNode) {
1688
+ function checkSelfNegations(node, negations, rootNode, cursor) {
1689
1689
  for (const sel of negations) {
1690
1690
  for (const alt of sel) {
1691
- if (alt.length !== 1) continue;
1692
- if (nodeMatchesSegment(node, alt[0], rootNode)) return false;
1691
+ if (alt.length === 0) continue;
1692
+ const lastSegment = alt[alt.length - 1];
1693
+ if (!nodeMatchesSegment(node, lastSegment, rootNode, cursor)) continue;
1694
+ if (alt.length === 1) return false;
1695
+ if (checkPrefix(cursor, alt, alt.length - 2, lastSegment.combinator, rootNode)) {
1696
+ return false;
1697
+ }
1693
1698
  }
1694
1699
  }
1695
1700
  return true;
@@ -1700,10 +1705,10 @@ function matchesName(actual, segment) {
1700
1705
  if (segment.pathRegex) return segment.pathRegex.test(actual);
1701
1706
  return actual === segment.name;
1702
1707
  }
1703
- function nodeMatchesSegment(node, segment, rootNode) {
1708
+ function nodeMatchesSegment(node, segment, rootNode, cursor) {
1704
1709
  if (segment.rootOnly) {
1705
1710
  if (node !== rootNode) return false;
1706
- return checkDescendants(node, segment.descendantChecks) && checkSelfNegations(node, segment.selfNegations, rootNode);
1711
+ return checkDescendants(node, segment.descendantChecks) && checkSelfNegations(node, segment.selfNegations, rootNode, cursor);
1707
1712
  }
1708
1713
  const baseMatches = (() => {
1709
1714
  switch (segment.kind) {
@@ -1742,7 +1747,7 @@ function nodeMatchesSegment(node, segment, rootNode) {
1742
1747
  }
1743
1748
  })();
1744
1749
  if (!baseMatches) return false;
1745
- return checkSelfNegations(node, segment.selfNegations, rootNode);
1750
+ return checkSelfNegations(node, segment.selfNegations, rootNode, cursor);
1746
1751
  }
1747
1752
  function checkPrefix(cursor, segments, segIdx, stepCombinator, rootNode) {
1748
1753
  if (segIdx < 0) return true;
@@ -1751,16 +1756,16 @@ function checkPrefix(cursor, segments, segIdx, stepCombinator, rootNode) {
1751
1756
  for (let i = cursor.indexInSiblings - 1; i >= 0; i--) {
1752
1757
  const sib = cursor.siblings[i];
1753
1758
  if (!isMatchableNode(sib)) continue;
1754
- if (!nodeMatchesSegment(sib, segment, rootNode)) {
1755
- if (stepCombinator === "adjacent-sibling") return false;
1756
- continue;
1757
- }
1758
- const newCursor = {
1759
+ const sibCursor = {
1759
1760
  ancestors: cursor.ancestors,
1760
1761
  siblings: cursor.siblings,
1761
1762
  indexInSiblings: i
1762
1763
  };
1763
- if (checkPrefix(newCursor, segments, segIdx - 1, segment.combinator, rootNode)) return true;
1764
+ if (!nodeMatchesSegment(sib, segment, rootNode, sibCursor)) {
1765
+ if (stepCombinator === "adjacent-sibling") return false;
1766
+ continue;
1767
+ }
1768
+ if (checkPrefix(sibCursor, segments, segIdx - 1, segment.combinator, rootNode)) return true;
1764
1769
  if (stepCombinator === "adjacent-sibling") return false;
1765
1770
  }
1766
1771
  return false;
@@ -1777,13 +1782,13 @@ function checkPrefix(cursor, segments, segIdx, stepCombinator, rootNode) {
1777
1782
  if (!matchesName(entry.name, segment)) return false;
1778
1783
  if (segment.kind === "html" && !checkAttributes(entry.node, segment.attributes)) return false;
1779
1784
  if (!checkDescendants(entry.node, segment.descendantChecks)) return false;
1780
- if (!checkSelfNegations(entry.node, segment.selfNegations, rootNode)) return false;
1781
- const newCursor = {
1785
+ const ancestorCursor = {
1782
1786
  ancestors: cursor.ancestors.slice(0, a),
1783
1787
  siblings: entry.siblings,
1784
1788
  indexInSiblings: entry.indexInSiblings
1785
1789
  };
1786
- return checkPrefix(newCursor, segments, segIdx - 1, segment.combinator, rootNode);
1790
+ if (!checkSelfNegations(entry.node, segment.selfNegations, rootNode, ancestorCursor)) return false;
1791
+ return checkPrefix(ancestorCursor, segments, segIdx - 1, segment.combinator, rootNode);
1787
1792
  }
1788
1793
  return false;
1789
1794
  }
@@ -1793,13 +1798,13 @@ function checkPrefix(cursor, segments, segIdx, stepCombinator, rootNode) {
1793
1798
  if (!matchesName(entry.name, segment)) continue;
1794
1799
  if (segment.kind === "html" && !checkAttributes(entry.node, segment.attributes)) continue;
1795
1800
  if (!checkDescendants(entry.node, segment.descendantChecks)) continue;
1796
- if (!checkSelfNegations(entry.node, segment.selfNegations, rootNode)) continue;
1797
- const newCursor = {
1801
+ const ancestorCursor = {
1798
1802
  ancestors: cursor.ancestors.slice(0, a),
1799
1803
  siblings: entry.siblings,
1800
1804
  indexInSiblings: entry.indexInSiblings
1801
1805
  };
1802
- if (checkPrefix(newCursor, segments, segIdx - 1, segment.combinator, rootNode)) return true;
1806
+ if (!checkSelfNegations(entry.node, segment.selfNegations, rootNode, ancestorCursor)) continue;
1807
+ if (checkPrefix(ancestorCursor, segments, segIdx - 1, segment.combinator, rootNode)) return true;
1803
1808
  }
1804
1809
  return false;
1805
1810
  }
@@ -1843,8 +1848,8 @@ function matchAlternative(rootNode, segments, rootSiblings, rootIndexInSiblings)
1843
1848
  const results = [];
1844
1849
  const lastSegment = segments[segments.length - 1];
1845
1850
  function walk(node, ancestors, siblings, indexInSiblings) {
1846
- if (nodeMatchesSegment(node, lastSegment, rootNode)) {
1847
- const cursor = { ancestors, siblings, indexInSiblings };
1851
+ const cursor = { ancestors, siblings, indexInSiblings };
1852
+ if (nodeMatchesSegment(node, lastSegment, rootNode, cursor)) {
1848
1853
  if (segments.length === 1 || checkPrefix(cursor, segments, segments.length - 2, lastSegment.combinator, rootNode)) {
1849
1854
  results.push(getReportNode(node, rootNode));
1850
1855
  }