@zackad/prettier-plugin-twig 0.14.0 → 0.15.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.
Files changed (53) hide show
  1. package/README.md +19 -0
  2. package/package.json +1 -1
  3. package/src/index.js +7 -0
  4. package/src/melody/melody-extension-core/operators.js +23 -12
  5. package/src/melody/melody-parser/Lexer.js +3 -0
  6. package/src/melody/melody-parser/Parser.js +6 -0
  7. package/src/parser.js +8 -0
  8. package/src/print/AliasExpression.js +2 -2
  9. package/src/print/ArrayExpression.js +2 -2
  10. package/src/print/ArrowFunction.js +2 -2
  11. package/src/print/Attribute.js +2 -2
  12. package/src/print/AutoescapeBlock.js +2 -2
  13. package/src/print/BinaryExpression.js +4 -4
  14. package/src/print/BlockStatement.js +2 -2
  15. package/src/print/CallExpression.js +2 -2
  16. package/src/print/ConditionalExpression.js +2 -2
  17. package/src/print/Declaration.js +2 -2
  18. package/src/print/DoStatement.js +2 -2
  19. package/src/print/Element.js +2 -2
  20. package/src/print/EmbedStatement.js +5 -2
  21. package/src/print/ExpressionStatement.js +2 -2
  22. package/src/print/ExtendsStatement.js +2 -2
  23. package/src/print/FilterBlockStatement.js +2 -2
  24. package/src/print/FilterExpression.js +2 -2
  25. package/src/print/FlushStatement.js +2 -2
  26. package/src/print/ForStatement.js +2 -2
  27. package/src/print/FromStatement.js +2 -2
  28. package/src/print/GenericToken.js +2 -2
  29. package/src/print/GenericTwigTag.js +2 -2
  30. package/src/print/HtmlComment.js +2 -2
  31. package/src/print/Identifier.js +2 -2
  32. package/src/print/IfStatement.js +2 -2
  33. package/src/print/ImportDeclaration.js +2 -2
  34. package/src/print/IncludeStatement.js +2 -2
  35. package/src/print/MacroDeclarationStatement.js +2 -2
  36. package/src/print/MemberExpression.js +2 -2
  37. package/src/print/MountStatement.js +2 -2
  38. package/src/print/NamedArgumentExpression.js +2 -2
  39. package/src/print/ObjectExpression.js +2 -2
  40. package/src/print/ObjectProperty.js +2 -2
  41. package/src/print/SequenceExpression.js +2 -2
  42. package/src/print/SetStatement.js +2 -2
  43. package/src/print/SliceExpression.js +2 -2
  44. package/src/print/SpacelessBlock.js +2 -2
  45. package/src/print/StringLiteral.js +2 -2
  46. package/src/print/SwitchTag.js +2 -2
  47. package/src/print/TestExpression.js +11 -3
  48. package/src/print/TextStatement.js +2 -2
  49. package/src/print/TwigComment.js +2 -2
  50. package/src/print/UnaryExpression.js +2 -2
  51. package/src/print/UnarySubclass.js +2 -2
  52. package/src/print/UseStatement.js +2 -2
  53. package/src/print/VariableDeclarationStatement.js +2 -2
package/README.md CHANGED
@@ -105,6 +105,25 @@ If we did not list the `"nav,endnav"` entry in `twigMultiTags`, this code exampl
105
105
 
106
106
  Note that the order matters: It has to be `"nav,endnav"`, and it must not be `"endnav,nav"`. In general, the first and the last tag name matter. In the case of `"switch,case,default,endswitch"`, the order of `case` and `default` does not matter. However, `switch` has to come first, and `endswitch` has to come last.
107
107
 
108
+ ### twigTestExpressions (default: `[]`)
109
+
110
+ Make custom Twig tests known to the parser.
111
+
112
+ ```json
113
+ twigTestExpressions: [
114
+ "snake_case_test",
115
+ "camelCaseTest"
116
+ ]
117
+ ```
118
+
119
+ __Example__
120
+ ```twig
121
+ {{ a is snake_case_test }}
122
+ {{ a is not snake_case_test }}
123
+ {{ a is camelCaseTest }}
124
+ {{ a is not camelCaseTest }}
125
+ ```
126
+
108
127
  ## Features
109
128
 
110
129
  ### `prettier-ignore` and `prettier-ignore-start`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zackad/prettier-plugin-twig",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Prettier Plugin for Twig",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.js CHANGED
