Skip to content
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

feat(php8 hanging comma) Add support for haning comma for functions, closures, arrow functions and methods #1769

Merged
merged 4 commits into from
Jun 23, 2021

Conversation

cseufert
Copy link
Collaborator

@cseufert cseufert commented Jun 22, 2021

This patch requires the PHP parser support for hanging commas glayzzle/php-parser#756

closes #1759

package.json Outdated Show resolved Hide resolved
Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Anyway good job!

src/printer.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@czosel czosel left a comment

Choose a reason for hiding this comment

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

Looks great otherwise 👍

@czosel czosel merged commit 41347a1 into master Jun 23, 2021
@cseufert cseufert deleted the fix-hanging-comma-func-php8 branch June 23, 2021 05:38
@justim
Copy link
Contributor

justim commented Jul 22, 2021

This change also adds a comma after "parameters" in a use block for a closure — which it should, but the resulting code can not be parsed again.

Input:

<?php

$test = function (SomeClass $one, SomeOtherClass $two, AndAnotherOne $three)
  use ($one, $two, $three, $four, $five, $six, $seven, $eight, $nine, $ten, $eleven)
{
}

Output:

<?php

$test = function (
    SomeClass $one,
    SomeOtherClass $two,
    AndAnotherOne $three,
) use (
    $one,
    $two,
    $three,
    $four,
    $five,
    $six,
    $seven,
    $eight,
    $nine,
    $ten,
    $eleven,
) {};

And using the output as input again give the following message:

Parse Error : syntax error, unexpected ')', expecting T_VARIABLE on line 19

  17 |     $ten,
  18 |     $eleven,
> 19 | ) {};
  20 |

See Prettier playgrounds: before and after.

Is this a quick fix? Or do you want me to look into it?

package.json Outdated
@@ -13,7 +13,7 @@
"dependencies": {
"linguist-languages": "^7.5.1",
"mem": "^8.0.0",
"php-parser": "https://github.com/moddengine/php-parser#c71ee4b5c7bab44dbaf5cb9e9bce7e69b45c23b8"
"php-parser": "hhttps://github.com/glayzzle/php-parser#cca83041d938b972c7ef74648f29de03777b0ea4"
Copy link
Member

Choose a reason for hiding this comment

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

@czosel here bug

Copy link
Contributor

Choose a reason for hiding this comment

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

That's not the latest version you're looking at. It currently links to the right commit on master, and the latest version of this PR as well.

The parses doesn't understand the extra ,.

@alexander-akait
Copy link
Member

@justim your code should work, can you open an new issue (before please test it on the latest version)

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.

PHP8: Trailing comma in method signature
4 participants