@prettier/plugin-php 0.19.7 → 0.20.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.
- package/README.md +13 -13
- package/package.json +18 -16
- package/src/comments.js +8 -20
- package/src/index.js +18 -0
- package/src/parser.js +1 -1
- package/src/printer.js +101 -140
- package/standalone.js +3 -1
package/src/printer.js
CHANGED
|
@@ -115,7 +115,7 @@ function genericPrint(path, options, print) {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
function printPropertyLookup(path, options, print, nullsafe = false) {
|
|
118
|
-
return [nullsafe ? "?" : "", "->",
|
|
118
|
+
return [nullsafe ? "?" : "", "->", print("offset")];
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
function printNullsafePropertyLookup(path, options, print) {
|
|
@@ -126,12 +126,7 @@ function printStaticLookup(path, options, print) {
|
|
|
126
126
|
const node = path.getValue();
|
|
127
127
|
const needCurly = !["variable", "identifier"].includes(node.offset.kind);
|
|
128
128
|
|
|
129
|
-
return [
|
|
130
|
-
"::",
|
|
131
|
-
needCurly ? "{" : "",
|
|
132
|
-
path.call(print, "offset"),
|
|
133
|
-
needCurly ? "}" : "",
|
|
134
|
-
];
|
|
129
|
+
return ["::", needCurly ? "{" : "", print("offset"), needCurly ? "}" : ""];
|
|
135
130
|
}
|
|
136
131
|
|
|
137
132
|
function printOffsetLookup(path, options, print) {
|
|
@@ -144,7 +139,7 @@ function printOffsetLookup(path, options, print) {
|
|
|
144
139
|
"[",
|
|
145
140
|
node.offset
|
|
146
141
|
? group([
|
|
147
|
-
indent([shouldInline ? "" : softline,
|
|
142
|
+
indent([shouldInline ? "" : softline, print("offset")]),
|
|
148
143
|
shouldInline ? "" : softline,
|
|
149
144
|
])
|
|
150
145
|
: "",
|
|
@@ -262,7 +257,7 @@ function printMemberChain(path, options, print) {
|
|
|
262
257
|
} else {
|
|
263
258
|
printedNodes.unshift({
|
|
264
259
|
node,
|
|
265
|
-
printed:
|
|
260
|
+
printed: print(),
|
|
266
261
|
});
|
|
267
262
|
}
|
|
268
263
|
}
|
|
@@ -659,7 +654,7 @@ function printArgumentsList(path, options, print, argumentsKey = "arguments") {
|
|
|
659
654
|
path.each((argPath) => {
|
|
660
655
|
if (shouldGroupFirst && i === 0) {
|
|
661
656
|
printedExpanded = [
|
|
662
|
-
argPath.call((
|
|
657
|
+
argPath.call(() => print([], { expandFirstArg: true })),
|
|
663
658
|
printedArguments.length > 1 ? "," : "",
|
|
664
659
|
hasEmptyLineFollowingFirstArg ? hardline : line,
|
|
665
660
|
hasEmptyLineFollowingFirstArg ? hardline : "",
|
|
@@ -670,7 +665,7 @@ function printArgumentsList(path, options, print, argumentsKey = "arguments") {
|
|
|
670
665
|
if (shouldGroupLast && i === args.length - 1) {
|
|
671
666
|
printedExpanded = [
|
|
672
667
|
...printedArguments.slice(0, -1),
|
|
673
|
-
argPath.call((
|
|
668
|
+
argPath.call(() => print([], { expandLastArg: true })),
|
|
674
669
|
];
|
|
675
670
|
}
|
|
676
671
|
|
|
@@ -772,9 +767,9 @@ function printBinaryExpression(
|
|
|
772
767
|
// Flatten them out by recursively calling this function.
|
|
773
768
|
parts = parts.concat(
|
|
774
769
|
path.call(
|
|
775
|
-
(
|
|
770
|
+
() =>
|
|
776
771
|
printBinaryExpression(
|
|
777
|
-
|
|
772
|
+
path,
|
|
778
773
|
print,
|
|
779
774
|
options,
|
|
780
775
|
/* isNested */ true,
|
|
@@ -784,14 +779,14 @@ function printBinaryExpression(
|
|
|
784
779
|
)
|
|
785
780
|
);
|
|
786
781
|
} else {
|
|
787
|
-
parts.push(
|
|
782
|
+
parts.push(print("left"));
|
|
788
783
|
}
|
|
789
784
|
|
|
790
785
|
const shouldInline = shouldInlineLogicalExpression(node);
|
|
791
786
|
|
|
792
787
|
const right = shouldInline
|
|
793
|
-
? [node.type, " ",
|
|
794
|
-
: [node.type, line,
|
|
788
|
+
? [node.type, " ", print("right")]
|
|
789
|
+
: [node.type, line, print("right")];
|
|
795
790
|
|
|
796
791
|
// If there's only a single binary expression, we want to create a group
|
|
797
792
|
// in order to avoid having a small right part like -1 be on its own line.
|
|
@@ -822,7 +817,7 @@ function printBinaryExpression(
|
|
|
822
817
|
}
|
|
823
818
|
} else {
|
|
824
819
|
// Our stopping case. Simply print the node normally.
|
|
825
|
-
parts.push(
|
|
820
|
+
parts.push(print());
|
|
826
821
|
}
|
|
827
822
|
|
|
828
823
|
return parts;
|
|
@@ -1148,7 +1143,7 @@ function printClassPart(
|
|
|
1148
1143
|
? [
|
|
1149
1144
|
hardline,
|
|
1150
1145
|
path.call(
|
|
1151
|
-
(
|
|
1146
|
+
() => comments.printDanglingComments(path, options, true),
|
|
1152
1147
|
part
|
|
1153
1148
|
),
|
|
1154
1149
|
hardline,
|
|
@@ -1172,7 +1167,7 @@ function printClassPart(
|
|
|
1172
1167
|
}, part)
|
|
1173
1168
|
)
|
|
1174
1169
|
)
|
|
1175
|
-
: [afterPart,
|
|
1170
|
+
: [afterPart, print(part)];
|
|
1176
1171
|
|
|
1177
1172
|
return indent([
|
|
1178
1173
|
printedBeforePart,
|
|
@@ -1241,11 +1236,11 @@ function printClass(path, options, print) {
|
|
|
1241
1236
|
declaration.push(isAnonymousClass ? "" : node.kind);
|
|
1242
1237
|
|
|
1243
1238
|
if (node.name) {
|
|
1244
|
-
declaration.push(" ",
|
|
1239
|
+
declaration.push(" ", print("name"));
|
|
1245
1240
|
}
|
|
1246
1241
|
|
|
1247
1242
|
if (node.kind === "enum" && node.valueType) {
|
|
1248
|
-
declaration.push(": ",
|
|
1243
|
+
declaration.push(": ", print("valueType"));
|
|
1249
1244
|
}
|
|
1250
1245
|
|
|
1251
1246
|
// Only `class` can have `extends` and `implements`
|
|
@@ -1369,7 +1364,7 @@ function printFunction(path, options, print) {
|
|
|
1369
1364
|
}
|
|
1370
1365
|
|
|
1371
1366
|
if (node.name) {
|
|
1372
|
-
declaration.push(
|
|
1367
|
+
declaration.push(print("name"));
|
|
1373
1368
|
}
|
|
1374
1369
|
|
|
1375
1370
|
declaration.push(printArgumentsList(path, options, print));
|
|
@@ -1386,15 +1381,14 @@ function printFunction(path, options, print) {
|
|
|
1386
1381
|
hasDanglingComments(node.type)
|
|
1387
1382
|
? [
|
|
1388
1383
|
path.call(
|
|
1389
|
-
(
|
|
1390
|
-
comments.printDanglingComments(typePath, options, true),
|
|
1384
|
+
() => comments.printDanglingComments(path, options, true),
|
|
1391
1385
|
"type"
|
|
1392
1386
|
),
|
|
1393
1387
|
" ",
|
|
1394
1388
|
]
|
|
1395
1389
|
: "",
|
|
1396
1390
|
node.nullable ? "?" : "",
|
|
1397
|
-
|
|
1391
|
+
print("type"),
|
|
1398
1392
|
]);
|
|
1399
1393
|
}
|
|
1400
1394
|
|
|
@@ -1407,7 +1401,7 @@ function printFunction(path, options, print) {
|
|
|
1407
1401
|
const isClosure = node.kind === "closure";
|
|
1408
1402
|
const printedBody = [
|
|
1409
1403
|
"{",
|
|
1410
|
-
indent([hasEmptyBody(path) ? "" : hardline,
|
|
1404
|
+
indent([hasEmptyBody(path) ? "" : hardline, print("body")]),
|
|
1411
1405
|
isClosure && hasEmptyBody(path) ? "" : hardline,
|
|
1412
1406
|
"}",
|
|
1413
1407
|
];
|
|
@@ -1456,7 +1450,7 @@ function printBodyControlStructure(
|
|
|
1456
1450
|
return ";";
|
|
1457
1451
|
}
|
|
1458
1452
|
|
|
1459
|
-
const printedBody =
|
|
1453
|
+
const printedBody = print(bodyProperty);
|
|
1460
1454
|
|
|
1461
1455
|
return [
|
|
1462
1456
|
node.shortForm ? ":" : " {",
|
|
@@ -1586,10 +1580,7 @@ function isStringOnItsOwnLine(node, text, options) {
|
|
|
1586
1580
|
|
|
1587
1581
|
function printComposedTypes(path, print, glue) {
|
|
1588
1582
|
return group(
|
|
1589
|
-
path.map(
|
|
1590
|
-
(uPath, i) => (i === 0 ? [path.call(print)] : [glue, path.call(print)]),
|
|
1591
|
-
"types"
|
|
1592
|
-
)
|
|
1583
|
+
path.map((uPath, i) => (i === 0 ? [print()] : [glue, print()]), "types")
|
|
1593
1584
|
);
|
|
1594
1585
|
}
|
|
1595
1586
|
|
|
@@ -1609,7 +1600,7 @@ function printNode(path, options, print) {
|
|
|
1609
1600
|
]);
|
|
1610
1601
|
}
|
|
1611
1602
|
case "expressionstatement":
|
|
1612
|
-
return
|
|
1603
|
+
return print("expression");
|
|
1613
1604
|
case "block":
|
|
1614
1605
|
return [
|
|
1615
1606
|
printLines(path, options, print),
|
|
@@ -1648,7 +1639,7 @@ function printNode(path, options, print) {
|
|
|
1648
1639
|
];
|
|
1649
1640
|
}
|
|
1650
1641
|
case "declaredirective":
|
|
1651
|
-
return [
|
|
1642
|
+
return [print("key"), "=", print("value")];
|
|
1652
1643
|
case "namespace":
|
|
1653
1644
|
return [
|
|
1654
1645
|
"namespace ",
|
|
@@ -1708,7 +1699,7 @@ function printNode(path, options, print) {
|
|
|
1708
1699
|
hasDanglingComments(node)
|
|
1709
1700
|
? [" ", comments.printDanglingComments(path, options, true)]
|
|
1710
1701
|
: "",
|
|
1711
|
-
node.alias ? [" as ",
|
|
1702
|
+
node.alias ? [" as ", print("alias")] : "",
|
|
1712
1703
|
];
|
|
1713
1704
|
case "class":
|
|
1714
1705
|
case "enum":
|
|
@@ -1717,20 +1708,20 @@ function printNode(path, options, print) {
|
|
|
1717
1708
|
return printClass(path, options, print);
|
|
1718
1709
|
case "traitprecedence":
|
|
1719
1710
|
return [
|
|
1720
|
-
|
|
1711
|
+
print("trait"),
|
|
1721
1712
|
"::",
|
|
1722
|
-
|
|
1713
|
+
print("method"),
|
|
1723
1714
|
" insteadof ",
|
|
1724
1715
|
join(", ", path.map(print, "instead")),
|
|
1725
1716
|
];
|
|
1726
1717
|
case "traitalias":
|
|
1727
1718
|
return [
|
|
1728
|
-
node.trait ? [
|
|
1729
|
-
node.method ?
|
|
1719
|
+
node.trait ? [print("trait"), "::"] : "",
|
|
1720
|
+
node.method ? print("method") : "",
|
|
1730
1721
|
" as ",
|
|
1731
1722
|
join(" ", [
|
|
1732
1723
|
...(node.visibility ? [node.visibility] : []),
|
|
1733
|
-
...(node.as ? [
|
|
1724
|
+
...(node.as ? [print("as")] : []),
|
|
1734
1725
|
]),
|
|
1735
1726
|
];
|
|
1736
1727
|
case "traituse":
|
|
@@ -1770,11 +1761,9 @@ function printNode(path, options, print) {
|
|
|
1770
1761
|
node.isStatic ? "static " : "",
|
|
1771
1762
|
"fn",
|
|
1772
1763
|
printArgumentsList(path, options, print),
|
|
1773
|
-
node.type
|
|
1774
|
-
? [": ", node.nullable ? "?" : "", path.call(print, "type")]
|
|
1775
|
-
: "",
|
|
1764
|
+
node.type ? [": ", node.nullable ? "?" : "", print("type")] : "",
|
|
1776
1765
|
" => ",
|
|
1777
|
-
|
|
1766
|
+
print("body"),
|
|
1778
1767
|
node.parenthesizedExpression ? ")" : "",
|
|
1779
1768
|
];
|
|
1780
1769
|
case "parameter": {
|
|
@@ -1791,11 +1780,11 @@ function printNode(path, options, print) {
|
|
|
1791
1780
|
promoted,
|
|
1792
1781
|
node.readonly ? "readonly " : "",
|
|
1793
1782
|
node.nullable ? "?" : "",
|
|
1794
|
-
node.type ? [
|
|
1783
|
+
node.type ? [print("type"), " "] : "",
|
|
1795
1784
|
node.byref ? "&" : "",
|
|
1796
1785
|
node.variadic ? "..." : "",
|
|
1797
1786
|
"$",
|
|
1798
|
-
|
|
1787
|
+
print("name"),
|
|
1799
1788
|
];
|
|
1800
1789
|
|
|
1801
1790
|
if (node.value) {
|
|
@@ -1810,7 +1799,7 @@ function printNode(path, options, print) {
|
|
|
1810
1799
|
printAssignmentRight(
|
|
1811
1800
|
node.name,
|
|
1812
1801
|
node.value,
|
|
1813
|
-
|
|
1802
|
+
print("value"),
|
|
1814
1803
|
false,
|
|
1815
1804
|
options
|
|
1816
1805
|
),
|
|
@@ -1820,22 +1809,20 @@ function printNode(path, options, print) {
|
|
|
1820
1809
|
return name;
|
|
1821
1810
|
}
|
|
1822
1811
|
case "variadic":
|
|
1823
|
-
return ["...",
|
|
1812
|
+
return ["...", print("what")];
|
|
1824
1813
|
case "property":
|
|
1825
1814
|
return group([
|
|
1826
1815
|
node.readonly ? "readonly " : "",
|
|
1827
|
-
node.type
|
|
1828
|
-
? [node.nullable ? "?" : "", path.call(print, "type"), " "]
|
|
1829
|
-
: "",
|
|
1816
|
+
node.type ? [node.nullable ? "?" : "", print("type"), " "] : "",
|
|
1830
1817
|
"$",
|
|
1831
|
-
|
|
1818
|
+
print("name"),
|
|
1832
1819
|
node.value
|
|
1833
1820
|
? [
|
|
1834
1821
|
" =",
|
|
1835
1822
|
printAssignmentRight(
|
|
1836
1823
|
node.name,
|
|
1837
1824
|
node.value,
|
|
1838
|
-
|
|
1825
|
+
print("value"),
|
|
1839
1826
|
false,
|
|
1840
1827
|
options
|
|
1841
1828
|
),
|
|
@@ -1882,7 +1869,7 @@ function printNode(path, options, print) {
|
|
|
1882
1869
|
const body = printBodyControlStructure(path, options, print, "body");
|
|
1883
1870
|
const opening = group([
|
|
1884
1871
|
"if (",
|
|
1885
|
-
group([indent([softline,
|
|
1872
|
+
group([indent([softline, print("test")]), softline]),
|
|
1886
1873
|
")",
|
|
1887
1874
|
body,
|
|
1888
1875
|
]);
|
|
@@ -1918,7 +1905,7 @@ function printNode(path, options, print) {
|
|
|
1918
1905
|
"else",
|
|
1919
1906
|
group(
|
|
1920
1907
|
node.alternate.kind === "if"
|
|
1921
|
-
?
|
|
1908
|
+
? print("alternate")
|
|
1922
1909
|
: printBodyControlStructure(path, options, print, "alternate")
|
|
1923
1910
|
)
|
|
1924
1911
|
);
|
|
@@ -1933,7 +1920,7 @@ function printNode(path, options, print) {
|
|
|
1933
1920
|
"do",
|
|
1934
1921
|
printBodyControlStructure(path, options, print, "body"),
|
|
1935
1922
|
" while (",
|
|
1936
|
-
group([indent([softline,
|
|
1923
|
+
group([indent([softline, print("test")]), softline]),
|
|
1937
1924
|
")",
|
|
1938
1925
|
];
|
|
1939
1926
|
case "while":
|
|
@@ -1941,7 +1928,7 @@ function printNode(path, options, print) {
|
|
|
1941
1928
|
return group([
|
|
1942
1929
|
node.kind,
|
|
1943
1930
|
" (",
|
|
1944
|
-
group([indent([softline,
|
|
1931
|
+
group([indent([softline, print("test")]), softline]),
|
|
1945
1932
|
")",
|
|
1946
1933
|
printBodyControlStructure(path, options, print, "body"),
|
|
1947
1934
|
]);
|
|
@@ -2004,18 +1991,13 @@ function printNode(path, options, print) {
|
|
|
2004
1991
|
group([
|
|
2005
1992
|
indent([
|
|
2006
1993
|
softline,
|
|
2007
|
-
|
|
1994
|
+
print("source"),
|
|
2008
1995
|
line,
|
|
2009
1996
|
"as ",
|
|
2010
1997
|
group(
|
|
2011
1998
|
node.key
|
|
2012
|
-
? indent(
|
|
2013
|
-
|
|
2014
|
-
[" =>", line],
|
|
2015
|
-
[path.call(print, "key"), path.call(print, "value")]
|
|
2016
|
-
)
|
|
2017
|
-
)
|
|
2018
|
-
: path.call(print, "value")
|
|
1999
|
+
? indent(join([" =>", line], [print("key"), print("value")]))
|
|
2000
|
+
: print("value")
|
|
2019
2001
|
),
|
|
2020
2002
|
]),
|
|
2021
2003
|
softline,
|
|
@@ -2053,7 +2035,7 @@ function printNode(path, options, print) {
|
|
|
2053
2035
|
? [
|
|
2054
2036
|
" (",
|
|
2055
2037
|
join(" | ", path.map(print, "what")),
|
|
2056
|
-
node.variable ? [" ",
|
|
2038
|
+
node.variable ? [" ", print("variable")] : "",
|
|
2057
2039
|
")",
|
|
2058
2040
|
]
|
|
2059
2041
|
: "",
|
|
@@ -2065,9 +2047,7 @@ function printNode(path, options, print) {
|
|
|
2065
2047
|
node.test
|
|
2066
2048
|
? [
|
|
2067
2049
|
"case ",
|
|
2068
|
-
node.test.comments
|
|
2069
|
-
? indent(path.call(print, "test"))
|
|
2070
|
-
: path.call(print, "test"),
|
|
2050
|
+
node.test.comments ? indent(print("test")) : print("test"),
|
|
2071
2051
|
":",
|
|
2072
2052
|
]
|
|
2073
2053
|
: "default:",
|
|
@@ -2075,7 +2055,7 @@ function printNode(path, options, print) {
|
|
|
2075
2055
|
? node.body.children && node.body.children.length
|
|
2076
2056
|
? indent([
|
|
2077
2057
|
isFirstChildrenInlineNode(path) ? "" : hardline,
|
|
2078
|
-
|
|
2058
|
+
print("body"),
|
|
2079
2059
|
])
|
|
2080
2060
|
: ""
|
|
2081
2061
|
: "",
|
|
@@ -2084,7 +2064,7 @@ function printNode(path, options, print) {
|
|
|
2084
2064
|
case "continue":
|
|
2085
2065
|
if (node.level) {
|
|
2086
2066
|
if (node.level.kind === "number" && node.level.value !== "1") {
|
|
2087
|
-
return [`${node.kind} `,
|
|
2067
|
+
return [`${node.kind} `, print("level")];
|
|
2088
2068
|
}
|
|
2089
2069
|
|
|
2090
2070
|
return node.kind;
|
|
@@ -2098,7 +2078,7 @@ function printNode(path, options, print) {
|
|
|
2098
2078
|
isStringOnItsOwnLine(node.arguments[0], options.originalText, options)
|
|
2099
2079
|
) {
|
|
2100
2080
|
return [
|
|
2101
|
-
|
|
2081
|
+
print("what"),
|
|
2102
2082
|
"(",
|
|
2103
2083
|
join(", ", path.map(print, "arguments")),
|
|
2104
2084
|
")",
|
|
@@ -2110,10 +2090,7 @@ function printNode(path, options, print) {
|
|
|
2110
2090
|
return printMemberChain(path, options, print);
|
|
2111
2091
|
}
|
|
2112
2092
|
|
|
2113
|
-
return [
|
|
2114
|
-
path.call(print, "what"),
|
|
2115
|
-
printArgumentsList(path, options, print),
|
|
2116
|
-
];
|
|
2093
|
+
return [print("what"), printArgumentsList(path, options, print)];
|
|
2117
2094
|
}
|
|
2118
2095
|
case "new": {
|
|
2119
2096
|
const isAnonymousClassNode =
|
|
@@ -2128,7 +2105,7 @@ function printNode(path, options, print) {
|
|
|
2128
2105
|
return [
|
|
2129
2106
|
"new ",
|
|
2130
2107
|
...path.call(printAttrs, "what"),
|
|
2131
|
-
|
|
2108
|
+
print("what"),
|
|
2132
2109
|
"(",
|
|
2133
2110
|
join(", ", path.map(print, "arguments")),
|
|
2134
2111
|
")",
|
|
@@ -2146,20 +2123,20 @@ function printNode(path, options, print) {
|
|
|
2146
2123
|
? [comments.printComments(node.what.leadingComments, options), " "]
|
|
2147
2124
|
: "",
|
|
2148
2125
|
...path.call(
|
|
2149
|
-
(
|
|
2126
|
+
() => printAttrs(path, options, print, { inline: true }),
|
|
2150
2127
|
"what"
|
|
2151
2128
|
),
|
|
2152
2129
|
"class",
|
|
2153
2130
|
node.arguments.length > 0
|
|
2154
2131
|
? [" ", printArgumentsList(path, options, print)]
|
|
2155
2132
|
: "",
|
|
2156
|
-
group(
|
|
2133
|
+
group(print("what"))
|
|
2157
2134
|
);
|
|
2158
2135
|
} else {
|
|
2159
2136
|
const isExpression = ["call", "offsetlookup"].includes(node.what.kind);
|
|
2160
2137
|
const printed = [
|
|
2161
2138
|
isExpression ? "(" : "",
|
|
2162
|
-
|
|
2139
|
+
print("what"),
|
|
2163
2140
|
isExpression ? ")" : "",
|
|
2164
2141
|
printArgumentsList(path, options, print),
|
|
2165
2142
|
];
|
|
@@ -2172,9 +2149,7 @@ function printNode(path, options, print) {
|
|
|
2172
2149
|
case "clone":
|
|
2173
2150
|
return [
|
|
2174
2151
|
"clone ",
|
|
2175
|
-
node.what.comments
|
|
2176
|
-
? indent(path.call(print, "what"))
|
|
2177
|
-
: path.call(print, "what"),
|
|
2152
|
+
node.what.comments ? indent(print("what")) : print("what"),
|
|
2178
2153
|
];
|
|
2179
2154
|
case "propertylookup":
|
|
2180
2155
|
case "nullsafepropertylookup":
|
|
@@ -2206,7 +2181,7 @@ function printNode(path, options, print) {
|
|
|
2206
2181
|
!isLookupNode(parent));
|
|
2207
2182
|
|
|
2208
2183
|
return [
|
|
2209
|
-
|
|
2184
|
+
print("what"),
|
|
2210
2185
|
shouldInline
|
|
2211
2186
|
? printLookupNodes(path, options, print)
|
|
2212
2187
|
: group(indent([softline, printLookupNodes(path, options, print)])),
|
|
@@ -2218,8 +2193,8 @@ function printNode(path, options, print) {
|
|
|
2218
2193
|
"(",
|
|
2219
2194
|
node.expression
|
|
2220
2195
|
? isStringOnItsOwnLine(node.expression, options.originalText, options)
|
|
2221
|
-
?
|
|
2222
|
-
: [indent([softline,
|
|
2196
|
+
? print("expression")
|
|
2197
|
+
: [indent([softline, print("expression")]), softline]
|
|
2223
2198
|
: comments.printDanglingComments(path, options),
|
|
2224
2199
|
")",
|
|
2225
2200
|
]);
|
|
@@ -2233,23 +2208,19 @@ function printNode(path, options, print) {
|
|
|
2233
2208
|
node.require ? "require" : "include",
|
|
2234
2209
|
node.once ? "_once" : "",
|
|
2235
2210
|
" ",
|
|
2236
|
-
node.target.comments
|
|
2237
|
-
? indent(path.call(print, "target"))
|
|
2238
|
-
: path.call(print, "target"),
|
|
2211
|
+
node.target.comments ? indent(print("target")) : print("target"),
|
|
2239
2212
|
];
|
|
2240
2213
|
case "label":
|
|
2241
|
-
return [
|
|
2214
|
+
return [print("name"), ":"];
|
|
2242
2215
|
case "goto":
|
|
2243
|
-
return ["goto ",
|
|
2216
|
+
return ["goto ", print("label")];
|
|
2244
2217
|
case "throw":
|
|
2245
2218
|
return [
|
|
2246
2219
|
"throw ",
|
|
2247
|
-
node.what.comments
|
|
2248
|
-
? indent(path.call(print, "what"))
|
|
2249
|
-
: path.call(print, "what"),
|
|
2220
|
+
node.what.comments ? indent(print("what")) : print("what"),
|
|
2250
2221
|
];
|
|
2251
2222
|
case "silent":
|
|
2252
|
-
return ["@",
|
|
2223
|
+
return ["@", print("expr")];
|
|
2253
2224
|
case "halt":
|
|
2254
2225
|
return [
|
|
2255
2226
|
hasDanglingComments(node)
|
|
@@ -2269,8 +2240,8 @@ function printNode(path, options, print) {
|
|
|
2269
2240
|
return group([
|
|
2270
2241
|
"eval(",
|
|
2271
2242
|
isStringOnItsOwnLine(node.source, options.originalText, options)
|
|
2272
|
-
?
|
|
2273
|
-
: [indent([softline,
|
|
2243
|
+
? print("source")
|
|
2244
|
+
: [indent([softline, print("source")]), softline],
|
|
2274
2245
|
")",
|
|
2275
2246
|
]);
|
|
2276
2247
|
case "echo": {
|
|
@@ -2299,8 +2270,8 @@ function printNode(path, options, print) {
|
|
|
2299
2270
|
return [
|
|
2300
2271
|
"print ",
|
|
2301
2272
|
node.expression.comments
|
|
2302
|
-
? indent(
|
|
2303
|
-
:
|
|
2273
|
+
? indent(print("expression"))
|
|
2274
|
+
: print("expression"),
|
|
2304
2275
|
];
|
|
2305
2276
|
}
|
|
2306
2277
|
case "return": {
|
|
@@ -2309,7 +2280,7 @@ function printNode(path, options, print) {
|
|
|
2309
2280
|
parts.push("return");
|
|
2310
2281
|
|
|
2311
2282
|
if (node.expr) {
|
|
2312
|
-
const printedExpr =
|
|
2283
|
+
const printedExpr = print("expr");
|
|
2313
2284
|
|
|
2314
2285
|
parts.push(" ", node.expr.comments ? indent(printedExpr) : printedExpr);
|
|
2315
2286
|
}
|
|
@@ -2332,7 +2303,7 @@ function printNode(path, options, print) {
|
|
|
2332
2303
|
case "empty":
|
|
2333
2304
|
return group([
|
|
2334
2305
|
"empty(",
|
|
2335
|
-
indent([softline,
|
|
2306
|
+
indent([softline, print("expression")]),
|
|
2336
2307
|
softline,
|
|
2337
2308
|
")",
|
|
2338
2309
|
]);
|
|
@@ -2354,13 +2325,7 @@ function printNode(path, options, print) {
|
|
|
2354
2325
|
const openCurly = node.curly ? "{" : "";
|
|
2355
2326
|
const closeCurly = node.curly ? "}" : "";
|
|
2356
2327
|
|
|
2357
|
-
return [
|
|
2358
|
-
ampersand,
|
|
2359
|
-
dollar,
|
|
2360
|
-
openCurly,
|
|
2361
|
-
path.call(print, "name"),
|
|
2362
|
-
closeCurly,
|
|
2363
|
-
];
|
|
2328
|
+
return [ampersand, dollar, openCurly, print("name"), closeCurly];
|
|
2364
2329
|
}
|
|
2365
2330
|
case "constantstatement":
|
|
2366
2331
|
case "classconstant": {
|
|
@@ -2388,10 +2353,10 @@ function printNode(path, options, print) {
|
|
|
2388
2353
|
case "constant":
|
|
2389
2354
|
return printAssignment(
|
|
2390
2355
|
node.name,
|
|
2391
|
-
|
|
2356
|
+
print("name"),
|
|
2392
2357
|
" =",
|
|
2393
2358
|
node.value,
|
|
2394
|
-
|
|
2359
|
+
print("value"),
|
|
2395
2360
|
false,
|
|
2396
2361
|
options
|
|
2397
2362
|
);
|
|
@@ -2422,10 +2387,10 @@ function printNode(path, options, print) {
|
|
|
2422
2387
|
case "staticvariable": {
|
|
2423
2388
|
return printAssignment(
|
|
2424
2389
|
node.variable,
|
|
2425
|
-
|
|
2390
|
+
print("variable"),
|
|
2426
2391
|
" =",
|
|
2427
2392
|
node.defaultValue,
|
|
2428
|
-
|
|
2393
|
+
print("defaultValue"),
|
|
2429
2394
|
false,
|
|
2430
2395
|
options
|
|
2431
2396
|
);
|
|
@@ -2507,19 +2472,19 @@ function printNode(path, options, print) {
|
|
|
2507
2472
|
return node.key
|
|
2508
2473
|
? printAssignment(
|
|
2509
2474
|
node.key,
|
|
2510
|
-
|
|
2475
|
+
print("key"),
|
|
2511
2476
|
" =>",
|
|
2512
2477
|
node.value,
|
|
2513
|
-
|
|
2478
|
+
print("value"),
|
|
2514
2479
|
ref,
|
|
2515
2480
|
options
|
|
2516
2481
|
)
|
|
2517
|
-
: [ref, unpack,
|
|
2482
|
+
: [ref, unpack, print("value")];
|
|
2518
2483
|
}
|
|
2519
2484
|
case "yield": {
|
|
2520
2485
|
const printedKeyAndValue = [
|
|
2521
|
-
node.key ? [
|
|
2522
|
-
|
|
2486
|
+
node.key ? [print("key"), " => "] : "",
|
|
2487
|
+
print("value"),
|
|
2523
2488
|
];
|
|
2524
2489
|
|
|
2525
2490
|
return [
|
|
@@ -2533,24 +2498,20 @@ function printNode(path, options, print) {
|
|
|
2533
2498
|
case "yieldfrom":
|
|
2534
2499
|
return [
|
|
2535
2500
|
"yield from ",
|
|
2536
|
-
node.value.comments
|
|
2537
|
-
? indent(path.call(print, "value"))
|
|
2538
|
-
: path.call(print, "value"),
|
|
2501
|
+
node.value.comments ? indent(print("value")) : print("value"),
|
|
2539
2502
|
];
|
|
2540
2503
|
case "unary":
|
|
2541
|
-
return [node.type,
|
|
2504
|
+
return [node.type, print("what")];
|
|
2542
2505
|
case "pre":
|
|
2543
|
-
return [node.type + node.type,
|
|
2506
|
+
return [node.type + node.type, print("what")];
|
|
2544
2507
|
case "post":
|
|
2545
|
-
return [
|
|
2508
|
+
return [print("what"), node.type + node.type];
|
|
2546
2509
|
case "cast":
|
|
2547
2510
|
return [
|
|
2548
2511
|
"(",
|
|
2549
2512
|
node.type,
|
|
2550
2513
|
") ",
|
|
2551
|
-
node.expr.comments
|
|
2552
|
-
? indent(path.call(print, "expr"))
|
|
2553
|
-
: path.call(print, "expr"),
|
|
2514
|
+
node.expr.comments ? indent(print("expr")) : print("expr"),
|
|
2554
2515
|
];
|
|
2555
2516
|
case "assignref":
|
|
2556
2517
|
case "assign": {
|
|
@@ -2558,10 +2519,10 @@ function printNode(path, options, print) {
|
|
|
2558
2519
|
|
|
2559
2520
|
return printAssignment(
|
|
2560
2521
|
node.left,
|
|
2561
|
-
|
|
2522
|
+
print("left"),
|
|
2562
2523
|
[" ", hasRef ? "=" : node.operator],
|
|
2563
2524
|
node.right,
|
|
2564
|
-
|
|
2525
|
+
print("right"),
|
|
2565
2526
|
hasRef,
|
|
2566
2527
|
options
|
|
2567
2528
|
);
|
|
@@ -2665,8 +2626,8 @@ function printNode(path, options, print) {
|
|
|
2665
2626
|
|
|
2666
2627
|
const printedFalseExpr =
|
|
2667
2628
|
node.falseExpr.kind === "bin"
|
|
2668
|
-
? indent(
|
|
2669
|
-
:
|
|
2629
|
+
? indent(print("falseExpr"))
|
|
2630
|
+
: print("falseExpr");
|
|
2670
2631
|
const part = [
|
|
2671
2632
|
node.trueExpr ? line : " ",
|
|
2672
2633
|
"?",
|
|
@@ -2674,8 +2635,8 @@ function printNode(path, options, print) {
|
|
|
2674
2635
|
? [
|
|
2675
2636
|
" ",
|
|
2676
2637
|
node.trueExpr.kind === "bin"
|
|
2677
|
-
? indent(
|
|
2678
|
-
:
|
|
2638
|
+
? indent(print("trueExpr"))
|
|
2639
|
+
: print("trueExpr"),
|
|
2679
2640
|
line,
|
|
2680
2641
|
]
|
|
2681
2642
|
: "",
|
|
@@ -2709,7 +2670,7 @@ function printNode(path, options, print) {
|
|
|
2709
2670
|
];
|
|
2710
2671
|
const breakClosingParens = breakLookupNodes.includes(pureParent.kind);
|
|
2711
2672
|
|
|
2712
|
-
const printedTest =
|
|
2673
|
+
const printedTest = print("test");
|
|
2713
2674
|
|
|
2714
2675
|
if (!node.trueExpr) {
|
|
2715
2676
|
const printed = [
|
|
@@ -2818,7 +2779,7 @@ function printNode(path, options, print) {
|
|
|
2818
2779
|
? "}"
|
|
2819
2780
|
: "";
|
|
2820
2781
|
|
|
2821
|
-
return [open,
|
|
2782
|
+
return [open, print("expression"), close];
|
|
2822
2783
|
}
|
|
2823
2784
|
case "encapsed":
|
|
2824
2785
|
switch (node.type) {
|
|
@@ -2866,7 +2827,7 @@ function printNode(path, options, print) {
|
|
|
2866
2827
|
case "name":
|
|
2867
2828
|
return [node.resolution === "rn" ? "namespace\\" : "", node.name];
|
|
2868
2829
|
case "literal":
|
|
2869
|
-
return
|
|
2830
|
+
return print("value");
|
|
2870
2831
|
case "parentreference":
|
|
2871
2832
|
return "parent";
|
|
2872
2833
|
case "selfreference":
|
|
@@ -2884,7 +2845,7 @@ function printNode(path, options, print) {
|
|
|
2884
2845
|
node.name = normalizeMagicMethodName(node.name);
|
|
2885
2846
|
}
|
|
2886
2847
|
|
|
2887
|
-
return
|
|
2848
|
+
return print("name");
|
|
2888
2849
|
}
|
|
2889
2850
|
case "match": {
|
|
2890
2851
|
const lastArmIndex = node.arms.length - 1;
|
|
@@ -2914,7 +2875,7 @@ function printNode(path, options, print) {
|
|
|
2914
2875
|
[",", line, print(condPath)].slice(condIdx === 0 ? 2 : 0),
|
|
2915
2876
|
"conds"
|
|
2916
2877
|
);
|
|
2917
|
-
const body =
|
|
2878
|
+
const body = print("body");
|
|
2918
2879
|
const maybeEmptyLineBetweenArms =
|
|
2919
2880
|
armIdx > 0 &&
|
|
2920
2881
|
isPreviousLineEmpty(options.originalText, armNode, options)
|
|
@@ -2937,7 +2898,7 @@ function printNode(path, options, print) {
|
|
|
2937
2898
|
}, "arms");
|
|
2938
2899
|
return group([
|
|
2939
2900
|
"match (",
|
|
2940
|
-
group([softline, indent(
|
|
2901
|
+
group([softline, indent(print("cond")), softline]),
|
|
2941
2902
|
") {",
|
|
2942
2903
|
group(indent([...arms])),
|
|
2943
2904
|
" ",
|
|
@@ -2951,19 +2912,19 @@ function printNode(path, options, print) {
|
|
|
2951
2912
|
? comments.printComments(path.getValue().comments, options)
|
|
2952
2913
|
: "";
|
|
2953
2914
|
case "namedargument":
|
|
2954
|
-
return [node.name, ": ",
|
|
2915
|
+
return [node.name, ": ", print("value")];
|
|
2955
2916
|
|
|
2956
2917
|
case "enumcase":
|
|
2957
2918
|
return group([
|
|
2958
2919
|
"case ",
|
|
2959
|
-
|
|
2920
|
+
print("name"),
|
|
2960
2921
|
node.value
|
|
2961
2922
|
? [
|
|
2962
2923
|
" =",
|
|
2963
2924
|
printAssignmentRight(
|
|
2964
2925
|
node.name,
|
|
2965
2926
|
node.value,
|
|
2966
|
-
|
|
2927
|
+
print("value"),
|
|
2967
2928
|
false,
|
|
2968
2929
|
options
|
|
2969
2930
|
),
|