question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Script tags & AST Strructure / Introducing Breaking Changes

See original GitHub issue

The 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:open
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Feb 18, 2019

@ichiriac we use own algorithm to attach comment, it is simple comment location should fit in new script node ast location

1reaction
alexander-akaitcommented, Oct 9, 2018

@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 ?>, use group for all content and detect indent for this.

Now we print ?> before inline and <?php after inline (it is very dirty solution and doesn’t work as expected in some cases), Also please look on innerComments, it is allow to print comments in empty expression:

<?php
// Comment
?>
Read more comments on GitHub >

github_iconTop Results From Across the Web

The Script element - HTML: HyperText Markup Language
This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a...
Read more >
Abstract syntax tree - Wikipedia
In computer science, an abstract syntax tree (AST), or just syntax tree, is a tree representation of the abstract syntactic structure of text...
Read more >
Introduction to Abstract Syntax Trees - Twilio
AST stands for Abstract Syntax Tree and they power a lot of parts of your ... step would just break down the HTML...
Read more >
Scripts in HTML documents - W3C
Introduction to scripts; Designing documents for user agents that support scripting. The SCRIPT element; Specifying the scripting language.
Read more >
When and how to make breaking changes
Package managers structure the problem and make dependencies and versions explicit [3, 47, 51], and practices like semantic versioning assign ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found