@reteps/tree-sitter-htmlmustache 0.9.1 → 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.
- package/browser/out/browser/index.d.ts +11 -2
- package/browser/out/browser/index.d.ts.map +1 -1
- package/browser/out/browser/index.mjs +25 -20
- package/browser/out/browser/index.mjs.map +2 -2
- package/browser/out/core/configSchema.d.ts +8 -0
- package/browser/out/core/configSchema.d.ts.map +1 -1
- package/browser/out/core/customRuleFilter.d.ts +14 -0
- package/browser/out/core/customRuleFilter.d.ts.map +1 -0
- package/browser/out/core/selectorMatcher.d.ts +5 -1
- package/browser/out/core/selectorMatcher.d.ts.map +1 -1
- package/cli/out/main.js +64 -29
- package/package.json +1 -1
- package/src/browser/browser.test.ts +14 -0
- package/src/browser/index.ts +11 -2
- package/src/core/configSchema.ts +16 -0
- package/src/core/customRuleFilter.ts +32 -0
- package/src/core/selectorMatcher.ts +44 -24
|
@@ -9,8 +9,17 @@ import type { PrettierLike } from '../core/formatting/embedded.js';
|
|
|
9
9
|
import type { Diagnostic } from '../core/diagnostic.js';
|
|
10
10
|
import type { HtmlMustacheConfig, RulesConfig, RuleSeverity, CustomRule as CustomRuleType } from '../core/configSchema.js';
|
|
11
11
|
import type { CustomCodeTagConfig } from '../core/customCodeTags.js';
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* `include`/`exclude` on custom rules are stripped from the browser surface:
|
|
14
|
+
* the browser API has no filesystem path to match against, so those fields
|
|
15
|
+
* would silently do nothing. Users who share a `.htmlmustache.jsonc` config
|
|
16
|
+
* between the CLI and a web playground should strip them before passing, or
|
|
17
|
+
* let TypeScript catch the mismatch.
|
|
18
|
+
*/
|
|
19
|
+
export type CustomRule = Omit<CustomRuleType, 'include' | 'exclude'>;
|
|
20
|
+
export type Config = Omit<HtmlMustacheConfig, 'include' | 'exclude' | 'customRules'> & {
|
|
21
|
+
customRules?: CustomRule[];
|
|
22
|
+
};
|
|
14
23
|
export type CustomTag = CustomCodeTagConfig;
|
|
15
24
|
export type { RulesConfig, RuleSeverity, PrettierLike, Diagnostic };
|
|
16
25
|
export type LocateWasm = string | ((filename: string) => string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,UAAU,IAAI,cAAc,EAC7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,UAAU,IAAI,cAAc,EAC7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;AACrE,MAAM,MAAM,MAAM,GAChB,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,SAAS,GAAG,aAAa,CAAC,GAC7D;IAAE,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC;AACnC,MAAM,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AAEpE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,UAAU,EAAE,UAAU,CAAC;IACvB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE,CAAC;IACpD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAChF;AAED,kDAAkD;AAClD,eAAO,MAAM,cAAc,EAAE,MAAgD,CAAC;AAc9E;;;GAGG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiD7E"}
|
|
@@ -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
|
|
1692
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
1847
|
-
|
|
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
|
}
|