@reteps/tree-sitter-htmlmustache 0.0.40 → 0.1.0
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/cli/out/main.js +84 -0
- package/package.json +1 -1
package/cli/out/main.js
CHANGED
|
@@ -1903,6 +1903,78 @@ function validateBalance(events, condition) {
|
|
|
1903
1903
|
}
|
|
1904
1904
|
return errors;
|
|
1905
1905
|
}
|
|
1906
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
1907
|
+
"area",
|
|
1908
|
+
"base",
|
|
1909
|
+
"basefont",
|
|
1910
|
+
"bgsound",
|
|
1911
|
+
"br",
|
|
1912
|
+
"col",
|
|
1913
|
+
"command",
|
|
1914
|
+
"embed",
|
|
1915
|
+
"frame",
|
|
1916
|
+
"hr",
|
|
1917
|
+
"image",
|
|
1918
|
+
"img",
|
|
1919
|
+
"input",
|
|
1920
|
+
"isindex",
|
|
1921
|
+
"keygen",
|
|
1922
|
+
"link",
|
|
1923
|
+
"menuitem",
|
|
1924
|
+
"meta",
|
|
1925
|
+
"nextid",
|
|
1926
|
+
"param",
|
|
1927
|
+
"source",
|
|
1928
|
+
"track",
|
|
1929
|
+
"wbr"
|
|
1930
|
+
]);
|
|
1931
|
+
var OPTIONAL_END_TAG_ELEMENTS = /* @__PURE__ */ new Set([
|
|
1932
|
+
"li",
|
|
1933
|
+
"dt",
|
|
1934
|
+
"dd",
|
|
1935
|
+
"p",
|
|
1936
|
+
"colgroup",
|
|
1937
|
+
"rb",
|
|
1938
|
+
"rt",
|
|
1939
|
+
"rp",
|
|
1940
|
+
"rtc",
|
|
1941
|
+
"optgroup",
|
|
1942
|
+
"option",
|
|
1943
|
+
"tr",
|
|
1944
|
+
"td",
|
|
1945
|
+
"th",
|
|
1946
|
+
"thead",
|
|
1947
|
+
"tbody",
|
|
1948
|
+
"tfoot",
|
|
1949
|
+
"caption",
|
|
1950
|
+
"html",
|
|
1951
|
+
"head",
|
|
1952
|
+
"body"
|
|
1953
|
+
]);
|
|
1954
|
+
function checkUnclosedTags(rootNode) {
|
|
1955
|
+
const errors = [];
|
|
1956
|
+
function visit(node) {
|
|
1957
|
+
if (node.type === "html_element") {
|
|
1958
|
+
const hasEndTag = node.children.some((c) => c.type === "html_end_tag");
|
|
1959
|
+
const hasForcedEnd = node.children.some((c) => c.type === "html_forced_end_tag");
|
|
1960
|
+
if (!hasEndTag && !hasForcedEnd) {
|
|
1961
|
+
const tagName = getTagName(node);
|
|
1962
|
+
if (tagName && !VOID_ELEMENTS.has(tagName) && !OPTIONAL_END_TAG_ELEMENTS.has(tagName)) {
|
|
1963
|
+
const startTag = node.children.find((c) => c.type === "html_start_tag");
|
|
1964
|
+
errors.push({
|
|
1965
|
+
node: startTag ?? node,
|
|
1966
|
+
message: `Unclosed HTML tag: <${tagName}>`
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
for (const child of node.children) {
|
|
1972
|
+
visit(child);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
visit(rootNode);
|
|
1976
|
+
return errors;
|
|
1977
|
+
}
|
|
1906
1978
|
var MAX_SECTION_NAMES = 15;
|
|
1907
1979
|
function checkHtmlBalance(rootNode) {
|
|
1908
1980
|
const rawItems = extractFromNode(rootNode);
|
|
@@ -1987,6 +2059,18 @@ function collectErrors(tree, file) {
|
|
|
1987
2059
|
nodeText: error.node.text
|
|
1988
2060
|
});
|
|
1989
2061
|
}
|
|
2062
|
+
const unclosedErrors = checkUnclosedTags(rootNode);
|
|
2063
|
+
for (const error of unclosedErrors) {
|
|
2064
|
+
errors.push({
|
|
2065
|
+
file,
|
|
2066
|
+
line: error.node.startPosition.row + 1,
|
|
2067
|
+
column: error.node.startPosition.column + 1,
|
|
2068
|
+
endLine: error.node.endPosition.row + 1,
|
|
2069
|
+
endColumn: error.node.endPosition.column + 1,
|
|
2070
|
+
message: error.message,
|
|
2071
|
+
nodeText: error.node.text
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
1990
2074
|
return errors;
|
|
1991
2075
|
}
|
|
1992
2076
|
function formatError(error, source) {
|