@zackad/prettier-plugin-twig 0.17.0 → 0.18.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.
@@ -444,6 +444,42 @@ const stripTwigCommentChars = s => {
444
444
  return result;
445
445
  };
446
446
 
447
+ /**
448
+ * Splits a Twig comment into its text and the delimiters around it.
449
+ * Documentation comments (Twig 3.29) open with "{##" and may close
450
+ * symmetrically with "##}".
451
+ *
452
+ * @param {string} s
453
+ */
454
+ const parseTwigComment = s => {
455
+ let text = s.startsWith("{#") ? s.slice(2) : s;
456
+ // "{##}" is an empty regular comment, not a documentation comment
457
+ const isDocumentation = text.startsWith("#") && text !== "#}";
458
+ if (isDocumentation) {
459
+ text = text.slice(1);
460
+ }
461
+ const trimLeft = text.startsWith("-");
462
+ if (trimLeft) {
463
+ text = text.slice(1);
464
+ }
465
+ if (text.endsWith("#}")) {
466
+ text = text.slice(0, -2);
467
+ }
468
+ const hasSymmetricClose = isDocumentation && text.endsWith("#");
469
+ if (hasSymmetricClose) {
470
+ text = text.slice(0, -1);
471
+ }
472
+ const trimRight = text.endsWith("-");
473
+ if (trimRight) {
474
+ text = text.slice(0, -1);
475
+ }
476
+ return {
477
+ text,
478
+ open: (isDocumentation ? "{##" : "{#") + (trimLeft ? "-" : ""),
479
+ close: (trimRight ? "-" : "") + (hasSymmetricClose ? "##}" : "#}")
480
+ };
481
+ };
482
+
447
483
  const normalizeHtmlComment = s => {
448
484
  const commentText = stripHtmlCommentChars(s);
449
485
  return "<!-- " + unifyWhitespace(commentText) + " -->";
@@ -599,6 +635,8 @@ export {
599
635
  hasAtLeastTwoNewlines,
600
636
  stripHtmlCommentChars,
601
637
  stripTwigCommentChars,
638
+ parseTwigComment,
639
+ unifyWhitespace,
602
640
  normalizeHtmlComment,
603
641
  normalizeTwigComment,
604
642
  isHtmlCommentEqualTo,
@@ -55,6 +55,12 @@ const PRESERVE_LEADING_WHITESPACE = Symbol("PRESERVE_LEADING_WHITESPACE");
55
55
  */
56
56
  const PRESERVE_TRAILING_WHITESPACE = Symbol("PRESERVE_TRAILING_WHITESPACE");
57
57
 
58
+ /**
59
+ * Signals to statements that they should be ignored
60
+ * and printed as is.
61
+ */
62
+ const PRETTIER_IGNORED_CODE = Symbol("PRETTIER_IGNORED_CODE");
63
+
58
64
  /**
59
65
  * Signals to text statements that only newlines should be
60
66
  * preserved when hitting a whitespace-only node
@@ -77,6 +83,7 @@ const IS_ROOT_LOGICAL_EXPRESSION = Symbol("IS_ROOT_LOGICAL_EXPRESSION");
77
83
  export {
78
84
  STRING_NEEDS_QUOTES,
79
85
  OVERRIDE_QUOTE_CHAR,
86
+ PRETTIER_IGNORED_CODE,
80
87
  INSIDE_OF_STRING,
81
88
  EXPRESSION_NEEDED,
82
89
  FILTER_BLOCK,