Skip to content

Commit 4fd2db9

Browse files
authored
Merge pull request #409 from phpactor/readonly-attr
bugfix: Support attributes on readonly classes
2 parents 8781df1 + c660589 commit 4fd2db9

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

src/Parser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ private function parseAttributeStatement($parentNode) {
755755
$statement = $this->parseInterfaceElementFn()($parentNode);
756756
} else {
757757
// Classlikes, anonymous functions, global functions, and arrow functions can have attributes. Global constants cannot.
758-
if (in_array($this->token->kind, [TokenKind::ClassKeyword, TokenKind::TraitKeyword, TokenKind::InterfaceKeyword, TokenKind::AbstractKeyword, TokenKind::FinalKeyword, TokenKind::FunctionKeyword, TokenKind::FnKeyword, TokenKind::EnumKeyword], true) ||
758+
if (in_array($this->token->kind, [TokenKind::ReadonlyKeyword, TokenKind::ClassKeyword, TokenKind::TraitKeyword, TokenKind::InterfaceKeyword, TokenKind::AbstractKeyword, TokenKind::FinalKeyword, TokenKind::FunctionKeyword, TokenKind::FnKeyword, TokenKind::EnumKeyword], true) ||
759759
$this->token->kind === TokenKind::StaticKeyword && $this->lookahead([TokenKind::FunctionKeyword, TokenKind::FnKeyword])) {
760760
$statement = $this->parseStatement($parentNode);
761761
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
#[Foobar]readonly class A {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"SourceFileNode": {
3+
"statementList": [
4+
{
5+
"InlineHtml": {
6+
"scriptSectionEndTag": null,
7+
"text": null,
8+
"scriptSectionStartTag": {
9+
"kind": "ScriptSectionStartTag",
10+
"textLength": 6
11+
}
12+
}
13+
},
14+
{
15+
"ClassDeclaration": {
16+
"attributes": [
17+
{
18+
"AttributeGroup": {
19+
"startToken": {
20+
"kind": "AttributeToken",
21+
"textLength": 2
22+
},
23+
"attributes": {
24+
"AttributeElementList": {
25+
"children": [
26+
{
27+
"Attribute": {
28+
"name": {
29+
"QualifiedName": {
30+
"globalSpecifier": null,
31+
"relativeSpecifier": null,
32+
"nameParts": [
33+
{
34+
"kind": "Name",
35+
"textLength": 6
36+
}
37+
]
38+
}
39+
},
40+
"openParen": null,
41+
"argumentExpressionList": null,
42+
"closeParen": null
43+
}
44+
}
45+
]
46+
}
47+
},
48+
"endToken": {
49+
"kind": "CloseBracketToken",
50+
"textLength": 1
51+
}
52+
}
53+
}
54+
],
55+
"abstractOrFinalModifier": {
56+
"kind": "ReadonlyKeyword",
57+
"textLength": 8
58+
},
59+
"modifiers": [],
60+
"classKeyword": {
61+
"kind": "ClassKeyword",
62+
"textLength": 5
63+
},
64+
"name": {
65+
"kind": "Name",
66+
"textLength": 1
67+
},
68+
"classBaseClause": null,
69+
"classInterfaceClause": null,
70+
"classMembers": {
71+
"ClassMembersNode": {
72+
"openBrace": {
73+
"kind": "OpenBraceToken",
74+
"textLength": 1
75+
},
76+
"classMemberDeclarations": [],
77+
"closeBrace": {
78+
"kind": "CloseBraceToken",
79+
"textLength": 1
80+
}
81+
}
82+
}
83+
}
84+
}
85+
],
86+
"endOfFileToken": {
87+
"kind": "EndOfFileToken",
88+
"textLength": 0
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)