prettier / prettier/plugin-php

Invalid output caused by combo of if statement, inline node, and comment

オープン
#517 コメント 12 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug high-pri inline
主要言語
PHP
スター
1.9k
フォーク
139
PR マージ指標
30日以内にマージされた PR はありません

説明

Input:

<?php
if (true) {
    ?>inline<?php
    // comment
}

Output:

<?php
if (true) { ?>inline<?php
    // comment
    // comment
    ?>}

Note the extra closing tag that has been added, which makes the code invalid, and that the comment is duplicated, which is unexpected.

If you comment out this line, it doesn't print out the closing tag that breaks the code, but it also removes the closing tag from the test file inline3.php.

If you comment out the line above, prettier throws the following error, I think about inline3.php again.

Comment "// test" was not printed. Please report this error!

I've tried to debug, but the printing system is quite large. I'll still keep looking, but might as well put it out to the community too!

Problem aslo with

<!DOCTYPE html>
<html lang="de">
<head>
    <?php /* ups */
    if (1==1)
    {
        echo 'FOO';
    } ?>
</head>
<body>
</body>
</html>

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

src/printer.js の 1362-1363 行付近から始め、提示された PHP ケースを再現します。出力を tests/comments/inline3.php と比較し、特に inline の閉じタグの動作を確認します。formatter が必要な閉じタグを保持し、無効な追加タグを付加したりコメントを重複させたりせず、既存の inline3.php の期待値も引き続き有効であれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
tooling
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。