Stillat / blade-parser-typescript

A Laravel Blade parser, compiler, and static analyzer written in TypeScript.
https://stillat.com
MIT License
90 stars 3 forks source link

`body` closing tag not being terminated #111

Closed RobertBlaauwendraad closed 3 months ago

RobertBlaauwendraad commented 3 months ago
  <body @php(body_class())>
  <a class="action skip contentarea d-none" href="#contentarea">
    <span>{{ __('Ga naar de inhoud', 'suiteseven') }}</span>
  </a>
  @include('layouts.header' . (features()->get('woocommerce') && is_checkout() ? '-checkout' : ''))
...
  </body>

Gives:

SyntaxError: Opening tag "body" not terminated. (23:3)
[error]   21 |
[error]   22 |
[error] > 23 |   <body <BVP0Uzhv9ZgZRsgXgjB />>
[error]      |   ^^^^^^
[error]   24 |   <a class="action skip contentarea d-none" href="#contentarea">
[error]   25 |     <span>BfDxyyRND9Wn2T4AcFhDjbdfMS6ImHtGpylpaD9wpVAB</span>
[error]   26 |   </a>
[error]   21 |   <body @php(body_class())>
[error]   22 |   <a class="action skip contentarea d-none" href="#contentarea">
[error] > 23 |     <span>{{ __('Ga naar de inhoud', 'suiteseven') }}</span>
[error]      |   ^^^^^^
[error]   24 |   </a>
[error]   25 |   @include('layouts.header' . (features()->get('woocommerce') && is_checkout() ? '-checkout' : ''))
[error]   26 |

Wrapping <body @php(body_class())> and </body> with format-ignore resolves the problem

RobertBlaauwendraad commented 3 months ago

Also, the code inside the <body> tag doesn't get indented, which I think is nice However <html> does give indentation, maybe remove that as well?

JohnathonKoster commented 3 months ago

I cannot reproduce this with the provided template. This is usually caused by having unpaired elements (such as those inside conditions/etc.), which causes issues with prettier. I would also check to see if this is caused by something similar to this on your end:

https://github.com/Stillat/blade-parser-typescript/issues/109#issuecomment-2278090058

Feel free to re-open if that is not the case.

Also, the code inside the tag doesn't get indented, which I think is nice However does give indentation, maybe remove that as well?

IF the formatter encounters a catastrophic error, the original content will be returned. With valid input, code inside the <body> will get indented.

RobertBlaauwendraad commented 1 month ago

This bug is caused by the @php(body_class()) part inside of the <body> tag. Without it, it runs perfectly fine and indents it just as you said. Are you able to reproduce it now?

By the way, I can't re-open this issue :)

JohnathonKoster commented 1 month ago

Thanks for the extra info. Are you running on the latest version? I will double check a few things on my end, but still haven't reproduced this one (but don't think you're wrong)

RobertBlaauwendraad commented 1 month ago

Yes I'm on the latest version. It seems that the @php(body_class()) part duplicates the body, a and span tags and therefore thinks the first body tag isn't closed?