@@ -72,6 +72,13 @@ const printers = {
72
72
 
73
73
  /** @type {import('prettier').Options} Options */
74
74
  const options = {
75
+ twigTestExpressions: {
76
+ type: "path",
77
+ category: "Global",
78
+ array: true,
79
+ default: [{ value: [] }],
80
+ description: "Make custom Twig tests known to the parser."
81
+ },
75
82
  twigMultiTags: {
76
83
  type: "path",
77
84
  category: "Global",
@@ -301,13 +301,19 @@ export const BinaryEmptyCoalesceExpression = createBinaryOperatorNode({
301
301
  //endregion
302
302
 
303
303
  //region Test Expressions
304
- export const TestEvenExpression = createTest("even", "TestEvenExpression");
305
- export const TestOddExpression = createTest("odd", "TestOddExpression");
306
- export const TestDefinedExpression = createTest(
304
+ export const TestEvenExpression = createTestExpression(
305
+ "even",
306
+ "TestEvenExpression"
307
+ );
308
+ export const TestOddExpression = createTestExpression(
309
+ "odd",
310
+ "TestOddExpression"
311
+ );
312
+ export const TestDefinedExpression = createTestExpression(
307
313
  "defined",
308
314
  "TestDefinedExpression"
309
315
  );
310
- export const TestSameAsExpression = createTest(
316
+ export const TestSameAsExpression = createTestExpression(
311
317
  "same as",
312
318
  "TestSameAsExpression"
313
319
  );
@@ -318,14 +324,17 @@ tests.push({
318
324
  return new TestSameAsExpression(expr, args);
319
325
  }
320
326
  });
321
- export const TestNullExpression = createTest("null", "TestNullExpression");
327
+ export const TestNullExpression = createTestExpression(
328
+ "null",
329
+ "TestNullExpression"
330
+ );
322
331
  tests.push({
323
332
  text: "none",
324
333
  createNode(expr, args) {
325
334
  return new TestNullExpression(expr, args);
326
335
  }
327
336
  });
328
- export const TestDivisibleByExpression = createTest(
337
+ export const TestDivisibleByExpression = createTestExpression(
329
338
  "divisible by",
330
339
  "TestDivisibleByExpression"
331
340
  );
@@ -336,24 +345,26 @@ tests.push({
336
345
  return new TestDivisibleByExpression(expr, args);
337
346
  }
338
347
  });
339
- export const TestConstantExpression = createTest(
348
+ export const TestConstantExpression = createTestExpression(
340
349
  "constant",
341
350
  "TestConstantExpression"
342
351
  );
343
- export const TestEmptyExpression = createTest("empty", "TestEmptyExpression");
344
- export const TestIterableExpression = createTest(
352
+ export const TestEmptyExpression = createTestExpression(
353
+ "empty",
354
+ "TestEmptyExpression"
355
+ );
356
+ export const TestIterableExpression = createTestExpression(
345
357
  "iterable",
346
358
  "TestIterableExpression"
347
359
  );
348
-
349
- export const TestInstanceOfExpression = createTest(
360
+ export const TestInstanceOfExpression = createTestExpression(
350
361
  "instance of",
351
362
  "TestInstanceOfExpression"
352
363
  );
353
364
  //endregion
354
365
 
355
366
  //region Utilities
356
- function createTest(text, typeName) {
367
+ export function createTestExpression(text, typeName) {
357
368
  const TestExpression = class extends Node {
358
369
  /**
359
370
  * @param {Node} expr
@@ -578,6 +578,9 @@ export default class Lexer {
578
578
  if (c === "\\" && input.la(1) === start) {
579
579
  input.next();
580
580
  input.next();
581
+ } else if (c === "{" && input.la(1) === "{") {
582
+ // interpolation start
583
+ break;
581
584
  } else if (c === start) {
582
585
  break;
583
586
  } else {
@@ -29,6 +29,7 @@ import { GenericTagParser } from "./GenericTagParser.js";
29
29
  import { createMultiTagParser } from "./GenericMultiTagParser.js";
30
30
  import { voidElements } from "./elementInfo.js";
31
31
  import * as he from "he";
32
+ import { Attribute } from "../melody-types/index.js";
32
33
 
33
34
  /**
34
35
  * @typedef {Object} UnaryOperator
@@ -378,6 +379,7 @@ export default class Parser {
378
379
  tokens.lat(0) !== Types.ELEMENT_END
379
380
  ) {
380
381
  const key = tokens.nextIf(Types.SYMBOL);
382
+ let twigComment;
381
383
  if (key) {
382
384
  const keyNode = new n.Identifier(key.text);
383
385
  setStartFromToken(keyNode, key);
@@ -442,6 +444,10 @@ export default class Parser {
442
444
  } else if (tokens.nextIf(Types.EXPRESSION_START)) {
443
445
  element.attributes.push(this.matchExpression());
444
446
  tokens.expect(Types.EXPRESSION_END);
447
+ } else if ((twigComment = tokens.nextIf(Types.COMMENT))) {
448
+ const twigCommentValue = new n.StringLiteral(twigComment.text);
449
+ const twigCommentNode = new n.TwigComment(twigCommentValue);
450
+ element.attributes.push(twigCommentNode);
445
451
  } else {
446
452
  this.error({
447
453
  title: "Invalid token",
package/src/parser.js CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  Parser
6
6
  } from "./melody/melody-parser/index.js";
7
7
  import { extension as coreExtension } from "./melody/melody-extension-core/index.js";
8
+ import { createTestExpression } from "./melody/melody-extension-core/operators.js";
8
9
 
9
10
  const ORIGINAL_SOURCE = Symbol("ORIGINAL_SOURCE");
10
11
 
@@ -74,8 +75,15 @@ const getMultiTagConfig = (tagsCsvs = []) =>
74
75
  return acc;
75
76
  }, {});
76
77
 
78
+ const registerTestExtensions = (testExpressions = []) => {
79
+ testExpressions.forEach(test =>
80
+ createTestExpression(test, `Test[${test}]Expression`)
81
+ );
82
+ };
83
+
77
84
  const parse = (text, parsers, options) => {
78
85
  const multiTagConfig = getMultiTagConfig(options.twigMultiTags || []);
86
+ registerTestExtensions(options.twigTestExpressions || []);
79
87
 
80
88
  const extensions = [coreExtension];
81
89
  const parser = createConfiguredParser(text, multiTagConfig, ...extensions);
@@ -1,5 +1,5 @@
1
- const p = (node, path, print) => {
1
+ const printAliasExpression = (node, path, print) => {
2
2
  return [path.call(print, "name"), " as ", path.call(print, "alias")];
3
3
  };
4
4
 
5
- export { p as printAliasExpression };
5
+ export { printAliasExpression };
@@ -3,7 +3,7 @@ import { STRING_NEEDS_QUOTES } from "../util/index.js";
3
3
 
4
4
  const { group, softline, line, indent, join } = doc.builders;
5
5
 
6
- const p = (node, path, print) => {
6
+ const printArrayExpression = (node, path, print) => {
7
7
  node[STRING_NEEDS_QUOTES] = true;
8
8
  const mappedElements = path.map(print, "elements");
9
9
  const indentedContent = [softline, join([",", line], mappedElements)];
@@ -11,4 +11,4 @@ const p = (node, path, print) => {
11
11
  return group(["[", indent(indentedContent), softline, "]"]);
12
12
  };
13
13
 
14
- export { p as printArrayExpression };
14
+ export { printArrayExpression };
@@ -1,7 +1,7 @@
1
1
  import { doc } from "prettier";
2
2
  const { group, indent, join, line, softline } = doc.builders;
3
3
 
4
- const p = (node, path, print) => {
4
+ const printArrowFunction = (node, path, print) => {
5
5
  const args = node.args;
6
6
  const body = path.call(print, "body");
7
7
 
@@ -34,4 +34,4 @@ const p = (node, path, print) => {
34
34
  return group(parts);
35
35
  };
36
36
 
37
- export { p as printArrowFunction };
37
+ export { printArrowFunction };
@@ -19,7 +19,7 @@ const printConcatenatedString = (valueNode, path, print, ...initialPath) => {
19
19
  return printedFragments;
20
20
  };
21
21
 
22
- const p = (node, path, print = print) => {
22
+ const printAttribute = (node, path, print = print) => {
23
23
  node[EXPRESSION_NEEDED] = false;
24
24
  const docs = [path.call(print, "name")];
25
25
  node[EXPRESSION_NEEDED] = true;
@@ -47,4 +47,4 @@ const p = (node, path, print = print) => {
47
47
  return docs;
48
48
  };
49
49
 
50
- export { p as printAttribute };
50
+ export { printAttribute };
@@ -25,7 +25,7 @@ const createOpener = (node, options) => {
25
25
  ];
26
26
  };
27
27
 
28
- const p = (node, path, print, options) => {
28
+ const printAutoescapeBlock = (node, path, print, options) => {
29
29
  const parts = [createOpener(node, options)];
30
30
  parts.push(printChildBlock(node, path, print, "expressions"));
31
31
  parts.push(
@@ -38,4 +38,4 @@ const p = (node, path, print, options) => {
38
38
  return parts;
39
39
  };
40
40
 
41
- export { p as printAutoescapeBlock };
41
+ export { printAutoescapeBlock };
@@ -65,7 +65,7 @@ const otherNeedsParentheses = (node, otherProp) => {
65
65
  );
66
66
  };
67
67
 
68
- const printBinaryExpression = (node, path, print) => {
68
+ const internalPrintBinaryExpression = (node, path, print) => {
69
69
  node[EXPRESSION_NEEDED] = false;
70
70
  node[STRING_NEEDS_QUOTES] = true;
71
71
 
@@ -145,11 +145,11 @@ const printBinaryExpression = (node, path, print) => {
145
145
  return shouldGroupResult ? group(result) : result;
146
146
  };
147
147
 
148
- const p = (node, path, print, options) => {
148
+ const printBinaryExpression = (node, path, print, options) => {
149
149
  if (Node.isBinaryConcatExpression(node) && node.wasImplicitConcatenation) {
150
150
  return printInterpolatedString(node, path, print, options);
151
151
  }
152
- return printBinaryExpression(node, path, print);
152
+ return internalPrintBinaryExpression(node, path, print);
153
153
  };
154
154
 
155
- export { p as printBinaryExpression };
155
+ export { printBinaryExpression };
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  const { hardline, group } = doc.builders;
10
10
 
11
- const p = (node, path, print, options) => {
11
+ const printBlockStatement = (node, path, print, options) => {
12
12
  node[EXPRESSION_NEEDED] = false;
13
13
  const hasChildren = Array.isArray(node.body);
14
14
  const printEndblockName = options.twigOutputEndblockName === true;
@@ -55,4 +55,4 @@ const p = (node, path, print, options) => {
55
55
  }
56
56
  };
57
57
 
58
- export { p as printBlockStatement };
58
+ export { printBlockStatement };
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  const { group, softline, line, indent, join } = doc.builders;
10
10
 
11
- const p = (node, path, print) => {
11
+ const printCallExpression = (node, path, print) => {
12
12
  node[EXPRESSION_NEEDED] = false;
13
13
  node[STRING_NEEDS_QUOTES] = true;
14
14
  const mappedArguments = path.map(print, "arguments");
@@ -35,4 +35,4 @@ const p = (node, path, print) => {
35
35
  return group(parts);
36
36
  };
37
37
 
38
- export { p as printCallExpression };
38
+ export { printCallExpression };
@@ -7,7 +7,7 @@ import {
7
7
 
8
8
  const { line, indent, group } = doc.builders;
9
9
 
10
- const p = (node, path, print) => {
10
+ const printConditionalExpression = (node, path, print) => {
11
11
  node[EXPRESSION_NEEDED] = false;
12
12
  node[STRING_NEEDS_QUOTES] = true;
13
13
 
@@ -24,4 +24,4 @@ const p = (node, path, print) => {
24
24
  return group(parts);
25
25
  };
26
26
 
27
- export { p as printConditionalExpression };
27
+ export { printConditionalExpression };
@@ -3,7 +3,7 @@ import { STRING_NEEDS_QUOTES, OVERRIDE_QUOTE_CHAR } from "../util/index.js";
3
3
 
4
4
  const { fill, join } = doc.builders;
5
5
 
6
- const p = (node, path, print) => {
6
+ const printDeclaration = (node, path, print) => {
7
7
  node[STRING_NEEDS_QUOTES] = true;
8
8
  node[OVERRIDE_QUOTE_CHAR] = '"';
9
9
  const start = "<!" + (node.declarationType || "").toUpperCase();
@@ -12,4 +12,4 @@ const p = (node, path, print) => {
12
12
  return fill([start, " ", join(" ", printedParts), ">"]);
13
13
  };
14
14
 
15
- export { p as printDeclaration };
15
+ export { printDeclaration };
@@ -1,4 +1,4 @@
1
- const p = (node, path, print) => {
1
+ const printDoStatement = (node, path, print) => {
2
2
  return [
3
3
  node.trimLeft ? "{%-" : "{%",
4
4
  " do ",
@@ -7,4 +7,4 @@ const p = (node, path, print) => {
7
7
  ];
8
8
  };
9
9
 
10
- export { p as printDoStatement };
10
+ export { printDoStatement };
@@ -46,7 +46,7 @@ const printSeparatedList = (path, print, separator, attrName) => {
46
46
  return join([separator, line], path.map(print, attrName));
47
47
  };
48
48
 
49
- const p = (node, path, print, options) => {
49
+ const printElement = (node, path, print, options) => {
50
50
  // Set a flag in case attributes contain, e.g., a FilterExpression
51
51
  node[EXPRESSION_NEEDED] = true;
52
52
  const openingGroup = group(printOpeningTag(node, path, print, options));
@@ -83,4 +83,4 @@ const p = (node, path, print, options) => {
83
83
  return group(result, { id: groupElement });
84
84
  };
85
85
 
86
- export { p as printElement };
86
+ export { printElement };
@@ -18,11 +18,14 @@ const printOpener = (node, path, print) => {
18
18
  if (node.argument) {
19
19
  parts.push(indent([line, "with ", path.call(print, "argument")]));
20
20
  }
21
+ if (node.contextFree) {
22
+ parts.push(" only");
23
+ }
21
24
  parts.push([line, node.trimRightEmbed ? "-%}" : "%}"]);
22
25
  return group(parts);
23
26
  };
24
27
 
25
- const p = (node, path, print) => {
28
+ const printEmbedStatement = (node, path, print) => {
26
29
  const children = printChildBlock(node, path, print, "blocks");
27
30
  const printedOpener = printOpener(node, path, print);
28
31
  const closing = [
@@ -35,4 +38,4 @@ const p = (node, path, print) => {
35
38
  return [printedOpener, children, closing];
36
39
  };
37
40
 
38
- export { p as printEmbedStatement };
41
+ export { printEmbedStatement };
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  const { group, indent, line } = doc.builders;
10
10
 
11
- const p = (node, path, print) => {
11
+ const printExpressionStatement = (node, path, print) => {
12
12
  node[EXPRESSION_NEEDED] = false;
13
13
  node[STRING_NEEDS_QUOTES] = true;
14
14
  const opener = node.trimLeft ? "{{-" : "{{";
@@ -22,4 +22,4 @@ const p = (node, path, print) => {
22
22
  return group([opener, value, padding, closing]);
23
23
  };
24
24
 
25
- export { p as printExpressionStatement };
25
+ export { printExpressionStatement };
@@ -1,6 +1,6 @@
1
1
  import { STRING_NEEDS_QUOTES } from "../util/index.js";
2
2
 
3
- const p = (node, path, print) => {
3
+ const printExtendsStatement = (node, path, print) => {
4
4
  node[STRING_NEEDS_QUOTES] = true;
5
5
  return [
6
6
  node.trimLeft ? "{%-" : "{%",
@@ -10,4 +10,4 @@ const p = (node, path, print) => {
10
10
  ];
11
11
  };
12
12
 
13
- export { p as printExtendsStatement };
13
+ export { printExtendsStatement };
@@ -10,7 +10,7 @@ const printOpeningGroup = (node, path, print) => {
10
10
  return group(parts);
11
11
  };
12
12
 
13
- const p = (node, path, print) => {
13
+ const printFilterBlockStatement = (node, path, print) => {
14
14
  node[FILTER_BLOCK] = true;
15
15
  const openingGroup = printOpeningGroup(node, path, print);
16
16
  const body = printChildBlock(node, path, print, "body");
@@ -24,4 +24,4 @@ const p = (node, path, print) => {
24
24
  return [openingGroup, body, closingStatement];
25
25
  };
26
26
 
27
- export { p as printFilterBlockStatement };
27
+ export { printFilterBlockStatement };
@@ -53,7 +53,7 @@ const joinFilters = (filterExpressions, space = "") => {
53
53
  );
54
54
  };
55
55
 
56
- const p = (node, path, print, options) => {
56
+ const printFilterExpression = (node, path, print, options) => {
57
57
  let currentNode = node;
58
58
  node[EXPRESSION_NEEDED] = false;
59
59
  node[STRING_NEEDS_QUOTES] = true;
@@ -128,4 +128,4 @@ const p = (node, path, print, options) => {
128
128
  return group(parts);
129
129
  };
130
130
 
131
- export { p as printFilterExpression };
131
+ export { printFilterExpression };
@@ -1,7 +1,7 @@
1
- const p = (node, path, print) => {
1
+ const printFlushStatement = (node, path, print) => {
2
2
  const dashLeft = node.trimLeft ? "-" : "";
3
3
  const dashRight = node.trimRight ? "-" : "";
4
4
  return `{%${dashLeft} flush ${dashRight}%}`;
5
5
  };
6
6
 
7
- export { p as printFlushStatement };
7
+ export { printFlushStatement };
@@ -24,7 +24,7 @@ const printFor = (node, path, print) => {
24
24
  return group(parts);
25
25
  };
26
26
 
27
- const p = (node, path, print) => {
27
+ const printForStatement = (node, path, print) => {
28
28
  node[EXPRESSION_NEEDED] = false;
29
29
  const parts = [printFor(node, path, print)];
30
30
  const isBodyEmpty =
@@ -55,4 +55,4 @@ const p = (node, path, print) => {
55
55
  return parts;
56
56
  };
57
57
 
58
- export { p as printForStatement };
58
+ export { printForStatement };
@@ -11,7 +11,7 @@ const printImportDeclaration = node => {
11
11
  return parts;
12
12
  };
13
13
 
14
- const p = (node, path, print) => {
14
+ const printFromStatement = (node, path, print) => {
15
15
  node[STRING_NEEDS_QUOTES] = true;
16
16
  // Unfortunately, ImportDeclaration has different
17
17
  // formatting needs here compared to when used
@@ -29,4 +29,4 @@ const p = (node, path, print) => {
29
29
  ]);
30
30
  };
31
31
 
32
- export { p as printFromStatement };
32
+ export { printFromStatement };
@@ -1,5 +1,5 @@
1
- const p = (node, path, print) => {
1
+ const printGenericToken = (node, path, print) => {
2
2
  return node.tokenText;
3
3
  };
4
4
 
5
- export { p as printGenericToken };
5
+ export { printGenericToken };
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  const { hardline } = doc.builders;
11
11
 
12
- const p = (node, path, print) => {
12
+ const printGenericTwigTag = (node, path, print) => {
13
13
  node[STRING_NEEDS_QUOTES] = true;
14
14
  const openingTag = printSingleTwigTag(node, path, print);
15
15
  const parts = [openingTag];
@@ -27,4 +27,4 @@ const p = (node, path, print) => {
27
27
  return parts;
28
28
  };
29
29
 
30
- export { p as printGenericTwigTag };
30
+ export { printGenericTwigTag };
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  const { join, indent, hardline } = doc.builders;
10
10
 
11
- const p = (node, path, print) => {
11
+ const printHtmlComment = (node, path, print) => {
12
12
  const commentText = stripHtmlCommentChars(node.value.value || "");
13
13
 
14
14
  const numNewlines = countNewlines(commentText);
@@ -19,4 +19,4 @@ const p = (node, path, print) => {
19
19
  return ["<!-- ", commentText, " -->"];
20
20
  };
21
21
 
22
- export { p as printHtmlComment };
22
+ export { printHtmlComment };
@@ -7,7 +7,7 @@ import {
7
7
 
8
8
  const { group } = doc.builders;
9
9
 
10
- const p = (node, path, print) => {
10
+ const printIdentifier = (node, path, print) => {
11
11
  node[EXPRESSION_NEEDED] = false;
12
12
  node[STRING_NEEDS_QUOTES] = true;
13
13
 
@@ -21,4 +21,4 @@ const p = (node, path, print) => {
21
21
  return parts.length === 1 ? result : group(result);
22
22
  };
23
23
 
24
- export { p as printIdentifier };
24
+ export { printIdentifier };
@@ -12,7 +12,7 @@ const { group, indent, line, hardline } = doc.builders;
12
12
 
13
13
  const IS_ELSEIF = Symbol("IS_ELSEIF");
14
14
 
15
- const p = (node, path, print) => {
15
+ const printIfStatement = (node, path, print) => {
16
16
  node[EXPRESSION_NEEDED] = false;
17
17
  const hasElseBranch =
18
18
  Array.isArray(node.alternate) && node.alternate.length > 0;
@@ -78,4 +78,4 @@ const p = (node, path, print) => {
78
78
  return parts;
79
79
  };
80
80
 
81
- export { p as printIfStatement };
81
+ export { printIfStatement };
@@ -3,7 +3,7 @@ import { STRING_NEEDS_QUOTES } from "../util/index.js";
3
3
 
4
4
  const { group, line, indent } = doc.builders;
5
5
 
6
- const p = (node, path, print) => {
6
+ const printImportDeclaration = (node, path, print) => {
7
7
  node[STRING_NEEDS_QUOTES] = true;
8
8
  return group([
9
9
  node.trimLeft ? "{%-" : "{%",
@@ -15,4 +15,4 @@ const p = (node, path, print) => {
15
15
  ]);
16
16
  };
17
17
 
18
- export { p as printImportDeclaration };
18
+ export { printImportDeclaration };
@@ -3,7 +3,7 @@ import { STRING_NEEDS_QUOTES } from "../util/index.js";
3
3
 
4
4
  const { group } = doc.builders;
5
5
 
6
- const p = (node, path, print) => {
6
+ const printIncludeStatement = (node, path, print) => {
7
7
  node[STRING_NEEDS_QUOTES] = true;
8
8
  const parts = [
9
9
  node.trimLeft ? "{%-" : "{%",
@@ -23,4 +23,4 @@ const p = (node, path, print) => {
23
23
  return group(parts);
24
24
  };
25
25
 
26
- export { p as printIncludeStatement };
26
+ export { printIncludeStatement };
@@ -16,7 +16,7 @@ const printOpener = (node, path, print) => {
16
16
  return group(parts);
17
17
  };
18
18
 
19
- const p = (node, path, print) => {
19
+ const printMacroDeclarationStatement = (node, path, print) => {
20
20
  const parts = [printOpener(node, path, print)];
21
21
  parts.push(indent([hardline, path.call(print, "body")]));
22
22
  parts.push(
@@ -28,4 +28,4 @@ const p = (node, path, print) => {
28
28
  return parts;
29
29
  };
30
30
 
31
- export { p as printMacroDeclarationStatement };
31
+ export { printMacroDeclarationStatement };
@@ -7,7 +7,7 @@ import {
7
7
 
8
8
  const { group } = doc.builders;
9
9
 
10
- const p = (node, path, print) => {
10
+ const printMemberExpression = (node, path, print) => {
11
11
  node[EXPRESSION_NEEDED] = false;
12
12
  node[STRING_NEEDS_QUOTES] = true;
13
13
  const parts = [path.call(print, "object")];
@@ -20,4 +20,4 @@ const p = (node, path, print) => {
20
20
  return group(parts);
21
21
  };
22
22
 
23
- export { p as printMemberExpression };
23
+ export { printMemberExpression };
@@ -59,7 +59,7 @@ const buildErrorHandling = (node, path, print) => {
59
59
  return parts;
60
60
  };
61
61
 
62
- const p = (node, path, print) => {
62
+ const printMountStatement = (node, path, print) => {
63
63
  node[EXPRESSION_NEEDED] = false;
64
64
  node[STRING_NEEDS_QUOTES] = true;
65
65
  const parts = [buildOpener(node, path, print)];
@@ -81,4 +81,4 @@ const p = (node, path, print) => {
81
81
  return parts;
82
82
  };
83
83
 
84
- export { p as printMountStatement };
84
+ export { printMountStatement };
@@ -1,6 +1,6 @@
1
1
  import { STRING_NEEDS_QUOTES } from "../util/index.js";
2
2
 
3
- const p = (node, path, print, options) => {
3
+ const printNamedArgumentExpression = (node, path, print, options) => {
4
4
  node[STRING_NEEDS_QUOTES] = true;
5
5
  const printedName = path.call(print, "name");
6
6
  const printedValue = path.call(print, "value");
@@ -8,4 +8,4 @@ const p = (node, path, print, options) => {
8
8
  return [printedName, separator, printedValue];
9
9
  };
10
10
 
11
- export { p as printNamedArgumentExpression };
11
+ export { printNamedArgumentExpression };
@@ -3,7 +3,7 @@ import { EXPRESSION_NEEDED, wrapExpressionIfNeeded } from "../util/index.js";
3
3
 
4
4
  const { group, line, hardline, indent, join } = doc.builders;
5
5
 
6
- const p = (node, path, print, options) => {
6
+ const printObjectExpression = (node, path, print, options) => {
7
7
  if (node.properties.length === 0) {
8
8
  return "{}";
9
9
  }
@@ -18,4 +18,4 @@ const p = (node, path, print, options) => {
18
18
  return group(parts);
19
19
  };
20
20
 
21
- export { p as printObjectExpression };
21
+ export { printObjectExpression };
@@ -1,7 +1,7 @@
1
1
  import { Node } from "../melody/melody-types/index.js";
2
2
  import { isValidIdentifierName, STRING_NEEDS_QUOTES } from "../util/index.js";
3
3
 
4
- const p = (node, path, print, options) => {
4
+ const printObjectProperty = (node, path, print, options) => {
5
5
  node[STRING_NEEDS_QUOTES] =
6
6
  !node.computed &&
7
7
  Node.isStringLiteral(node.key) &&
@@ -28,4 +28,4 @@ const p = (node, path, print, options) => {
28
28
  return parts;
29
29
  };
30
30
 
31
- export { p as printObjectProperty };
31
+ export { printObjectProperty };
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  const { hardline } = doc.builders;
10
10
 
11
- const p = (node, path, print) => {
11
+ const printSequenceExpression = (node, path, print) => {
12
12
  node[STRING_NEEDS_QUOTES] = false;
13
13
  node.expressions = removeSurroundingWhitespace(node.expressions);
14
14
  const items = printChildGroups(node, path, print, "expressions");
@@ -18,4 +18,4 @@ const p = (node, path, print) => {
18
18
  return items;
19
19
  };
20
20
 
21
- export { p as printSequenceExpression };
21
+ export { printSequenceExpression };
@@ -80,7 +80,7 @@ const printEmbracingSet = (node, path, print) => {
80
80
  return parts;
81
81
  };
82
82
 
83
- const p = (node, path, print) => {
83
+ const printSetStatement = (node, path, print) => {
84
84
  node[STRING_NEEDS_QUOTES] = true;
85
85
  if (isEmbracingSet(node)) {
86
86
  return printEmbracingSet(node, path, print);
@@ -88,4 +88,4 @@ const p = (node, path, print) => {
88
88
  return printRegularSet(node, path, print);
89
89
  };
90
90
 
91
- export { p as printSetStatement };
91
+ export { printSetStatement };
@@ -1,8 +1,8 @@
1
- const p = (node, path, print) => {
1
+ const printSliceExpression = (node, path, print) => {
2
2
  const printedTarget = path.call(print, "target");
3
3
  const printedStart = node.start ? path.call(print, "start") : "";
4
4
  const printedEnd = node.end ? path.call(print, "end") : "";
5
5
  return [printedTarget, "[", printedStart, ":", printedEnd, "]"];
6
6
  };
7
7
 
8
- export { p as printSliceExpression };
8
+ export { printSliceExpression };
@@ -3,7 +3,7 @@ import { printChildBlock } from "../util/index.js";
3
3
 
4
4
  const { hardline, group } = doc.builders;
5
5
 
6
- const p = (node, path, print) => {
6
+ const printSpacelessBlock = (node, path, print) => {
7
7
  const parts = [
8
8
  node.trimLeft ? "{%-" : "{%",
9
9
  " spaceless ",
@@ -20,4 +20,4 @@ const p = (node, path, print) => {
20
20
  return result;
21
21
  };
22
22
 
23
- export { p as printSpacelessBlock };
23
+ export { printSpacelessBlock };
@@ -33,7 +33,7 @@ const getQuoteChar = (s, options) => {
33
33
  return quoteChar(options);
34
34
  };
35
35
 
36
- const p = (node, path, print, options) => {
36
+ const printStringLiteral = (node, path, print, options) => {
37
37
  // The structure this string literal is part of
38
38
  // determines if we need quotes or not
39
39
  const needsQuotes = firstValueInAncestorChain(
@@ -60,4 +60,4 @@ const p = (node, path, print, options) => {
60
60
  return node.value;
61
61
  };
62
62
 
63
- export { p as printStringLiteral };
63
+ export { printStringLiteral };
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  const { indent, hardline } = doc.builders;
11
11
 
12
- const p = (node, path, print) => {
12
+ const printSwitchTag = (node, path, print) => {
13
13
  node[STRING_NEEDS_QUOTES] = true;
14
14
  const openingTag = printSingleTwigTag(node, path, print);
15
15
  const parts = [openingTag];
@@ -32,4 +32,4 @@ const p = (node, path, print) => {
32
32
  return parts;
33
33
  };
34
34
 
35
- export { p as printSwitchTag };
35
+ export { printSwitchTag };
@@ -18,7 +18,7 @@ const textMap = {
18
18
  const isNegator = node =>
19
19
  node.constructor.name === "UnarySubclass" && node.operator === "not";
20
20
 
21
- const p = (node, path, print) => {
21
+ const printTestExpression = (node, path, print) => {
22
22
  node[STRING_NEEDS_QUOTES] = true;
23
23
  const expressionType = node.__proto__.type;
24
24
  const parts = [path.call(print, "expression"), " is "];
@@ -28,7 +28,15 @@ const p = (node, path, print) => {
28
28
  if (isNegator(parent)) {
29
29
  parts.push("not ");
30
30
  }
31
- if (!textMap[expressionType]) {
31
+
32
+ if (expressionType.includes("[") && expressionType.includes("]")) {
33
+ const testText = expressionType.substring(
34
+ expressionType.indexOf("[") + 1,
35
+ expressionType.lastIndexOf("]")
36
+ );
37
+
38
+ parts.push(testText);
39
+ } else if (!textMap[expressionType]) {
32
40
  console.error(
33
41
  "TestExpression: No text for " + expressionType + " defined"
34
42
  );
@@ -46,4 +54,4 @@ const p = (node, path, print) => {
46
54
  return parts;
47
55
  };
48
56
 
49
- export { p as printTestExpression };
57
+ export { printTestExpression };
@@ -20,7 +20,7 @@ const newlinesOnly = (s, preserveWhitespace = true) => {
20
20
  return [hardline, hardline];
21
21
  };
22
22
 
23
- const p = (node, path, print) => {
23
+ const printTextStatement = (node, path, print) => {
24
24
  // Check for special values that might have been
25
25
  // computed during preprocessing
26
26
  const preserveLeadingWhitespace =
@@ -42,4 +42,4 @@ const p = (node, path, print) => {
42
42
  return join([hardline, hardline], textGroups);
43
43
  };
44
44
 
45
- export { p as printTextStatement };
45
+ export { printTextStatement };
@@ -5,7 +5,7 @@ import {
5
5
  countNewlines
6
6
  } from "../util/index.js";
7
7
 
8
- const p = node => {
8
+ const printTwigComment = node => {
9
9
  const originalText = node.value.value || "";
10
10
  const commentText = stripTwigCommentChars(originalText);
11
11
  const trimLeft = originalText.length >= 3 ? originalText[2] === "-" : false;
@@ -20,4 +20,4 @@ const p = node => {
20
20
  return [trimLeft ? "{#-" : "{#", commentText, trimRight ? "-#}" : "#}"];
21
21
  };
22
22
 
23
- export { p as printTwigComment };
23
+ export { printTwigComment };
@@ -7,7 +7,7 @@ import {
7
7
 
8
8
  const { group } = doc.builders;
9
9
 
10
- const p = (node, path, print) => {
10
+ const printUnaryExpression = (node, path, print) => {
11
11
  node[EXPRESSION_NEEDED] = false;
12
12
  node[STRING_NEEDS_QUOTES] = true;
13
13
  const parts = [node.operator, path.call(print, "argument")];
@@ -15,4 +15,4 @@ const p = (node, path, print) => {
15
15
  return group(parts);
16
16
  };
17
17
 
18
- export { p as printUnaryExpression };
18
+ export { printUnaryExpression };
@@ -42,7 +42,7 @@ const printLogicalExpression = (node, path, print) => {
42
42
  return shouldCreateTopLevelGroup ? group(result) : result;
43
43
  };
44
44
 
45
- const p = (node, path, print) => {
45
+ const printUnarySubclass = (node, path, print) => {
46
46
  // We need this part to prevent argument being wrapped into expression separated from operator
47
47
  // Example:
48
48
  // with node[EXPRESSION_NEEDED] = true; // default value
@@ -71,4 +71,4 @@ const p = (node, path, print) => {
71
71
  return parts;
72
72
  };
73
73
 
74
- export { p as printUnarySubclass };
74
+ export { printUnarySubclass };
@@ -2,7 +2,7 @@ import { doc } from "prettier";
2
2
 
3
3
  const { group, indent, join, line } = doc.builders;
4
4
 
5
- const p = (node, path, print) => {
5
+ const printUseStatement = (node, path, print) => {
6
6
  const docs = [
7
7
  node.trimLeft ? "{%-" : "{%",
8
8
  ' use "',
@@ -22,4 +22,4 @@ const p = (node, path, print) => {
22
22
  return group(docs);
23
23
  };
24
24
 
25
- export { p as printUseStatement };
25
+ export { printUseStatement };
@@ -3,7 +3,7 @@ import { STRING_NEEDS_QUOTES, isContractableNodeType } from "../util/index.js";
3
3
 
4
4
  const { line, indent } = doc.builders;
5
5
 
6
- const p = (node, path, print) => {
6
+ const printVariableDeclarationStatement = (node, path, print) => {
7
7
  const printedName = path.call(print, "name");
8
8
  node[STRING_NEEDS_QUOTES] = true;
9
9
  const printedValue = path.call(print, "value");
@@ -18,4 +18,4 @@ const p = (node, path, print) => {
18
18
  return [printedName, " =", rightHandSide];
19
19
  };
20
20
 
21
- export { p as printVariableDeclarationStatement };
21
+ export { printVariableDeclarationStatement };