plugin-php
plugin-php copied to clipboard
multi-line comment duplicated, leaking outside PHP blocks
The obvious problem is that the multi-line comment is being duplicated and jumping outside the PHP block. But it's weirder, variations are below the main report example.
@prettier/plugin-php v0.11.2 Playground link
Input:
<?php ?>
<?php ?>
<?php
/**
* comment
*/
$var = 0;
$var = 1;
?>
<?php ?>
Output:
<?php ?>
/**
* comment
*/<?php
/**
* comment
*/
?>
$var = 0;
$var = 1;
?>
Additional examples (links go to playground variations):
- Add a blank line between the first two
<?php ?>blocks: Works correctly. - Remove all blank lines between
<?php ?>blocks: Works correctly (mostly, whitespace) - Add a single character to the comment (
comments): Works correctly (mostly, whitespace) - Add two characters to the comment (
commentss): Broken
I didn't run into this with empty PHP blocks, here's the are some examples with code in the PHP blocks, behavior appears to be the same:
- Code blocks,
comment: Broken - Code blocks,
comments: Works correctly (mostly, whitespace - Code blocks, no blank lines: Works correctly (mostly, whitespace)
Same problem here
Same happened to me. This bug made me disable prettier for my php files. Such a shame :(.
But still loving prettier! Hopefully this gets fixed soon...
Here's another example that's hapenning for me:
<?php /* Template Name: Printable Page */ ?>
<?php
/**
* The template for displaying printable pages. This is like the default page.php but adds a prominent print button.
*
* @package Polyfoaming
*/
get_header();
set_query_var('show-print-button', true);
?>
is changed to
<?php
/* Template Name: Printable Page */
?>
/**
* The template for displaying printable pages. This is like the default page.php but adds a prominent print button.
*
* @package Polyfoaming
*/<?php
/**
* The template for displaying printable pages. This is like the default page.php but adds a prominent print button.
*
* @package Polyfoaming
*/
?>
get_header();
set_query_var('show-print-button', true);
?>
Yep, bug :disappointed:
We need to find a way to handle <?php and ?> in parser, it is not easy, so any help welcome
We need to find a way to handle
<?phpand?>in parser, it is not easy, so any help welcome
@alexander-akait
Wouldn't that be easy using a regex? I don't know what technique you are using.
But a regex can do this pretty easily, if you are using DFA for parsing however you should chnage your way to PDA therefore you'll be able to handle all those pretty easily.
If you are not using any of this I have no idea then.
Feeling hopeful about this one, didn't realize it was happening upstream too. https://prettier.io/blog/2021/05/09/2.3.0.html#fix-unstable-multiple-comments-on-the-same-line-9672httpsgithubcomprettierprettierpull9672-by-fiskerhttpsgithubcomfisker