Skip to content

Fixes #189 : Fix parsing edge cases in yield statements #232

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

Merged
merged 1 commit into from
Mar 18, 2018

Conversation

TysonAndre
Copy link
Contributor

Update tests diagnostics and expected generated ASTs

For backwards compatibility, continue to make yield from expr
have an ArrayElement as a child node.

To maintain the invariant that all Nodes must have at least one child,
make $yieldExpression->arrayElement be null when parsing yield;

Aside: yield &$a; is (and should be)
parsed as the binary operator (yield) & ($a).
This is surprising, but makes sense, being the only sane parse tree.

Verified with the PHP module nikic/php-ast (generates AST_BINARY_OP)

var_export(ast_dump(
    ast\parse_code('<?php function test() { yield & $x; }', 50)
));

Misc: Fix wrong param name in doc.

@TysonAndre
Copy link
Contributor Author

Made $yieldExpression->arrayElement be null for yield;, that was accidentally left out.

Added unit tests for yield & &$x (invalid) and yield &&$x (valid use of && operator in php 7)

Update tests diagnostics and expected generated ASTs

For backwards compatibility, continue to make `yield from expr`
have an ArrayElement as a child node.

To maintain the invariant that all Nodes must have at least one child,
make $yieldExpression->arrayElement be null when parsing `yield;`

Aside: `yield &$a;` is (and should be)
parsed as the binary operator `(yield) & ($a)`.
This is surprising, but makes sense, being the only sane parse tree.

- Add a unit test that `yield & &$a;` is invalid.
  There is no way to parse that.

Verified with the PHP module nikic/php-ast

```php
var_export(ast_dump(
    ast\parse_code('<?php function test() { yield & $x; }', 50)
));
```
@roblourens roblourens merged commit 90dc39f into microsoft:master Mar 18, 2018
@TysonAndre TysonAndre deleted the fix-empty-yield branch June 19, 2018 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants