Stillat / vscode-antlers-language-server

Provides rich language features for Statamic's Antlers templating language, including code completions, syntax highlighting, and more.
https://antlers.dev
MIT License
38 stars 3 forks source link

Formatting Error - random `undefined` #15

Closed lioneaglesolutions closed 2 years ago

lioneaglesolutions commented 2 years ago

Sorry to open another issue!

When I have a component like below;

{{#
    @name Header
    @desc The sites header rendered on each page.
#}}

<header class="w-full py-4 z-40">
    <div class="fluid-container flex justify-between items-center">
        {{ partial:components/logo width="150" }}
        {{ partial:navigation/main }}
        {{ partial:components/button label="Early Access" class="uppercase shadow-md" variant={{ if current_uri === '/' }} "white" {{ else }} "solid" {{ /if }} }}
    </div>
</header>

Upon formatting, an odd undefined is thrown in in the button partial before the close {{ /if }}

{{#
    @name Header
    @desc The sites header rendered on each page.
#}}

<header class="w-full py-4 z-40">
    <div class="fluid-container flex justify-between items-center">
        {{ partial:components/logo width="150" }}
        {{ partial:navigation/main }}
        {{ partial:components/button label="Early Access" class="uppercase shadow-md" variant={{ if current_uri === '/' }} "white" {{ else }} "solid"
undefined{{ /if }} }}
    </div>
</header>

Not sure if this is a bug, or me not having the right syntax here...

JohnathonKoster commented 2 years ago

No worries!

The nested if statement like that within other tags is technically not supported, and I would recommend something like this for now (even though it is a bit repetitive!):

{{#
    @name Header
    @desc The sites header rendered on each page.
#}}

<header class="w-full py-4 z-40">
    <div class="fluid-container flex justify-between items-center">
        {{ partial:components/logo width="150" }}
        {{ partial:navigation/main }}

        {{ if current_uri === '/' }}
            {{ partial:components/button label="Early Access" class="uppercase shadow-md" variant="white" }}
        {{ else }}
            {{ partial:components/button label="Early Access" class="uppercase shadow-md" variant="solid" }}
        {{ /if }}
    </div>
</header>

Having said that, the formatter definitely shouldn't be adding undefined to the template; this has been resolved as of 1.1.4

lioneaglesolutions commented 2 years ago

Thanks for the tip! I'll update that now. Thanks.