Skip to content

Commit b5c7cd4

Browse files
authored
Merge pull request microsoft#346 from TysonAndre/attribute-group-missing-error
Warn about #[] attribute groups of 0 length
2 parents 85b40c3 + 0c991bc commit b5c7cd4

File tree

9 files changed

+110
-4
lines changed

9 files changed

+110
-4
lines changed

src/Parser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ private function parseAttributeGroups($parentNode): array
757757
while ($attributeToken = $this->eatOptional1(TokenKind::AttributeToken)) {
758758
$attributeGroup = new AttributeGroup();
759759
$attributeGroup->startToken = $attributeToken;
760-
$attributeGroup->attributes = $this->parseAttributeElementList($attributeGroup);
760+
$attributeGroup->attributes = $this->parseAttributeElementList($attributeGroup)
761+
?: (new MissingToken(TokenKind::Name, $this->token->fullStart));
761762
$attributeGroup->endToken = $this->eat1(TokenKind::CloseBracketToken);
762763
$attributeGroup->parent = $parentNode;
763764
$attributeGroups[] = $attributeGroup;

tests/cases/parser80/attributes16.php.diag

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"start": 12,
1212
"length": 0
1313
},
14+
{
15+
"kind": 0,
16+
"message": "'Name' expected.",
17+
"start": 15,
18+
"length": 0
19+
},
1420
{
1521
"kind": 0,
1622
"message": "']' expected.",

tests/cases/parser80/attributes16.php.tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
"kind": "AttributeToken",
4141
"textLength": 2
4242
},
43-
"attributes": null,
43+
"attributes": {
44+
"error": "MissingToken",
45+
"kind": "Name",
46+
"textLength": 0
47+
},
4448
"endToken": {
4549
"error": "MissingToken",
4650
"kind": "CloseBracketToken",

tests/cases/parser80/attributes17.php.diag

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"start": 15,
1212
"length": 0
1313
},
14+
{
15+
"kind": 0,
16+
"message": "'Name' expected.",
17+
"start": 18,
18+
"length": 0
19+
},
1420
{
1521
"kind": 0,
1622
"message": "']' expected.",

tests/cases/parser80/attributes17.php.tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@
4141
"kind": "AttributeToken",
4242
"textLength": 2
4343
},
44-
"attributes": null,
44+
"attributes": {
45+
"error": "MissingToken",
46+
"kind": "Name",
47+
"textLength": 0
48+
},
4549
"endToken": {
4650
"error": "MissingToken",
4751
"kind": "CloseBracketToken",

tests/cases/parser80/attributes18.php.diag

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"start": 8,
66
"length": 0
77
},
8+
{
9+
"kind": 0,
10+
"message": "'Name' expected.",
11+
"start": 11,
12+
"length": 0
13+
},
814
{
915
"kind": 0,
1016
"message": "']' expected.",

tests/cases/parser80/attributes18.php.tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
"kind": "AttributeToken",
4141
"textLength": 2
4242
},
43-
"attributes": null,
43+
"attributes": {
44+
"error": "MissingToken",
45+
"kind": "Name",
46+
"textLength": 0
47+
},
4448
"endToken": {
4549
"error": "MissingToken",
4650
"kind": "CloseBracketToken",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"kind": 0,
4+
"message": "'Name' expected.",
5+
"start": 8,
6+
"length": 0
7+
}
8+
]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
"error": "MissingToken",
25+
"kind": "Name",
26+
"textLength": 0
27+
},
28+
"endToken": {
29+
"kind": "CloseBracketToken",
30+
"textLength": 1
31+
}
32+
}
33+
}
34+
],
35+
"abstractOrFinalModifier": null,
36+
"classKeyword": {
37+
"kind": "ClassKeyword",
38+
"textLength": 5
39+
},
40+
"name": {
41+
"kind": "Name",
42+
"textLength": 1
43+
},
44+
"classBaseClause": null,
45+
"classInterfaceClause": null,
46+
"classMembers": {
47+
"ClassMembersNode": {
48+
"openBrace": {
49+
"kind": "OpenBraceToken",
50+
"textLength": 1
51+
},
52+
"classMemberDeclarations": [],
53+
"closeBrace": {
54+
"kind": "CloseBraceToken",
55+
"textLength": 1
56+
}
57+
}
58+
}
59+
}
60+
}
61+
],
62+
"endOfFileToken": {
63+
"kind": "EndOfFileToken",
64+
"textLength": 0
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)