Skip to content

InlineHtml::$echoStatement in control statement does not move into statement list. #309

@ngyuki

Description

@ngyuki

Validation code

<?php
require __DIR__ . '/vendor/autoload.php';

$input = <<<'EOS'
<?php if (true): ?><?= 'x' ?><?php endif; ?>
EOS;

$ast = (new Microsoft\PhpParser\Parser())->parseSourceFile($input);
$f = function (Microsoft\PhpParser\Node $node, string $indent = '') use (&$f) {
    echo $indent .  get_class($node) . PHP_EOL;
    foreach ($node->getChildNodes() as $child) {
        $f($child, $indent . '    ');
    }
};
$f($ast);

Expected output

Should include EchoExpression and StringLiteral.

Microsoft\PhpParser\Node\SourceFileNode
    Microsoft\PhpParser\Node\Statement\InlineHtml
    Microsoft\PhpParser\Node\Statement\IfStatementNode
        Microsoft\PhpParser\Node\ReservedWord
        Microsoft\PhpParser\Node\Statement\InlineHtml
        Microsoft\PhpParser\Node\Statement\ExpressionStatement
            Microsoft\PhpParser\Node\Expression\EchoExpression
                Microsoft\PhpParser\Node\DelimitedList\ExpressionList
                    Microsoft\PhpParser\Node\StringLiteral
        Microsoft\PhpParser\Node\Statement\InlineHtml
    Microsoft\PhpParser\Node\Statement\InlineHtml

Actual output

EchoExpression and StringLiteral are not included.

Microsoft\PhpParser\Node\SourceFileNode
    Microsoft\PhpParser\Node\Statement\InlineHtml
    Microsoft\PhpParser\Node\Statement\IfStatementNode
        Microsoft\PhpParser\Node\ReservedWord
        Microsoft\PhpParser\Node\Statement\InlineHtml
        Microsoft\PhpParser\Node\Statement\InlineHtml
    Microsoft\PhpParser\Node\Statement\InlineHtml

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