Stillat / blade-parser-typescript

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

Element content formatting issue #25

Closed zepfietje closed 1 year ago

zepfietje commented 1 year ago

Input

<span>
    {{ 'foo' }}:
</span>

Output

<span>
    {{ 'foo' }}
    :
</span>

I would expect the input to remain unchanged or be formatted similar to how the following without {{ }} would:

Input

<span>
    foo:
</span>

Output

<span>foo:</span>
JohnathonKoster commented 1 year ago

Due to the implementation - I'm unlikely to change this at the moment (otherwise it breaks a lot of other things)

danharrin commented 1 year ago

The problem is, its does actually affect the output visually. The browser will parse the colon separately to the text, which creates a gap between them

JohnathonKoster commented 1 year ago

Will figure something out 🙂 Its an edge case that breaks for the most part (an annoying one, but I think I can get it sorted)

JohnathonKoster commented 1 year ago

I've updated the inline echo analyzer, and it will now inline them as text when they are surrounded by content. This will let them be treated as text by prettier, but reversed back into the correct Blade echo once transformation is complete.

With the default settings I use for testing, the following input:

<span>
    {{ 'foo' }}:
</span>

becomes:

<span>{{ "foo" }}:</span>

and the echo and its adjacent content are no longer separated.

However, if the echo does not neighbor any meaningful content in either direction (with respect to any child documents), the transformer will force them to be blocks internally to allow for the following:


@if ('foo')
        {{ $actions }}
        @elseif ('bar')
        @endif

to become:

@if ("foo")
    {{ $actions }}
@elseif ("bar")
@endif

P.s - You have all been incredibly patient and awesome with providing examples. Thanks a ton for that!!

danharrin commented 1 year ago

Thank you for your responsivity John!