Make remainingTargetNames consistent, avoid php notice

Add a test of parsing an empty `insteadof` clause

Make remainingTargetNames consistently be an empty array instead of null
This commit is contained in:
Tyson Andre 2018-05-12 11:58:41 -07:00
Родитель f297043862
Коммит 797f79578d
11 изменённых файлов: 194 добавлений и 11 удалений

Просмотреть файл

@ -2950,15 +2950,15 @@ class Parser {
if ($traitSelectAndAliasClause->asOrInsteadOfKeyword->kind === TokenKind::InsteadOfKeyword) { if ($traitSelectAndAliasClause->asOrInsteadOfKeyword->kind === TokenKind::InsteadOfKeyword) {
// https://github.com/Microsoft/tolerant-php-parser/issues/190 // https://github.com/Microsoft/tolerant-php-parser/issues/190
// TODO: In the next backwards incompatible release, convert targetName to a list? // TODO: In the next backwards incompatible release, convert targetName to a list?
$interfaceNameList = $this->parseQualifiedNameList($traitSelectAndAliasClause)->children; $interfaceNameList = $this->parseQualifiedNameList($traitSelectAndAliasClause)->children ?? [];
$traitSelectAndAliasClause->targetName = $interfaceNameList[0] ?? null; $traitSelectAndAliasClause->targetName = $interfaceNameList[0] ?? new MissingToken(TokenKind::BarToken, $this->token->fullStart);
$traitSelectAndAliasClause->remainingTargetNames = array_slice($interfaceNameList, 1); $traitSelectAndAliasClause->remainingTargetNames = array_slice($interfaceNameList, 1);
} else { } else {
$traitSelectAndAliasClause->targetName = $traitSelectAndAliasClause->targetName =
$this->parseQualifiedNameOrScopedPropertyAccessExpression($traitSelectAndAliasClause); $this->parseQualifiedNameOrScopedPropertyAccessExpression($traitSelectAndAliasClause);
$traitSelectAndAliasClause->remainingTargetNames = [];
} }
// TODO errors for insteadof/as // TODO errors for insteadof/as
return $traitSelectAndAliasClause; return $traitSelectAndAliasClause;
}; };

Просмотреть файл

@ -90,7 +90,7 @@
] ]
} }
}, },
"remainingTargetNames": null "remainingTargetNames": []
} }
} }
] ]

Просмотреть файл

@ -128,7 +128,7 @@
] ]
} }
}, },
"remainingTargetNames": null "remainingTargetNames": []
} }
}, },
{ {

Просмотреть файл

@ -95,7 +95,7 @@
] ]
} }
}, },
"remainingTargetNames": null "remainingTargetNames": []
} }
}, },
{ {

Просмотреть файл

@ -99,7 +99,7 @@
] ]
} }
}, },
"remainingTargetNames": null "remainingTargetNames": []
} }
}, },
{ {

Просмотреть файл

@ -96,7 +96,7 @@
] ]
} }
}, },
"remainingTargetNames": null "remainingTargetNames": []
} }
}, },
{ {
@ -157,7 +157,7 @@
] ]
} }
}, },
"remainingTargetNames": null "remainingTargetNames": []
} }
}, },
{ {

Просмотреть файл

@ -149,7 +149,7 @@
] ]
} }
}, },
"remainingTargetNames": null "remainingTargetNames": []
} }
}, },
{ {

Просмотреть файл

@ -0,0 +1,8 @@
<?php
// https://github.com/Microsoft/tolerant-php-parser/issues/98
class A {
use X, Y, Z {
\X::b insteadof;
}
}

Просмотреть файл

@ -0,0 +1,8 @@
[
{
"kind": 0,
"message": "'|' expected.",
"start": 121,
"length": 0
}
]

Просмотреть файл

@ -0,0 +1,167 @@
{
"SourceFileNode": {
"statementList": [
{
"InlineHtml": {
"scriptSectionEndTag": null,
"text": null,
"scriptSectionStartTag": {
"kind": "ScriptSectionStartTag",
"textLength": 6
}
}
},
{
"ClassDeclaration": {
"abstractOrFinalModifier": null,
"classKeyword": {
"kind": "ClassKeyword",
"textLength": 5
},
"name": {
"kind": "Name",
"textLength": 1
},
"classBaseClause": null,
"classInterfaceClause": null,
"classMembers": {
"ClassMembersNode": {
"openBrace": {
"kind": "OpenBraceToken",
"textLength": 1
},
"classMemberDeclarations": [
{
"TraitUseClause": {
"useKeyword": {
"kind": "UseKeyword",
"textLength": 3
},
"traitNameList": {
"QualifiedNameList": {
"children": [
{
"QualifiedName": {
"globalSpecifier": null,
"relativeSpecifier": null,
"nameParts": [
{
"kind": "Name",
"textLength": 1
}
]
}
},
{
"kind": "CommaToken",
"textLength": 1
},
{
"QualifiedName": {
"globalSpecifier": null,
"relativeSpecifier": null,
"nameParts": [
{
"kind": "Name",
"textLength": 1
}
]
}
},
{
"kind": "CommaToken",
"textLength": 1
},
{
"QualifiedName": {
"globalSpecifier": null,
"relativeSpecifier": null,
"nameParts": [
{
"kind": "Name",
"textLength": 1
}
]
}
}
]
}
},
"semicolonOrOpenBrace": {
"kind": "OpenBraceToken",
"textLength": 1
},
"traitSelectAndAliasClauses": {
"TraitSelectOrAliasClauseList": {
"children": [
{
"TraitSelectOrAliasClause": {
"name": {
"ScopedPropertyAccessExpression": {
"scopeResolutionQualifier": {
"QualifiedName": {
"globalSpecifier": {
"kind": "BackslashToken",
"textLength": 1
},
"relativeSpecifier": null,
"nameParts": [
{
"kind": "Name",
"textLength": 1
}
]
}
},
"doubleColon": {
"kind": "ColonColonToken",
"textLength": 2
},
"memberName": {
"kind": "Name",
"textLength": 1
}
}
},
"asOrInsteadOfKeyword": {
"kind": "InsteadOfKeyword",
"textLength": 9
},
"modifiers": [],
"targetName": {
"error": "MissingToken",
"kind": "BarToken",
"textLength": 0
},
"remainingTargetNames": []
}
},
{
"kind": "SemicolonToken",
"textLength": 1
}
]
}
},
"closeBrace": {
"kind": "CloseBraceToken",
"textLength": 1
}
}
}
],
"closeBrace": {
"kind": "CloseBraceToken",
"textLength": 1
}
}
}
}
}
],
"endOfFileToken": {
"kind": "EndOfFileToken",
"textLength": 0
}
}
}

Просмотреть файл

@ -90,7 +90,7 @@
] ]
} }
}, },
"remainingTargetNames": null "remainingTargetNames": []
} }
}, },
{ {