@zackad/prettier-plugin-twig 0.13.0 → 0.14.1
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/package.json +1 -1
- package/src/melody/melody-parser/Lexer.js +3 -0
- package/src/print/AliasExpression.js +2 -2
- package/src/print/ArrayExpression.js +2 -2
- package/src/print/ArrowFunction.js +2 -2
- package/src/print/Attribute.js +2 -2
- package/src/print/AutoescapeBlock.js +2 -2
- package/src/print/BinaryExpression.js +4 -4
- package/src/print/BlockStatement.js +11 -4
- package/src/print/CallExpression.js +2 -2
- package/src/print/ConditionalExpression.js +2 -2
- package/src/print/Declaration.js +2 -2
- package/src/print/DoStatement.js +2 -2
- package/src/print/Element.js +53 -30
- package/src/print/EmbedStatement.js +2 -2
- package/src/print/ExpressionStatement.js +2 -2
- package/src/print/ExtendsStatement.js +2 -2
- package/src/print/FilterBlockStatement.js +2 -2
- package/src/print/FilterExpression.js +2 -2
- package/src/print/FlushStatement.js +2 -2
- package/src/print/ForStatement.js +2 -2
- package/src/print/FromStatement.js +2 -2
- package/src/print/GenericToken.js +2 -2
- package/src/print/GenericTwigTag.js +2 -2
- package/src/print/HtmlComment.js +2 -2
- package/src/print/Identifier.js +2 -2
- package/src/print/IfStatement.js +2 -2
- package/src/print/ImportDeclaration.js +2 -2
- package/src/print/IncludeStatement.js +2 -2
- package/src/print/MacroDeclarationStatement.js +2 -2
- package/src/print/MemberExpression.js +2 -2
- package/src/print/MountStatement.js +2 -2
- package/src/print/NamedArgumentExpression.js +2 -2
- package/src/print/ObjectExpression.js +2 -2
- package/src/print/ObjectProperty.js +2 -2
- package/src/print/SequenceExpression.js +2 -2
- package/src/print/SetStatement.js +2 -2
- package/src/print/SliceExpression.js +2 -2
- package/src/print/SpacelessBlock.js +2 -2
- package/src/print/StringLiteral.js +2 -2
- package/src/print/SwitchTag.js +2 -2
- package/src/print/TestExpression.js +2 -2
- package/src/print/TextStatement.js +2 -2
- package/src/print/TwigComment.js +2 -2
- package/src/print/UnaryExpression.js +2 -2
- package/src/print/UnarySubclass.js +2 -2
- package/src/print/UseStatement.js +2 -2
- package/src/print/VariableDeclarationStatement.js +2 -2
- package/src/util/publicFunctions.js +22 -1
package/package.json
CHANGED
|
@@ -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 {
|
|
@@ -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
|
|
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 {
|
|
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
|
|
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 {
|
|
37
|
+
export { printArrowFunction };
|
package/src/print/Attribute.js
CHANGED
|
@@ -19,7 +19,7 @@ const printConcatenatedString = (valueNode, path, print, ...initialPath) => {
|
|
|
19
19
|
return printedFragments;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const
|
|
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 {
|
|
50
|
+
export { printAttribute };
|
|
@@ -25,7 +25,7 @@ const createOpener = (node, options) => {
|
|
|
25
25
|
];
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const
|
|
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 {
|
|
41
|
+
export { printAutoescapeBlock };
|
|
@@ -65,7 +65,7 @@ const otherNeedsParentheses = (node, otherProp) => {
|
|
|
65
65
|
);
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
const
|
|
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
|
|
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
|
|
152
|
+
return internalPrintBinaryExpression(node, path, print);
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
export {
|
|
155
|
+
export { printBinaryExpression };
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { doc } from "prettier";
|
|
2
|
-
import { Node } from "../melody/melody-types/index.js";
|
|
3
|
-
import {
|
|
2
|
+
import { Node, StringLiteral } from "../melody/melody-types/index.js";
|
|
3
|
+
import {
|
|
4
|
+
printChildBlock,
|
|
5
|
+
EXPRESSION_NEEDED,
|
|
6
|
+
STRING_NEEDS_QUOTES
|
|
7
|
+
} from "../util/index.js";
|
|
4
8
|
|
|
5
9
|
const { hardline, group } = doc.builders;
|
|
6
10
|
|
|
7
|
-
const
|
|
11
|
+
const printBlockStatement = (node, path, print, options) => {
|
|
8
12
|
node[EXPRESSION_NEEDED] = false;
|
|
9
13
|
const hasChildren = Array.isArray(node.body);
|
|
10
14
|
const printEndblockName = options.twigOutputEndblockName === true;
|
|
@@ -37,6 +41,9 @@ const p = (node, path, print, options) => {
|
|
|
37
41
|
|
|
38
42
|
return group(parts);
|
|
39
43
|
} else if (Node.isPrintExpressionStatement(node.body)) {
|
|
44
|
+
if (node.body.value instanceof StringLiteral) {
|
|
45
|
+
node[STRING_NEEDS_QUOTES] = true;
|
|
46
|
+
}
|
|
40
47
|
return [
|
|
41
48
|
node.trimLeft ? "{%-" : "{%",
|
|
42
49
|
" block ",
|
|
@@ -48,4 +55,4 @@ const p = (node, path, print, options) => {
|
|
|
48
55
|
}
|
|
49
56
|
};
|
|
50
57
|
|
|
51
|
-
export {
|
|
58
|
+
export { printBlockStatement };
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
const { group, softline, line, indent, join } = doc.builders;
|
|
10
10
|
|
|
11
|
-
const
|
|
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 {
|
|
38
|
+
export { printCallExpression };
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
const { line, indent, group } = doc.builders;
|
|
9
9
|
|
|
10
|
-
const
|
|
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 {
|
|
27
|
+
export { printConditionalExpression };
|
package/src/print/Declaration.js
CHANGED
|
@@ -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
|
|
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 {
|
|
15
|
+
export { printDeclaration };
|
package/src/print/DoStatement.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
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 {
|
|
10
|
+
export { printDoStatement };
|
package/src/print/Element.js
CHANGED
|
@@ -2,6 +2,7 @@ import { doc } from "prettier";
|
|
|
2
2
|
import {
|
|
3
3
|
removeSurroundingWhitespace,
|
|
4
4
|
isInlineElement,
|
|
5
|
+
isOwnlineElement,
|
|
5
6
|
printChildGroups,
|
|
6
7
|
EXPRESSION_NEEDED,
|
|
7
8
|
STRING_NEEDS_QUOTES
|
|
@@ -9,55 +10,77 @@ import {
|
|
|
9
10
|
|
|
10
11
|
const { group, line, hardline, softline, indent, join } = doc.builders;
|
|
11
12
|
|
|
12
|
-
const printOpeningTag = (node, path, print) => {
|
|
13
|
+
const printOpeningTag = (node, path, print, options) => {
|
|
14
|
+
const groupId = Symbol("opening-tag");
|
|
15
|
+
|
|
13
16
|
const opener = "<" + node.name;
|
|
14
17
|
const printedAttributes = printSeparatedList(path, print, "", "attributes");
|
|
15
|
-
const openingTagEnd = node.selfClosing ? " />" : ">";
|
|
16
|
-
const hasAttributes = node.attributes && node.attributes.length > 0;
|
|
17
18
|
|
|
19
|
+
const openingTagEnd = [];
|
|
20
|
+
if (node.selfClosing) {
|
|
21
|
+
if (!options.bracketSameLine) {
|
|
22
|
+
openingTagEnd.push(line);
|
|
23
|
+
} else {
|
|
24
|
+
openingTagEnd.push(" ");
|
|
25
|
+
}
|
|
26
|
+
openingTagEnd.push("/>");
|
|
27
|
+
} else {
|
|
28
|
+
if (!options.bracketSameLine) {
|
|
29
|
+
openingTagEnd.push(softline);
|
|
30
|
+
}
|
|
31
|
+
openingTagEnd.push(">");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const hasAttributes = node.attributes && node.attributes.length > 0;
|
|
18
35
|
if (hasAttributes) {
|
|
19
|
-
return
|
|
36
|
+
return group(
|
|
37
|
+
[opener, indent([line, printedAttributes]), openingTagEnd],
|
|
38
|
+
{ id: groupId }
|
|
39
|
+
);
|
|
20
40
|
}
|
|
21
|
-
|
|
41
|
+
|
|
42
|
+
return group([opener, openingTagEnd], { id: groupId });
|
|
22
43
|
};
|
|
23
44
|
|
|
24
45
|
const printSeparatedList = (path, print, separator, attrName) => {
|
|
25
46
|
return join([separator, line], path.map(print, attrName));
|
|
26
47
|
};
|
|
27
48
|
|
|
28
|
-
const
|
|
49
|
+
const printElement = (node, path, print, options) => {
|
|
29
50
|
// Set a flag in case attributes contain, e.g., a FilterExpression
|
|
30
51
|
node[EXPRESSION_NEEDED] = true;
|
|
31
|
-
const openingGroup = group(printOpeningTag(node, path, print));
|
|
52
|
+
const openingGroup = group(printOpeningTag(node, path, print, options));
|
|
32
53
|
node[EXPRESSION_NEEDED] = false;
|
|
33
54
|
node[STRING_NEEDS_QUOTES] = false;
|
|
34
55
|
|
|
35
|
-
if (
|
|
36
|
-
|
|
56
|
+
if (node.selfClosing) {
|
|
57
|
+
return openingGroup;
|
|
58
|
+
}
|
|
37
59
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const result = [openingGroup];
|
|
41
|
-
const joinedChildren = childGroups;
|
|
42
|
-
if (isInlineElement(node)) {
|
|
43
|
-
result.push(indent([softline, joinedChildren]), softline);
|
|
44
|
-
} else {
|
|
45
|
-
const childBlock = [];
|
|
46
|
-
if (childGroups.length > 0) {
|
|
47
|
-
childBlock.push(hardline);
|
|
48
|
-
}
|
|
49
|
-
childBlock.push(joinedChildren);
|
|
50
|
-
result.push(indent(childBlock));
|
|
51
|
-
if (childGroups.length > 0) {
|
|
52
|
-
result.push(hardline);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
result.push(closingTag);
|
|
60
|
+
const groupElement = Symbol("element");
|
|
61
|
+
node.children = removeSurroundingWhitespace(node.children);
|
|
56
62
|
|
|
57
|
-
|
|
63
|
+
const childGroups = printChildGroups(node, path, print, "children");
|
|
64
|
+
const closingTag = ["</", node.name, ">"];
|
|
65
|
+
const result = [openingGroup];
|
|
66
|
+
const joinedChildren = childGroups;
|
|
67
|
+
if (isOwnlineElement(node) || isInlineElement(node)) {
|
|
68
|
+
const element = [indent([softline, joinedChildren]), softline];
|
|
69
|
+
result.push(element);
|
|
70
|
+
} else {
|
|
71
|
+
const childBlock = [];
|
|
72
|
+
if (childGroups.length > 0) {
|
|
73
|
+
childBlock.push(hardline);
|
|
74
|
+
}
|
|
75
|
+
childBlock.push(joinedChildren);
|
|
76
|
+
result.push(indent(childBlock));
|
|
77
|
+
if (childGroups.length > 0) {
|
|
78
|
+
result.push(hardline);
|
|
79
|
+
}
|
|
58
80
|
}
|
|
81
|
+
result.push(closingTag);
|
|
59
82
|
|
|
60
|
-
return
|
|
83
|
+
return group(result, { id: groupElement });
|
|
61
84
|
};
|
|
62
85
|
|
|
63
|
-
export {
|
|
86
|
+
export { printElement };
|
|
@@ -22,7 +22,7 @@ const printOpener = (node, path, print) => {
|
|
|
22
22
|
return group(parts);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const
|
|
25
|
+
const printEmbedStatement = (node, path, print) => {
|
|
26
26
|
const children = printChildBlock(node, path, print, "blocks");
|
|
27
27
|
const printedOpener = printOpener(node, path, print);
|
|
28
28
|
const closing = [
|
|
@@ -35,4 +35,4 @@ const p = (node, path, print) => {
|
|
|
35
35
|
return [printedOpener, children, closing];
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
export {
|
|
38
|
+
export { printEmbedStatement };
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
const { group, indent, line } = doc.builders;
|
|
10
10
|
|
|
11
|
-
const
|
|
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 {
|
|
25
|
+
export { printExpressionStatement };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { STRING_NEEDS_QUOTES } from "../util/index.js";
|
|
2
2
|
|
|
3
|
-
const
|
|
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 {
|
|
13
|
+
export { printExtendsStatement };
|
|
@@ -10,7 +10,7 @@ const printOpeningGroup = (node, path, print) => {
|
|
|
10
10
|
return group(parts);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const
|
|
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 {
|
|
27
|
+
export { printFilterBlockStatement };
|
|
@@ -53,7 +53,7 @@ const joinFilters = (filterExpressions, space = "") => {
|
|
|
53
53
|
);
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
const
|
|
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 {
|
|
131
|
+
export { printFilterExpression };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
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 {
|
|
7
|
+
export { printFlushStatement };
|
|
@@ -24,7 +24,7 @@ const printFor = (node, path, print) => {
|
|
|
24
24
|
return group(parts);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const
|
|
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 {
|
|
58
|
+
export { printForStatement };
|
|
@@ -11,7 +11,7 @@ const printImportDeclaration = node => {
|
|
|
11
11
|
return parts;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const
|
|
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 {
|
|
32
|
+
export { printFromStatement };
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
|
|
10
10
|
const { hardline } = doc.builders;
|
|
11
11
|
|
|
12
|
-
const
|
|
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 {
|
|
30
|
+
export { printGenericTwigTag };
|
package/src/print/HtmlComment.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
const { join, indent, hardline } = doc.builders;
|
|
10
10
|
|
|
11
|
-
const
|
|
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 {
|
|
22
|
+
export { printHtmlComment };
|
package/src/print/Identifier.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
const { group } = doc.builders;
|
|
9
9
|
|
|
10
|
-
const
|
|
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 {
|
|
24
|
+
export { printIdentifier };
|
package/src/print/IfStatement.js
CHANGED
|
@@ -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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
26
|
+
export { printIncludeStatement };
|
|
@@ -16,7 +16,7 @@ const printOpener = (node, path, print) => {
|
|
|
16
16
|
return group(parts);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
const
|
|
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 {
|
|
31
|
+
export { printMacroDeclarationStatement };
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
const { group } = doc.builders;
|
|
9
9
|
|
|
10
|
-
const
|
|
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 {
|
|
23
|
+
export { printMemberExpression };
|
|
@@ -59,7 +59,7 @@ const buildErrorHandling = (node, path, print) => {
|
|
|
59
59
|
return parts;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
const
|
|
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 {
|
|
84
|
+
export { printMountStatement };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { STRING_NEEDS_QUOTES } from "../util/index.js";
|
|
2
2
|
|
|
3
|
-
const
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
31
|
+
export { printObjectProperty };
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
const { hardline } = doc.builders;
|
|
10
10
|
|
|
11
|
-
const
|
|
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 {
|
|
21
|
+
export { printSequenceExpression };
|
|
@@ -80,7 +80,7 @@ const printEmbracingSet = (node, path, print) => {
|
|
|
80
80
|
return parts;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
const
|
|
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 {
|
|
91
|
+
export { printSetStatement };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
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 {
|
|
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
|
|
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 {
|
|
23
|
+
export { printSpacelessBlock };
|
|
@@ -33,7 +33,7 @@ const getQuoteChar = (s, options) => {
|
|
|
33
33
|
return quoteChar(options);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
const
|
|
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 {
|
|
63
|
+
export { printStringLiteral };
|
package/src/print/SwitchTag.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
|
|
10
10
|
const { indent, hardline } = doc.builders;
|
|
11
11
|
|
|
12
|
-
const
|
|
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 {
|
|
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
|
|
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 "];
|
|
@@ -46,4 +46,4 @@ const p = (node, path, print) => {
|
|
|
46
46
|
return parts;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export {
|
|
49
|
+
export { printTestExpression };
|
|
@@ -20,7 +20,7 @@ const newlinesOnly = (s, preserveWhitespace = true) => {
|
|
|
20
20
|
return [hardline, hardline];
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
const
|
|
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 {
|
|
45
|
+
export { printTextStatement };
|
package/src/print/TwigComment.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
countNewlines
|
|
6
6
|
} from "../util/index.js";
|
|
7
7
|
|
|
8
|
-
const
|
|
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 {
|
|
23
|
+
export { printTwigComment };
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
const { group } = doc.builders;
|
|
9
9
|
|
|
10
|
-
const
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
21
|
+
export { printVariableDeclarationStatement };
|
|
@@ -28,7 +28,6 @@ const INLINE_HTML_ELEMENTS = [
|
|
|
28
28
|
"img",
|
|
29
29
|
"kbd",
|
|
30
30
|
"label",
|
|
31
|
-
"li",
|
|
32
31
|
"mark",
|
|
33
32
|
"q",
|
|
34
33
|
"s",
|
|
@@ -43,6 +42,22 @@ const INLINE_HTML_ELEMENTS = [
|
|
|
43
42
|
"var"
|
|
44
43
|
];
|
|
45
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Introducing new "type" html element that should be printed on their own line
|
|
47
|
+
* @type {string[]}
|
|
48
|
+
*/
|
|
49
|
+
const OWNLINE_HTML_ELEMENTS = [
|
|
50
|
+
"h1",
|
|
51
|
+
"h2",
|
|
52
|
+
"h3",
|
|
53
|
+
"h4",
|
|
54
|
+
"h5",
|
|
55
|
+
"h6",
|
|
56
|
+
"li",
|
|
57
|
+
"td",
|
|
58
|
+
"th"
|
|
59
|
+
];
|
|
60
|
+
|
|
46
61
|
/**
|
|
47
62
|
* Node types around which we avoid an extra line break.
|
|
48
63
|
* Example:
|
|
@@ -478,6 +493,12 @@ const isInlineElement = node => {
|
|
|
478
493
|
);
|
|
479
494
|
};
|
|
480
495
|
|
|
496
|
+
export const isOwnlineElement = node => {
|
|
497
|
+
return (
|
|
498
|
+
Node.isElement(node) && OWNLINE_HTML_ELEMENTS.indexOf(node.name) >= 0
|
|
499
|
+
);
|
|
500
|
+
};
|
|
501
|
+
|
|
481
502
|
const isCommentNode = node =>
|
|
482
503
|
Node.isTwigComment(node) || Node.isHtmlComment(node);
|
|
483
504
|
|