diff --git a/package.json b/package.json index bfc85b255..1ef1e88ce 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ ], "dependencies": { "linguist-languages": "^8.0.0", - "php-parser": "^3.1.5" + "php-parser": "^3.2.4" }, "devDependencies": { "@babel/preset-env": "^7.27.2", diff --git a/src/options.mjs b/src/options.mjs index 93fca45dc..b431fdf0d 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -23,6 +23,7 @@ export default { { value: "8.0" }, { value: "8.1" }, { value: "8.2" }, + { value: "8.3" }, ], }, trailingCommaPHP: { diff --git a/src/printer.mjs b/src/printer.mjs index cec72d0f7..69300dec9 100644 --- a/src/printer.mjs +++ b/src/printer.mjs @@ -2308,6 +2308,7 @@ function printNode(path, options, print) { node.final ? "final " : "", node.visibility ? [node.visibility, " "] : "", "const", + node.type ? [node.nullable ? " ?" : " ", print("type")] : "", firstVariable ? [" ", firstVariable] : "", indent(printed.slice(1).map((p) => [",", hardline, p])), ]); diff --git a/tests/class/__snapshots__/jsfmt.spec.mjs.snap b/tests/class/__snapshots__/jsfmt.spec.mjs.snap index a8fda07f4..cf60d29d6 100644 --- a/tests/class/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/class/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`anonymous.php 1`] = ` ====================================options===================================== @@ -918,6 +918,31 @@ readonly class ReadOnlyCls { class FinalCost { final public const FOO = 'foo'; } +// PHP 8.3 typed class constants +enum E { + const string TEST = "Test1"; // E::TEST is a string +} + +trait T { + const string TEST = E::TEST; // T::TEST is a string too +} + +interface I { + const string TEST = E::TEST; // I::TEST is a string as well +} + +class Foo implements I { + use T; + + const string TEST = E::TEST; // Foo::TEST must also be a string +} + +class Bar extends Foo { + const string TEST = "Test2"; // Bar::TEST must also be a string, but the value can change + public const int|null I = null; + public const ?int J = null; +} + =====================================output=====================================