@reteps/tree-sitter-htmlmustache 0.0.37 → 0.0.39
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 +54 -18
- package/grammar.js +4 -2
- package/package.json +1 -1
- package/src/grammar.json +10 -2
- package/src/node-types.json +4 -0
- package/src/parser.c +3696 -3571
- package/tree-sitter-htmlmustache.wasm +0 -0
package/cli/out/main.js
CHANGED
|
@@ -1739,29 +1739,33 @@ var ERROR_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
|
1739
1739
|
function collectErrors(tree, file) {
|
|
1740
1740
|
const errors = [];
|
|
1741
1741
|
const cursor = tree.walk();
|
|
1742
|
-
function visit() {
|
|
1742
|
+
function visit(insideMustacheSection) {
|
|
1743
1743
|
const node = cursor.currentNode;
|
|
1744
1744
|
const nodeType = cursor.nodeType;
|
|
1745
1745
|
if (ERROR_NODE_TYPES.has(nodeType) || cursor.nodeIsMissing) {
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1746
|
+
const skip = insideMustacheSection && nodeType === "html_erroneous_end_tag";
|
|
1747
|
+
if (!skip) {
|
|
1748
|
+
errors.push({
|
|
1749
|
+
file,
|
|
1750
|
+
line: node.startPosition.row + 1,
|
|
1751
|
+
column: node.startPosition.column + 1,
|
|
1752
|
+
endLine: node.endPosition.row + 1,
|
|
1753
|
+
endColumn: node.endPosition.column + 1,
|
|
1754
|
+
message: errorMessageForNode(nodeType, node),
|
|
1755
|
+
nodeText: node.text
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1755
1758
|
if (nodeType === "ERROR") return;
|
|
1756
1759
|
}
|
|
1760
|
+
const enteringMustacheSection = nodeType === "mustache_section" || nodeType === "mustache_inverted_section";
|
|
1757
1761
|
if (cursor.gotoFirstChild()) {
|
|
1758
1762
|
do {
|
|
1759
|
-
visit();
|
|
1763
|
+
visit(insideMustacheSection || enteringMustacheSection);
|
|
1760
1764
|
} while (cursor.gotoNextSibling());
|
|
1761
1765
|
cursor.gotoParent();
|
|
1762
1766
|
}
|
|
1763
1767
|
}
|
|
1764
|
-
visit();
|
|
1768
|
+
visit(false);
|
|
1765
1769
|
return errors;
|
|
1766
1770
|
}
|
|
1767
1771
|
function formatError(error, source) {
|
|
@@ -2664,6 +2668,10 @@ function hasImplicitEndTagsRecursive(node) {
|
|
|
2664
2668
|
}
|
|
2665
2669
|
return false;
|
|
2666
2670
|
}
|
|
2671
|
+
function isInlineContentNode(node) {
|
|
2672
|
+
if (node.type === "text") return node.text.trim().length > 0;
|
|
2673
|
+
return node.type === "mustache_interpolation" || node.type === "mustache_triple" || node.type === "mustache_partial";
|
|
2674
|
+
}
|
|
2667
2675
|
function isInTextFlow(node, index, nodes) {
|
|
2668
2676
|
if (index > 0) {
|
|
2669
2677
|
const prev = nodes[index - 1];
|
|
@@ -2679,6 +2687,21 @@ function isInTextFlow(node, index, nodes) {
|
|
|
2679
2687
|
}
|
|
2680
2688
|
return false;
|
|
2681
2689
|
}
|
|
2690
|
+
function hasAdjacentInlineContent(index, nodes) {
|
|
2691
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
2692
|
+
const n = nodes[i];
|
|
2693
|
+
if (n.type === "text" && n.text.trim().length === 0) continue;
|
|
2694
|
+
if (isInlineContentNode(n)) return true;
|
|
2695
|
+
break;
|
|
2696
|
+
}
|
|
2697
|
+
for (let i = index + 1; i < nodes.length; i++) {
|
|
2698
|
+
const n = nodes[i];
|
|
2699
|
+
if (n.type === "text" && n.text.trim().length === 0) continue;
|
|
2700
|
+
if (isInlineContentNode(n)) return true;
|
|
2701
|
+
break;
|
|
2702
|
+
}
|
|
2703
|
+
return false;
|
|
2704
|
+
}
|
|
2682
2705
|
function shouldHtmlElementStayInline(node, index, nodes) {
|
|
2683
2706
|
if (node.type !== "html_element") {
|
|
2684
2707
|
return false;
|
|
@@ -2686,6 +2709,9 @@ function shouldHtmlElementStayInline(node, index, nodes) {
|
|
|
2686
2709
|
if (isInTextFlow(node, index, nodes)) {
|
|
2687
2710
|
return true;
|
|
2688
2711
|
}
|
|
2712
|
+
if (hasAdjacentInlineContent(index, nodes)) {
|
|
2713
|
+
return true;
|
|
2714
|
+
}
|
|
2689
2715
|
if (index > 0) {
|
|
2690
2716
|
const prev = nodes[index - 1];
|
|
2691
2717
|
if (prev.type === "html_element" && isInTextFlow(prev, index - 1, nodes)) {
|
|
@@ -3148,12 +3174,13 @@ function formatStartTag(node, context) {
|
|
|
3148
3174
|
}
|
|
3149
3175
|
attrParts.push(attrs[i]);
|
|
3150
3176
|
}
|
|
3177
|
+
const breakClosingBracket = isSelfClosing ? "/>" : ">";
|
|
3151
3178
|
return group(
|
|
3152
3179
|
concat([
|
|
3153
3180
|
text("<"),
|
|
3154
3181
|
text(tagNameText),
|
|
3155
3182
|
indent(concat([line, concat(attrParts)])),
|
|
3156
|
-
ifBreak(concat([hardline, text(
|
|
3183
|
+
ifBreak(concat([hardline, text(breakClosingBracket)]), text(closingBracket))
|
|
3157
3184
|
])
|
|
3158
3185
|
);
|
|
3159
3186
|
}
|
|
@@ -3263,10 +3290,10 @@ function formatBlockChildren(nodes, context) {
|
|
|
3263
3290
|
}
|
|
3264
3291
|
const rawText = context.document.getText().slice(ignoreRegionStartIndex, node.startIndex).replace(/^\n/, "").replace(/\n$/, "");
|
|
3265
3292
|
if (rawText.length > 0) {
|
|
3266
|
-
lines.push({ doc: text(rawText), blankLineBefore: false });
|
|
3293
|
+
lines.push({ doc: text(rawText), blankLineBefore: false, rawLine: true });
|
|
3267
3294
|
}
|
|
3268
3295
|
const commentText = node.type === "mustache_comment" ? mustacheText(node.text, context) : node.text;
|
|
3269
|
-
lines.push({ doc: text(commentText), blankLineBefore: false });
|
|
3296
|
+
lines.push({ doc: text(commentText), blankLineBefore: false, rawLine: true });
|
|
3270
3297
|
inIgnoreRegion = false;
|
|
3271
3298
|
ignoreRegionStartIndex = -1;
|
|
3272
3299
|
lastNodeEnd = node.endIndex;
|
|
@@ -3433,7 +3460,12 @@ function formatBlockChildren(nodes, context) {
|
|
|
3433
3460
|
}
|
|
3434
3461
|
} else {
|
|
3435
3462
|
if (node.type === "text" && typeof formatted === "string") {
|
|
3436
|
-
|
|
3463
|
+
const words = textWords(formatted);
|
|
3464
|
+
if (words.length > 0) {
|
|
3465
|
+
currentLine.push(...words);
|
|
3466
|
+
} else if (node.text.trim() === "" && currentLine.length > 0) {
|
|
3467
|
+
currentLine.push(line);
|
|
3468
|
+
}
|
|
3437
3469
|
} else {
|
|
3438
3470
|
currentLine.push(formatted);
|
|
3439
3471
|
}
|
|
@@ -3445,7 +3477,7 @@ function formatBlockChildren(nodes, context) {
|
|
|
3445
3477
|
const lastNode = nodes[nodes.length - 1];
|
|
3446
3478
|
const rawText = context.document.getText().slice(ignoreRegionStartIndex, lastNode.endIndex).replace(/^\n/, "");
|
|
3447
3479
|
if (rawText.length > 0) {
|
|
3448
|
-
lines.push({ doc: text(rawText), blankLineBefore: false });
|
|
3480
|
+
lines.push({ doc: text(rawText), blankLineBefore: false, rawLine: true });
|
|
3449
3481
|
}
|
|
3450
3482
|
}
|
|
3451
3483
|
if (currentLine.length > 0) {
|
|
@@ -3463,7 +3495,11 @@ function formatBlockChildren(nodes, context) {
|
|
|
3463
3495
|
if (lines[i].blankLineBefore) {
|
|
3464
3496
|
parts.push("\n");
|
|
3465
3497
|
}
|
|
3466
|
-
|
|
3498
|
+
if (lines[i].rawLine) {
|
|
3499
|
+
parts.push("\n");
|
|
3500
|
+
} else {
|
|
3501
|
+
parts.push(hardline);
|
|
3502
|
+
}
|
|
3467
3503
|
}
|
|
3468
3504
|
parts.push(lines[i].doc);
|
|
3469
3505
|
}
|
package/grammar.js
CHANGED
|
@@ -281,12 +281,12 @@ module.exports = grammar({
|
|
|
281
281
|
_attribute_value_no_double_quote: ($) =>
|
|
282
282
|
choice(
|
|
283
283
|
$._mustache_node,
|
|
284
|
-
alias($.
|
|
284
|
+
alias($._html_attribute_value_no_double_quote, $.text),
|
|
285
285
|
),
|
|
286
286
|
_attribute_value_no_single_quote: ($) =>
|
|
287
287
|
choice(
|
|
288
288
|
$._mustache_node,
|
|
289
|
-
alias($.
|
|
289
|
+
alias($._html_attribute_value_no_single_quote, $.text),
|
|
290
290
|
),
|
|
291
291
|
_mustache_section_no_single_quote: ($) =>
|
|
292
292
|
seq(
|
|
@@ -370,6 +370,7 @@ module.exports = grammar({
|
|
|
370
370
|
),
|
|
371
371
|
_mustache_node_no_single_quote: ($) =>
|
|
372
372
|
choice(
|
|
373
|
+
$.mustache_triple,
|
|
373
374
|
$.mustache_interpolation,
|
|
374
375
|
alias($._mustache_comment_no_single_quote, $.mustache_comment),
|
|
375
376
|
alias($._mustache_partial_no_single_quote, $.mustache_partial),
|
|
@@ -381,6 +382,7 @@ module.exports = grammar({
|
|
|
381
382
|
),
|
|
382
383
|
_mustache_node_no_double_quote: ($) =>
|
|
383
384
|
choice(
|
|
385
|
+
$.mustache_triple,
|
|
384
386
|
$.mustache_interpolation,
|
|
385
387
|
alias($._mustache_comment_no_double_quote, $.mustache_comment),
|
|
386
388
|
alias($._mustache_partial_no_double_quote, $.mustache_partial),
|
package/package.json
CHANGED
package/src/grammar.json
CHANGED
|
@@ -942,7 +942,7 @@
|
|
|
942
942
|
"type": "ALIAS",
|
|
943
943
|
"content": {
|
|
944
944
|
"type": "SYMBOL",
|
|
945
|
-
"name": "
|
|
945
|
+
"name": "_html_attribute_value_no_double_quote"
|
|
946
946
|
},
|
|
947
947
|
"named": true,
|
|
948
948
|
"value": "text"
|
|
@@ -960,7 +960,7 @@
|
|
|
960
960
|
"type": "ALIAS",
|
|
961
961
|
"content": {
|
|
962
962
|
"type": "SYMBOL",
|
|
963
|
-
"name": "
|
|
963
|
+
"name": "_html_attribute_value_no_single_quote"
|
|
964
964
|
},
|
|
965
965
|
"named": true,
|
|
966
966
|
"value": "text"
|
|
@@ -1158,6 +1158,10 @@
|
|
|
1158
1158
|
"_mustache_node_no_single_quote": {
|
|
1159
1159
|
"type": "CHOICE",
|
|
1160
1160
|
"members": [
|
|
1161
|
+
{
|
|
1162
|
+
"type": "SYMBOL",
|
|
1163
|
+
"name": "mustache_triple"
|
|
1164
|
+
},
|
|
1161
1165
|
{
|
|
1162
1166
|
"type": "SYMBOL",
|
|
1163
1167
|
"name": "mustache_interpolation"
|
|
@@ -1203,6 +1207,10 @@
|
|
|
1203
1207
|
"_mustache_node_no_double_quote": {
|
|
1204
1208
|
"type": "CHOICE",
|
|
1205
1209
|
"members": [
|
|
1210
|
+
{
|
|
1211
|
+
"type": "SYMBOL",
|
|
1212
|
+
"name": "mustache_triple"
|
|
1213
|
+
},
|
|
1206
1214
|
{
|
|
1207
1215
|
"type": "SYMBOL",
|
|
1208
1216
|
"name": "mustache_interpolation"
|