Script tags & AST Strructure / Introducing Breaking Changes
See original GitHub issueThe A
from AST stands for Abstract, meaning it does not matters about source code formatting. This can result to removing/loosing some extra informations, and that makes impossible to transform AST back to the original source.
The reason why AST is like that is because it’s purpose is to be an intermediate machine language/structure, it’s used by a VM or JIT machine in order to generate atomic machine instructions.
But as php-parser
is mainly used to edit PHP sources, and the next major release introduce anyway breaking changes that the good time to decide the AST orientations.
If I choose to keep on AST the same structure as the document, the script tag nodes may also be included as an AST node in order to be able to scan something like this :
<?php /** HELLO **/ ?>
<?php /** WORLD **/ ?>
@czosel & @evilebottnawi - do you see any other missing use case where the formatting is lost ?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:11 (4 by maintainers)
Top GitHub Comments
@ichiriac we use own algorithm to attach comment, it is simple comment location should fit in new
script
node ast location@ichiriac maybe it is good idea introduce
PHPExpressionContainer
(or maybe better name) when we found<?php ?>
/<?php
(looks same for JSX https://astexplorer.net/#/gist/31725f76a8a3a6c33da02d098f4aa3ac/fe432a1b03023d56693a2e26e8f3edaaca15b8e9). It is allow to detect when we should print<?php
and?>
, usegroup
for all content and detect indent for this.Now we print
?>
beforeinline
and<?php
after inline (it is very dirty solution and doesn’t work as expected in some cases), Also please look oninnerComments
, it is allow to print comments in empty expression: