@reteps/tree-sitter-htmlmustache 0.4.1 → 0.4.2

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.
Files changed (2) hide show
  1. package/cli/out/main.js +43 -6
  2. package/package.json +1 -1
package/cli/out/main.js CHANGED
@@ -2813,13 +2813,50 @@ function formatMustacheSection(node, context) {
2813
2813
  parts.push(text(mustacheText(beginNode.text, context)));
2814
2814
  }
2815
2815
  const hasImplicit = hasImplicitEndTags(contentNodes);
2816
- const isStaircase = !hasImplicit && contentNodes.length > 0 && contentNodes.every((n) => n.type === "html_erroneous_end_tag");
2817
- if (isStaircase) {
2818
- const E = contentNodes.length;
2819
- for (let i = 0; i < E; i++) {
2820
- const formatted = formatNode(contentNodes[i], context);
2821
- parts.push(indentN(concat([hardline, formatted]), E - i));
2816
+ const erroneousCount = contentNodes.filter((n) => n.type === "html_erroneous_end_tag").length;
2817
+ const hasStaircase = !hasImplicit && erroneousCount > 0;
2818
+ if (hasStaircase) {
2819
+ let virtualDepth = erroneousCount - 1;
2820
+ const groupNodes = [];
2821
+ let lastNodeEnd = -1;
2822
+ let pendingBlankLine = false;
2823
+ let groupBlankLine = false;
2824
+ const emitGroup = () => {
2825
+ if (groupNodes.length === 0) return;
2826
+ const formatted = formatBlockChildren(groupNodes, context);
2827
+ if (hasDocContent(formatted)) {
2828
+ if (groupBlankLine) parts.push("\n");
2829
+ const depth = Math.max(0, virtualDepth + 1);
2830
+ parts.push(depth > 0 ? indentN(concat([hardline, formatted]), depth) : concat([hardline, formatted]));
2831
+ }
2832
+ groupNodes.length = 0;
2833
+ groupBlankLine = false;
2834
+ };
2835
+ for (const node2 of contentNodes) {
2836
+ if (lastNodeEnd >= 0 && node2.startIndex > lastNodeEnd) {
2837
+ const gap = context.document.getText().slice(lastNodeEnd, node2.startIndex);
2838
+ if ((gap.match(/\n/g) || []).length >= 2) {
2839
+ pendingBlankLine = true;
2840
+ }
2841
+ }
2842
+ if (node2.type === "html_erroneous_end_tag") {
2843
+ emitGroup();
2844
+ if (pendingBlankLine) parts.push("\n");
2845
+ pendingBlankLine = false;
2846
+ const formatted = formatNode(node2, context);
2847
+ const depth = Math.max(0, virtualDepth);
2848
+ parts.push(depth > 0 ? indentN(concat([hardline, formatted]), depth) : concat([hardline, formatted]));
2849
+ virtualDepth--;
2850
+ } else {
2851
+ if (groupNodes.length === 0) {
2852
+ groupBlankLine = pendingBlankLine;
2853
+ pendingBlankLine = false;
2854
+ }
2855
+ groupNodes.push(node2);
2856
+ }
2857
+ lastNodeEnd = node2.endIndex;
2822
2858
  }
2859
+ emitGroup();
2823
2860
  parts.push(hardline);
2824
2861
  } else {
2825
2862
  const formattedContent = formatBlockChildren(contentNodes, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reteps/tree-sitter-htmlmustache",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "HTML with Mustache/Handlebars template syntax grammar for tree-sitter",
5
5
  "repository": {
6
6
  "type": "git",