Skip to content

Commit f0b68cd

Browse files
authored
Merge pull request microsoft#325 from TysonAndre/missing-variable
Warn about missing use variable
2 parents 2096712 + 2e5f566 commit f0b68cd

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

src/Node/AnonymousFunctionUseClause.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Microsoft\PhpParser\Node;
88

9+
use Microsoft\PhpParser\MissingToken;
910
use Microsoft\PhpParser\Node;
1011
use Microsoft\PhpParser\Node\DelimitedList\UseVariableNameList;
1112
use Microsoft\PhpParser\Token;
@@ -17,7 +18,7 @@ class AnonymousFunctionUseClause extends Node {
1718
/** @var Token */
1819
public $openParen;
1920

20-
/** @var UseVariableNameList */
21+
/** @var UseVariableNameList|MissingToken */
2122
public $useVariableNameList;
2223

2324
/** @var Token */

src/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3566,7 +3566,7 @@ function ($parentNode) {
35663566
return $useVariableName;
35673567
},
35683568
$anonymousFunctionUseClause
3569-
);
3569+
) ?: (new MissingToken(TokenKind::VariableName, $this->token->fullStart));
35703570
$anonymousFunctionUseClause->closeParen = $this->eat1(TokenKind::CloseParenToken);
35713571

35723572
return $anonymousFunctionUseClause;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
function () use() {};
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": "'VariableName' expected.",
5+
"start": 22,
6+
"length": 0
7+
}
8+
]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
"ExpressionStatement": {
16+
"expression": {
17+
"AnonymousFunctionCreationExpression": {
18+
"staticModifier": null,
19+
"functionKeyword": {
20+
"kind": "FunctionKeyword",
21+
"textLength": 8
22+
},
23+
"byRefToken": null,
24+
"name": null,
25+
"openParen": {
26+
"kind": "OpenParenToken",
27+
"textLength": 1
28+
},
29+
"parameters": null,
30+
"closeParen": {
31+
"kind": "CloseParenToken",
32+
"textLength": 1
33+
},
34+
"anonymousFunctionUseClause": {
35+
"AnonymousFunctionUseClause": {
36+
"useKeyword": {
37+
"kind": "UseKeyword",
38+
"textLength": 3
39+
},
40+
"openParen": {
41+
"kind": "OpenParenToken",
42+
"textLength": 1
43+
},
44+
"useVariableNameList": {
45+
"error": "MissingToken",
46+
"kind": "VariableName",
47+
"textLength": 0
48+
},
49+
"closeParen": {
50+
"kind": "CloseParenToken",
51+
"textLength": 1
52+
}
53+
}
54+
},
55+
"colonToken": null,
56+
"questionToken": null,
57+
"returnType": null,
58+
"otherReturnTypes": null,
59+
"compoundStatementOrSemicolon": {
60+
"CompoundStatementNode": {
61+
"openBrace": {
62+
"kind": "OpenBraceToken",
63+
"textLength": 1
64+
},
65+
"statements": [],
66+
"closeBrace": {
67+
"kind": "CloseBraceToken",
68+
"textLength": 1
69+
}
70+
}
71+
}
72+
}
73+
},
74+
"semicolon": {
75+
"kind": "SemicolonToken",
76+
"textLength": 1
77+
}
78+
}
79+
}
80+
],
81+
"endOfFileToken": {
82+
"kind": "EndOfFileToken",
83+
"textLength": 0
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)