-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid output caused by combo of if statement, inline node, and comment #517
Comments
We're currently changing on the printing of only-comment code blocks by manually adding new AST nodes that represent them in #513. On that branch your example is formatted as <?php
if (true) { ?>inline<?php }
// comment which is not pretty, but at least seems to be valid PHP. Ultimately, I think we'll need the fix suggested in glayzzle/php-parser#170 to fix this for good. |
@evilebottnawi I’d recommend to merge #513, because it makes comment handling much simpler on the printing side. Let me know if there’s anything you’d still like to change in #513. |
@evilebottnawi The only way to fix this seems to be to add support for "only-comment" AST nodes in the parser. Do you agree? |
@czosel need investigate, feel free to experiment. Inline nodes is the most difficult part, comments also, together is incredibly difficult. |
Hello, I took a stab at this and I was able to remove the double comment and the extra closing tag. nikolasmatt@6b30d2f <?php
if (true) { ?>inline<?php
// comment
} This is ugly but non-breaking. I've hit a wall on how to make the block break appropriately. Any guidance would be much appreciated. |
I think I ran into this today, as well. Here is the example that bit me. (Sorry if this is a different problem; I can open a new issue if so.) Input
Output (note the extra
Which of course produces an error:
This was with Prettier 1.15.2 and plugin-php 0.9.0. |
@claytonrcarter yep, it is bug, need fix |
@czosel I will spend the whole weekend to come up with an algorithm for the best way to print them, but i have some examples where don't have idea how better print. Examples: <?php if (
$veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable ||
$veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable
) { ?>
<div>Test</div>
<?php } ?> Oh my good: <?php if (
$veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable ||
$veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable
) {
if ($veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable) { ?>
<div>Test</div>
<?php } ?> test <?php } ?> Any ideas, other examples? It is last what we should do and we can release stable version, support php7.3 we can implement in |
@evilebottnawi My feeling is that the whole inline topic is not something that can be solved in a "perfect" way - there is just too much freedom in mixing PHP with HTML. I'd suggest approaching the issue like this:
What do you think? |
We already do this in many cases.
Yep
Some edge cases already fixed, but i want implement algorithm what cover 90%-95% cases. I have some ideas. Printing inline is difficult only for |
I'm running into the same issue on the latest version (v0.10.2). Is there a recommended fix for this issue? I tried out the https://github.com/prettier/plugin-php/tree/issue-517 branch and it mostly works, except that running Should we be watching #1053 instead for a resolution? Thanks! |
Input:
Output:
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.
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
The text was updated successfully, but these errors were encountered: