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