Stillat / blade-parser

A library that makes it simple to parse, analyze, and manipulate Blade templates. Designed with tool makers in mind ❤️
https://bladeparser.com/
MIT License
125 stars 3 forks source link

Hangs when parsing #3

Closed tacman closed 1 year ago

tacman commented 1 year ago

Most files parse fine, but this one gets stuck.

https://raw.githubusercontent.com/themeselection/sneat-html-laravel-admin-template-free/main/resources/views/content/user-interface/ui-navbar.blade.php

This snippet hangs.

        $parser = new Blade();
        $contents = file_get_contents('https://raw.githubusercontent.com/themeselection/sneat-html-laravel-admin-template-free/main/resources/views/content/user-interface/ui-navbar.blade.php');
        $document = $parser->parse($contents);
tacman commented 1 year ago

This one too:

https://raw.githubusercontent.com/themeselection/sneat-html-laravel-admin-template-free/main/resources/views/content/user-interface/ui-modals.blade.php

JohnathonKoster commented 1 year ago

Yea, there is definitely room for performance optimizations with the current state of the parser. I will most likely end up just porting the work here https://github.com/stillat/blade-parser-typescript back to PHP, since it much more optimized.

JohnathonKoster commented 1 year ago

@tacman Out of curiosity - what kind of information are you looking to extract from your templates? If its a small amount of information, I may be able to reduce the scope of a rewrite (and add other features back over time) and tag a new major version that is more optimized

tacman commented 1 year ago

I'm working on a blade-to-twig converter, so most of it is just getting the @ directives.

But I don't think it's a question of optimization, that file is pretty small, I'm guessing it's a nesting issue, as the only thing that looks different between it and some others that worked is that there's less nesting in the HTML. The actual blade directives are very simple. At least that's just my guess.

On Fri, Nov 18, 2022 at 1:11 PM John Koster @.***> wrote:

@tacman https://github.com/tacman Out of curiosity - what kind of information are you looking to extract from your templates? If its a small amount of information, I may be able to reduce the scope of a rewrite (and add other features back over time) and tag a new major version that is more optimized

— Reply to this email directly, view it on GitHub https://github.com/Stillat/blade-parser/issues/3#issuecomment-1320367016, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEXIQIKRHSQB6CXSJK5YULWI7BGDANCNFSM6AAAAAASEXMT74 . You are receiving this because you were mentioned.Message ID: @.***>

JohnathonKoster commented 1 year ago

Definitely an optimization issue with how it actually traverses the document to find the end of each directive. If its just the directives, that's a pretty simple thing to improve on. I'll look to do that sometime soon, but don't have any hard timelines as to when I'll be able to get around to it right now 🙂

JohnathonKoster commented 1 year ago

I do have a quick fix I'll release this weekend when publishing to packagist, however, to unblock your work :)

tacman commented 1 year ago

Thanks! And if you can look at those two examples, perhaps it is something easy... (always easier to say when someone else is doing the work!)

If nothing else, do you think it can throw an error (that I can catch), since right now it completely hangs, so I have to manually exclude files that don't parse.

Thanks again.

On Fri, Nov 18, 2022 at 1:24 PM John Koster @.***> wrote:

I do have a quick fix I'll release this weekend when publishing to packagist, however, to unblock your work :)

— Reply to this email directly, view it on GitHub https://github.com/Stillat/blade-parser/issues/3#issuecomment-1320380918, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEXIQNNW7NO4UBV5WHMIUDWI7CV7ANCNFSM6AAAAAASEXMT74 . You are receiving this because you were mentioned.Message ID: @.***>

JohnathonKoster commented 1 year ago

A quick fix was added to prevent the infinite loop causing this hanging. This has been included with the first tagged release :)