Merge pull request #233 from TysonAndre/fix-empty-var
Fixes #188: Fix parsing empty variables
This commit is contained in:
Коммит
1bfbd22a93
|
@ -2066,10 +2066,19 @@ class Parser {
|
|||
$variable->dollar = $this->eat1(TokenKind::DollarToken);
|
||||
$token = $this->getCurrentToken();
|
||||
|
||||
$variable->name =
|
||||
$token->kind === TokenKind::OpenBraceToken ?
|
||||
$this->parseBracedExpression($variable) :
|
||||
$this->parseSimpleVariable($variable);
|
||||
switch ($token->kind) {
|
||||
case TokenKind::OpenBraceToken:
|
||||
$variable->name = $this->parseBracedExpression($variable);
|
||||
break;
|
||||
case TokenKind::VariableName:
|
||||
case TokenKind::StringVarname:
|
||||
case TokenKind::DollarToken:
|
||||
$variable->name = $this->parseSimpleVariable($variable);
|
||||
break;
|
||||
default:
|
||||
$variable->name = new MissingToken(TokenKind::VariableName, $token->fullStart);
|
||||
break;
|
||||
}
|
||||
} elseif ($token->kind === TokenKind::VariableName || $token->kind === TokenKind::StringVarname) {
|
||||
// TODO consider splitting into dollar and name.
|
||||
// StringVarname is the variable name without $, used in a template string e.g. `"${foo}"`
|
||||
|
@ -2089,7 +2098,6 @@ class Parser {
|
|||
TokenKind::YieldFromKeyword,
|
||||
TokenKind::YieldKeyword
|
||||
);
|
||||
|
||||
$yieldExpression->arrayElement = $this->parseArrayElement($yieldExpression);
|
||||
return $yieldExpression;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
$x = $;
|
|
@ -0,0 +1,8 @@
|
|||
[
|
||||
{
|
||||
"kind": 0,
|
||||
"message": "'VariableName' expected.",
|
||||
"start": 13,
|
||||
"length": 0
|
||||
}
|
||||
]
|
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"SourceFileNode": {
|
||||
"statementList": [
|
||||
{
|
||||
"InlineHtml": {
|
||||
"scriptSectionEndTag": null,
|
||||
"text": null,
|
||||
"scriptSectionStartTag": {
|
||||
"kind": "ScriptSectionStartTag",
|
||||
"textLength": 6
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"ExpressionStatement": {
|
||||
"expression": {
|
||||
"AssignmentExpression": {
|
||||
"leftOperand": {
|
||||
"Variable": {
|
||||
"dollar": null,
|
||||
"name": {
|
||||
"kind": "VariableName",
|
||||
"textLength": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": {
|
||||
"kind": "EqualsToken",
|
||||
"textLength": 1
|
||||
},
|
||||
"byRef": null,
|
||||
"rightOperand": {
|
||||
"Variable": {
|
||||
"dollar": {
|
||||
"kind": "DollarToken",
|
||||
"textLength": 1
|
||||
},
|
||||
"name": {
|
||||
"error": "MissingToken",
|
||||
"kind": "VariableName",
|
||||
"textLength": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"semicolon": {
|
||||
"kind": "SemicolonToken",
|
||||
"textLength": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"endOfFileToken": {
|
||||
"kind": "EndOfFileToken",
|
||||
"textLength": 0
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче