Skip to content

Commit 029d04f

Browse files
authored
[8.1] Add support for readonly properties (#1917)
1 parent 5aca15c commit 029d04f

6 files changed

Lines changed: 20 additions & 9 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"linguist-languages": "^7.5.1",
1515
"mem": "^8.0.0",
16-
"php-parser": "3.1.0-beta.1"
16+
"php-parser": "3.1.0-beta.4"
1717
},
1818
"devDependencies": {
1919
"@babel/preset-env": "^7.16.11",

src/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = {
2323
{ value: "7.3" },
2424
{ value: "7.4" },
2525
{ value: "8.0" },
26+
{ value: "8.1" },
2627
],
2728
},
2829
trailingCommaPHP: {

src/printer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,7 @@ function printNode(path, options, print) {
18211821
const name = concat([
18221822
...printAttrs(path, options, print, { inline: true }),
18231823
promoted,
1824+
node.readonly ? "readonly " : "",
18241825
node.nullable ? "?" : "",
18251826
node.type ? concat([path.call(print, "type"), " "]) : "",
18261827
node.byref ? "&" : "",
@@ -1859,6 +1860,7 @@ function printNode(path, options, print) {
18591860
case "property":
18601861
return group(
18611862
concat([
1863+
node.readonly ? "readonly " : "",
18621864
node.type
18631865
? concat([node.nullable ? "?" : "", path.call(print, "type"), " "])
18641866
: "",

tests/class/__snapshots__/jsfmt.spec.js.snap

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ abstract class ReallyReallyReallyLongClassName extends AbstractModelFactoryResou
655655
public $test;
656656
public $other = 1;
657657
public static $staticTest = ['hi'];
658+
public readonly int $readonlytype;
658659
static $cache;
659660
protected static $_instance;
660661
protected $fillable = ['title', 'requester_id', 'type', 'summary', 'proof'];
@@ -672,7 +673,7 @@ abstract class ReallyReallyReallyLongClassName extends AbstractModelFactoryResou
672673
*
673674
* @return \\Some\\Test
674675
*/
675-
public function __construct($test, $test_int = null, $test_string = 'hi') {
676+
public function __construct($test, $test_int = null, $test_string = 'hi', readonly int $test_readonly, public readonly string $test_promoted_readonly) {
676677
parent::__construct($test_int ?: 1);
677678
$this->other = $test_string;
678679
$this->current_version = $current_version ?: new Content_Version_Model();
@@ -965,6 +966,7 @@ abstract class ReallyReallyReallyLongClassName
965966
public $test;
966967
public $other = 1;
967968
public static $staticTest = ["hi"];
969+
public readonly int $readonlytype;
968970
static $cache;
969971
protected static $_instance;
970972
protected $fillable = ["title", "requester_id", "type", "summary", "proof"];
@@ -989,8 +991,13 @@ abstract class ReallyReallyReallyLongClassName
989991
*
990992
* @return \\Some\\Test
991993
*/
992-
public function __construct($test, $test_int = null, $test_string = "hi")
993-
{
994+
public function __construct(
995+
$test,
996+
$test_int = null,
997+
$test_string = "hi",
998+
readonly int $test_readonly,
999+
public readonly string $test_promoted_readonly
1000+
) {
9941001
parent::__construct($test_int ?: 1);
9951002
$this->other = $test_string;
9961003
$this->current_version =

tests/class/class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ abstract class ReallyReallyReallyLongClassName extends AbstractModelFactoryResou
2020
public $test;
2121
public $other = 1;
2222
public static $staticTest = ['hi'];
23+
public readonly int $readonlytype;
2324
static $cache;
2425
protected static $_instance;
2526
protected $fillable = ['title', 'requester_id', 'type', 'summary', 'proof'];
@@ -37,7 +38,7 @@ abstract class ReallyReallyReallyLongClassName extends AbstractModelFactoryResou
3738
*
3839
* @return \Some\Test
3940
*/
40-
public function __construct($test, $test_int = null, $test_string = 'hi') {
41+
public function __construct($test, $test_int = null, $test_string = 'hi', readonly int $test_readonly, public readonly string $test_promoted_readonly) {
4142
parent::__construct($test_int ?: 1);
4243
$this->other = $test_string;
4344
$this->current_version = $current_version ?: new Content_Version_Model();

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,10 +3694,10 @@ path-type@^4.0.0:
36943694
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
36953695
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
36963696

3697-
php-parser@3.1.0-beta.1:
3698-
version "3.1.0-beta.1"
3699-
resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.1.0-beta.1.tgz#bd8cd6d872b0f85f7a59a6b5f019ea8f37c7cbcc"
3700-
integrity sha512-4dvvMO+cDbF+CqgZ+7h87wexInYVoocIAaSO9sc5DRzTVfz914KTk9H9y6QupjHQ3pygXfCbP2LE5zvpexkGXg==
3697+
php-parser@3.1.0-beta.4:
3698+
version "3.1.0-beta.4"
3699+
resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.1.0-beta.4.tgz#a56e3c90e0371e41fb9c1a09f4459b5adad2b03b"
3700+
integrity sha512-fLW5tSV8PK0Kizn+Wx1LrhJIFW5eYME4RXoHwIIXfArTBRs7RQJhoU016rXJTPQZIKAXo93ddVyojVvCOETxiA==
37013701

37023702
picocolors@^1.0.0:
37033703
version "1.0.0"

0 commit comments

Comments
 (0)