Skip to content

Inline comment of constant lost #129

@SyuTingSong

Description

@SyuTingSong

Version: 4.0.6

Bug Description

The inline comment declared begin with // besides constants get lost after fromCode and printFile

Steps To Reproduce

$file = \Nette\PhpGenerator\PhpFile::fromCode(<<<'PHP'
<?php

class A {
    public const HELLO = 'hello'; // some comment

    public function say(string $to): string {
        // just combine hello and $to
        return static::HELLO . ' ' . $to;
    }
}
PHP
);
echo (new \Nette\PhpGenerator\PsrPrinter())->printFile($file);

Actual Result

<?php

class A
{
    public const HELLO = 'hello';

    public function say(string $to): string
    {
        // just combine hello and $to
        return static::HELLO . ' ' . $to;
    }
}

Expected Behavior

Keep the inline comment as well.

<?php

class A
{
    public const HELLO = 'hello'; // some comment

    public function say(string $to): string
    {
        // just combine hello and $to
        return static::HELLO . ' ' . $to;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions