Skip to content

Proposed changes for 0.1.0 #349

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 5 commits into from
Jun 11, 2021
Merged

Conversation

TysonAndre
Copy link
Contributor

@TysonAndre TysonAndre commented Dec 15, 2020

Drop support for byRefToken in ArgumentExpression - it's a syntax error
in php 7.0+ and is prohibited in php 5.4+.

Convert the foo and otherFooList to fooList for union types in catch
name lists, parameters, properties, and return union types.

Remove ThrowStatement in favor of ThrowExpression for php 8.0.
Remove EchoExpression in favor of EchoStatement - echo cannot be used as
an expression.

Remove statement from NamedLabelStatement - it's always null since a
named label is a single statement by itself.

TODO: Consistently support MissingToken in a single-element list in cases where
a non-empty list is required, such as after ? in types
(php 8.0 union types forbid combining ? with multiple types)

TODO: Check for any regressions in diagnostics

TODO: Validate that this can be used with real projects if they are refactored to use the new API

Rename to getFullStartPosition and getStartPosition

Consistently end public API methods with Position.
Avoid the need for callers to check if an object is a Node/Token before
calling a method.

For #329
NOTE: It may be useful to create a new v1 branch or other name for the newly created major version - I don't think it was created yet

@TysonAndre TysonAndre marked this pull request as draft December 15, 2020 18:31
@roblourens roblourens changed the base branch from master to v0.1.0 December 21, 2020 19:54
@roblourens
Copy link
Member

roblourens commented Dec 21, 2020

This all looks fine so far, thanks! Moved to a v0.1.0 branch. Will call it that for now, that still implies a backwards-incompatible change under semver for 0.x.y.

Drop support for byRefToken in ArgumentExpression - it's a syntax error
in php 7.0+ and is prohibited in php 5.4+.

Convert the foo and otherFooList to fooList for union types in catch
name lists, parameters, properties, and return union types.

Remove ThrowStatement in favor of ThrowExpression for php 8.0.
Remove EchoExpression in favor of EchoStatement - echo cannot be used as
an expression.

Remove statement from NamedLabelStatement - it's always null since a
named label is a single statement by itself.

TODO: Consistently support MissingToken in a single-element list in cases where
a non-empty list is required, such as after `?` in types
(php 8.0 union types forbid combining `?` with multiple types)

TODO: Check for any regressions in diagnostics

TODO: Validate that this can be used with real projects
@TysonAndre TysonAndre changed the title [WIP] Proposed changes for 1.0.0 Proposed changes for 0.1.0 Apr 29, 2021
Raise the minimum php version from 7.0 to 7.2.
Depend on phpunit 8 for local development

Unify method names for Node and Token to getFullStartPosition and getStartPosition
(Consistently end public API methods with Position).
Avoid the need for callers to check if an object is a Node/Token before
calling a method.

Convert UnsetIntrinsicExpression to UnsetStatement - it can only be used
as a statement.

Unify previously split up lists into a single list in some AST node
properties (initially done that way for backward compatibility)

Clean up unnecessary special case for throw
- This continues to be parsed as an ExpressionStatement with the same
  precedence

Rename throwStatement to throwExpression in test file names.
@TysonAndre TysonAndre marked this pull request as ready for review April 29, 2021 21:22
(Using short arrays for array destructuring requires php 7.1)
@TysonAndre
Copy link
Contributor Author

This is ready for review. Note that the target v0.1.0 branch should be reset to the commit of the main branch to filter out commits that were already approved and merged (such as enum support)

Note that in .travis.yml, 8.0 becomes the number 8, which gets treated like the string '8', which typically means the latest stable 8.x release.

@roblourens roblourens changed the base branch from v0.1.0 to main May 11, 2021 17:59
@roblourens roblourens changed the base branch from main to v0.1.0 May 11, 2021 17:59
@TysonAndre
Copy link
Contributor Author

@roblourens thoughts?

@roblourens
Copy link
Member

Sorry @TysonAndre, I will look at it this week

class MissingToken extends Token {
public function __construct(int $kind, int $fullStart) {
parent::__construct($kind, $fullStart, $fullStart, 0);
}

#[ReturnTypeWillChange]
public function jsonSerialize() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://wiki.php.net/rfc/internal_method_return_types adds support for tentative return types, and :mixed was later added to JsonSerializable's method in 8.1 in php/php-src#7051 . This means that implementations will have to return something (or throw), and also that the absence of a return type will emit a warning.

  • fixes vendor/microsoft/tolerant-php-parser/src/Token.php:113 [8192] Declaration of Microsoft\PhpParser\Token::jsonSerialize() should be compatible with JsonSerializable::jsonSerialize(): mixed (a warning, not an error)

Because php 7 is still supported, add an annotation to suppress the warning instead.

Eventually this may have to drop support for 7.x because the mixed type requires 8.0, but that's probably enough time, but that depends on how many 8.x minor releases there are, which is unknown

Copy link
Member

@roblourens roblourens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work @TysonAndre, sorry for the slow review. I am happy with this. Is this ready to merge and publish as 0.1.0?

@TysonAndre
Copy link
Contributor Author

Is this ready to merge and publish as 0.1.0?

Yes, it is

@roblourens roblourens merged commit 769b9d9 into microsoft:v0.1.0 Jun 11, 2021
@TysonAndre TysonAndre deleted the v1-refactor branch July 8, 2021 13:52
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