blade-parser-typescript icon indicating copy to clipboard operation
blade-parser-typescript copied to clipboard

Component props sometimes get double quotes

Open adevade opened this issue 9 months ago • 0 comments

Input

@props([
    'as' => 'h1',
    'dot' => true,
])

<{{ $as }} {{ $attributes->class('text-balance text-4xl font-bold tracking-tight text-gray-950 sm:text-6xl') }}>
    {{ $slot }}@if ($dot)<span class="text-red-600">.</span>@endif
</{{ $as }}>

Output

@props([
    "as" => "h1",
    "dot" => true,
])

<{{ $as }} {{ $attributes->class('text-balance text-4xl font-bold tracking-tight text-gray-950 sm:text-6xl') }}>
    {{ $slot }}@if ($dot)<span class="text-red-600">.</span>
    @endif
</{{ $as }}>

.prettierrc

{
    "printWidth": 120,
    "tabWidth": 4,
    "singleQuote": true,
    "trailingComma": "all",
    "plugins": [
        "prettier-plugin-blade"
    ],
    "overrides": [
        {
            "files": [
                "*.blade.php"
            ],
            "options": {
                "parser": "blade"
            }
        }
    ]
}

The reason for formatting the if statement that way is to not have any whitespace between the text and dot. This could of course be done in other ways, but thought I'd report this as a bug anyway.

Adding a space between }} and @if ($dot) fixes the issue with the props getting double quotes. Also, enabling usePint seems to makes it work as well.

adevade avatar Mar 14 '25 14:03 adevade