Plugin-php: impossible detect two php tags

Created on 7 Mar 2018  路  12Comments  路  Source: prettier/plugin-php

<div></div>
<?php echo 'test'; ?>
<?php echo 'test'; ?>
<div></div>
bug inline

Most helpful comment

Fixed

All 12 comments

@evilebottnawi this is fixed right?

@mgrip no

ok so just checked, and this works, but you loose the 2nd php tag

<div></div>
<?php
echo 'test';
echo 'test';
?>
<div></div>

Maybe this is just personal preference but I think the way we currently output is fine?

@mgrip it is other discussion, by default we don't change ast

Just a heads up --

<div></div>
<?php echo 'test'; ?>
<?php echo 'test'; ?>
<div></div>

does not equal

<div></div>
<?php
echo 'test';
echo 'test';
?>
<div></div>

There's a new line character that's now missing. That's important for .phtml that frequently interweaves PHP blocks. Not sure by last comment if the second block is the resulting code; however, it should not. It should keep all php tags and corresponding spacing outside the php blocks.

/cc @mgrip what do you think, after refactor inline, it is easy fix?

Unfortunately the parser treats the 2 cases exactly the same - ideally it would pick up the case with 2 sets of tags as having an extra inline node in between the two echo nodes. _But_ the parent program node does have the source prop - we could theoretically check this to see if there to find the extra tags. So definitely possible, i can try to take a look today or monday.

@mgrip what about looks in source code?

Yup! That's probably how we'll have to do it - but we'll have to look in the parent program node - the tags don't exist in the source prop for either of the echo nodes

image

@mgrip maybe need investigate

Fixed

Was this page helpful?
0 / 5 - 0 ratings