diff --git a/package.json b/package.json index bb2c4c42e..61b649888 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ ], "dependencies": { "linguist-languages": "^8.0.0", - "php-parser": "^3.2.5" + "php-parser": "^3.4.0" }, "devDependencies": { "@babel/preset-env": "^7.27.2", diff --git a/src/options.mjs b/src/options.mjs index e7444d804..e650f85ad 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -7,7 +7,7 @@ const CATEGORY_PHP = "PHP"; const SUPPORTED_PHP_VERSIONS = [ 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, - 8.0, 8.1, 8.2, 8.3, 8.4, + 8.0, 8.1, 8.2, 8.3, 8.4, 8.5, ]; export const LATEST_SUPPORTED_PHP_VERSION = Math.max(...SUPPORTED_PHP_VERSIONS); diff --git a/src/printer.mjs b/src/printer.mjs index c3cf11cd0..67f987c2f 100644 --- a/src/printer.mjs +++ b/src/printer.mjs @@ -1219,7 +1219,7 @@ function printClass(path, options, print) { declaration.push("abstract "); } - if (node.isReadonly) { + if (node.isReadonly && !isAnonymousClass) { declaration.push("readonly "); } @@ -2094,7 +2094,7 @@ function printNode(path, options, print) { () => printAttrs(path, options, print, { inline: true }), "what" ), - "class", + node.what.isReadonly ? "readonly class" : "class", node.arguments.length > 0 ? [" ", printArgumentsList(path, options, print)] : "", diff --git a/src/util.mjs b/src/util.mjs index b4bf9e473..41a415534 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -41,6 +41,7 @@ const PRECEDENCE = new Map( "<<=", ">>=", ], + ["|>"], ["??"], ["||"], ["&&"], diff --git a/tests/pipe/jsfmt.spec.mjs b/tests/pipe/jsfmt.spec.mjs new file mode 100644 index 000000000..49eaa5ec8 --- /dev/null +++ b/tests/pipe/jsfmt.spec.mjs @@ -0,0 +1 @@ +run_spec(import.meta, ["php"], { phpVersion: "8.5" }); diff --git a/tests/pipe/pipe.php b/tests/pipe/pipe.php new file mode 100644 index 000000000..d96ddbddd --- /dev/null +++ b/tests/pipe/pipe.php @@ -0,0 +1,17 @@ + strtoupper(...); +$result = "Hello, World!" |> strtoupper(...) |> trim(...); +$result = "Hello, World!" |> strtoupper(...) |> trim(...) |> htmlspecialchars(...); + +return $value |> transform(...); +echo $value |> format(...); + +if ($x |> validate(...)) {} + +$result = $value |> fn1(...) ?? $fallback; +$result = $value ?? $fallback |> fn1(...); + +foo($value |> transform(...), $other); + +$veryLongVariableName |> someVeryLongFunctionName(...) |> anotherVeryLongFunctionName(...); diff --git a/tests/readonly-class/anonymous.php b/tests/readonly-class/anonymous.php new file mode 100644 index 000000000..1dc0bd302 --- /dev/null +++ b/tests/readonly-class/anonymous.php @@ -0,0 +1,21 @@ +