support trailing commas

This commit is contained in:
Max Loeb 2019-10-22 08:00:13 -07:00 committed by Ondřej Mirtes
parent f9e4a3b8cb
commit e81bfd8679
2 changed files with 35 additions and 0 deletions

View File

@ -226,6 +226,11 @@ class TypeParser
while ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA)) {
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
if($tokens->tryConsumeTokenType(Lexer::TOKEN_CLOSE_CURLY_BRACKET)) {
// trailing comma case
return new Ast\Type\ArrayShapeNode($items);
}
$items[] = $this->parseArrayShapeItem($tokens);
}

View File

@ -477,6 +477,36 @@ class TypeParserTest extends \PHPUnit\Framework\TestCase
),
]),
],
[
'array{
a: int,
}',
new ArrayShapeNode([
new ArrayShapeItemNode(
new IdentifierTypeNode('a'),
false,
new IdentifierTypeNode('int')
),
]),
],
[
'array{
a: int,
b: string,
}',
new ArrayShapeNode([
new ArrayShapeItemNode(
new IdentifierTypeNode('a'),
false,
new IdentifierTypeNode('int')
),
new ArrayShapeItemNode(
new IdentifierTypeNode('b'),
false,
new IdentifierTypeNode('string')
),
]),
],
[
'array{
a: int,