yiisoft/composer-config-plugin

Arrow function syntax produces invalid output

rvkulikov opened this issue · 3 comments

Usage of arrow function syntax produces redundant semicolon in assembled files.

What steps will reproduce the problem?

Create two files with the following content:

composer.json

{
  "minimum-stability": "dev",
  "require": {
    "yiisoft/composer-config-plugin": "dev-master"
  },
  "extra": {
    "config-plugin-output-dir": "out",
    "config-plugin": {
      "config": [
        "config.php"
      ]
    }
  }
}

config.php

<?php
// trailing comma does not matter
return [
    'key' => fn() => 'value'
];

execute

composer u

What is the expected result?

File out/config.php contains the following code:

<?php

$baseDir = dirname(__DIR__, 1);

$_ENV = array_merge((array) require __DIR__ . '/envs.php', $_ENV);



$params = (array) require __DIR__ . '/params.php';

return [
    'key' => fn() => 'value'
, // note: no semicolon here
];

What do you get instead?

File out/config.php has the following code:

<?php

$baseDir = dirname(__DIR__, 1);

$_ENV = array_merge((array) require __DIR__ . '/envs.php', $_ENV);



$params = (array) require __DIR__ . '/params.php';

return [
    'key' => fn() => 'value'
;, // note: redundant semicolon here
];

Additional info

Q A
Version dev-master (5f76666)
Composer Version 1.10.1
PHP version 7.4.3
Operating system Ubuntu 20.04 LTS (Focal Fossa)

This section of readme https://github.com/yiisoft/composer-config-plugin#known-issues
says that "Anonymous functions must be used in multiline form only".

I've thought that it should be solved here initially for arrow functions (since minimum php version is 7.4) after migrating from hiqdev.

Arrow function syntax has very specific constraint: it is one line only. So I think it can be solved here (just for short arrow functions, not for regular functions).

If it is assumed that arrow function syntax will not be supported, then you can close the ticket

Solved in #54