@reteps/tree-sitter-htmlmustache 0.0.37 → 0.0.38

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 +38 -6
  2. package/package.json +1 -1
package/cli/out/main.js CHANGED
@@ -2664,6 +2664,10 @@ function hasImplicitEndTagsRecursive(node) {
2664
2664
  }
2665
2665
  return false;
2666
2666
  }
2667
+ function isInlineContentNode(node) {
2668
+ if (node.type === "text") return node.text.trim().length > 0;
2669
+ return node.type === "mustache_interpolation" || node.type === "mustache_triple" || node.type === "mustache_partial";
2670
+ }
2667
2671
  function isInTextFlow(node, index, nodes) {
2668
2672
  if (index > 0) {
2669
2673
  const prev = nodes[index - 1];
@@ -2679,6 +2683,21 @@ function isInTextFlow(node, index, nodes) {
2679
2683
  }
2680
2684
  return false;
2681
2685
  }
2686
+ function hasAdjacentInlineContent(index, nodes) {
2687
+ for (let i = index - 1; i >= 0; i--) {
2688
+ const n = nodes[i];
2689
+ if (n.type === "text" && n.text.trim().length === 0) continue;
2690
+ if (isInlineContentNode(n)) return true;
2691
+ break;
2692
+ }
2693
+ for (let i = index + 1; i < nodes.length; i++) {
2694
+ const n = nodes[i];
2695
+ if (n.type === "text" && n.text.trim().length === 0) continue;
2696
+ if (isInlineContentNode(n)) return true;
2697
+ break;
2698
+ }
2699
+ return false;
2700
+ }
2682
2701
  function shouldHtmlElementStayInline(node, index, nodes) {
2683
2702
  if (node.type !== "html_element") {
2684
2703
  return false;
@@ -2686,6 +2705,9 @@ function shouldHtmlElementStayInline(node, index, nodes) {
2686
2705
  if (isInTextFlow(node, index, nodes)) {
2687
2706
  return true;
2688
2707
  }
2708
+ if (hasAdjacentInlineContent(index, nodes)) {
2709
+ return true;
2710
+ }
2689
2711
  if (index > 0) {
2690
2712
  const prev = nodes[index - 1];
2691
2713
  if (prev.type === "html_element" && isInTextFlow(prev, index - 1, nodes)) {
@@ -3148,12 +3170,13 @@ function formatStartTag(node, context) {
3148
3170
  }
3149
3171
  attrParts.push(attrs[i]);
3150
3172
  }
3173
+ const breakClosingBracket = isSelfClosing ? "/>" : ">";
3151
3174
  return group(
3152
3175
  concat([
3153
3176
  text("<"),
3154
3177
  text(tagNameText),
3155
3178
  indent(concat([line, concat(attrParts)])),
3156
- ifBreak(concat([hardline, text(closingBracket)]), text(closingBracket))
3179
+ ifBreak(concat([hardline, text(breakClosingBracket)]), text(closingBracket))
3157
3180
  ])
3158
3181
  );
3159
3182
  }
@@ -3263,10 +3286,10 @@ function formatBlockChildren(nodes, context) {
3263
3286
  }
3264
3287
  const rawText = context.document.getText().slice(ignoreRegionStartIndex, node.startIndex).replace(/^\n/, "").replace(/\n$/, "");
3265
3288
  if (rawText.length > 0) {
3266
- lines.push({ doc: text(rawText), blankLineBefore: false });
3289
+ lines.push({ doc: text(rawText), blankLineBefore: false, rawLine: true });
3267
3290
  }
3268
3291
  const commentText = node.type === "mustache_comment" ? mustacheText(node.text, context) : node.text;
3269
- lines.push({ doc: text(commentText), blankLineBefore: false });
3292
+ lines.push({ doc: text(commentText), blankLineBefore: false, rawLine: true });
3270
3293
  inIgnoreRegion = false;
3271
3294
  ignoreRegionStartIndex = -1;
3272
3295
  lastNodeEnd = node.endIndex;
@@ -3433,7 +3456,12 @@ function formatBlockChildren(nodes, context) {
3433
3456
  }
3434
3457
  } else {
3435
3458
  if (node.type === "text" && typeof formatted === "string") {
3436
- currentLine.push(...textWords(formatted));
3459
+ const words = textWords(formatted);
3460
+ if (words.length > 0) {
3461
+ currentLine.push(...words);
3462
+ } else if (node.text.trim() === "" && currentLine.length > 0) {
3463
+ currentLine.push(line);
3464
+ }
3437
3465
  } else {
3438
3466
  currentLine.push(formatted);
3439
3467
  }
@@ -3445,7 +3473,7 @@ function formatBlockChildren(nodes, context) {
3445
3473
  const lastNode = nodes[nodes.length - 1];
3446
3474
  const rawText = context.document.getText().slice(ignoreRegionStartIndex, lastNode.endIndex).replace(/^\n/, "");
3447
3475
  if (rawText.length > 0) {
3448
- lines.push({ doc: text(rawText), blankLineBefore: false });
3476
+ lines.push({ doc: text(rawText), blankLineBefore: false, rawLine: true });
3449
3477
  }
3450
3478
  }
3451
3479
  if (currentLine.length > 0) {
@@ -3463,7 +3491,11 @@ function formatBlockChildren(nodes, context) {
3463
3491
  if (lines[i].blankLineBefore) {
3464
3492
  parts.push("\n");
3465
3493
  }
3466
- parts.push(hardline);
3494
+ if (lines[i].rawLine) {
3495
+ parts.push("\n");
3496
+ } else {
3497
+ parts.push(hardline);
3498
+ }
3467
3499
  }
3468
3500
  parts.push(lines[i].doc);
3469
3501
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reteps/tree-sitter-htmlmustache",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "description": "HTML with Mustache/Handlebars template syntax grammar for tree-sitter",
5
5
  "repository": {
6
6
  "type": "git",