-
Notifications
You must be signed in to change notification settings - Fork 64
Support multiple lines for array shape #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
2c684dd
e6ec026
7e0ad3a
414daf3
2e69b9a
571feed
1f26308
52d586e
17d28cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,12 +221,15 @@ private function tryParseArray(TokenIterator $tokens, Ast\Type\TypeNode $type): | |
private function parseArrayShape(TokenIterator $tokens, Ast\Type\TypeNode $type): Ast\Type\TypeNode | ||
{ | ||
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET); | ||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL); | ||
$items = [$this->parseArrayShapeItem($tokens)]; | ||
|
||
while ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA)) { | ||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL); | ||
$items[] = $this->parseArrayShapeItem($tokens); | ||
} | ||
|
||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL); | ||
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_CURLY_BRACKET); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we should also allow line breaks before the comma, so that this works:
We might want to allow trailing commas as well:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. Trailing commas are awesome :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each of these examples should have a separate test case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing commas 571feed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line breaks before commas 1f26308 |
||
|
||
return new Ast\Type\ArrayShapeNode($items); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,7 +393,12 @@ public function provideParseData(): array | |
]), | ||
], | ||
[ | ||
'array{a: int, b: array{c: callable(): int}}', | ||
'array{ | ||
a: int, | ||
b: array{ | ||
c: callable(): int | ||
} | ||
}', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add new test instead of modifying an existing one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the test is incorrect, as it's missing the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it all right if I just add a single test showing that the leading |
||
new ArrayShapeNode([ | ||
new ArrayShapeItemNode( | ||
new IdentifierTypeNode('a'), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
$this->bound !== null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7e0ad3a