Skip to content

LWC parser should use textToDoc to parse interpolated attributes #5816

@ntotten

Description

@ntotten

The current implementation of the LWC parser uses the raw interpolated attributes as is, without modification. It would be preferred to run textToDoc on them to also apply formatting to those values (i.e. change " to ')

Prettier pr-5800
Playground link

--parser lwc
--single-quote

Input:

<div data-for={foo["baz"]}></div>

Output:

SyntaxError: Unexpected closing tag "div". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (1:28)
> 1 | <div data-for={foo["baz"]}></div>
    |                            ^

Expected behavior:
The output should format the interpolated value using prettier as well. It should look like:

<div data-for={foo['baz']}></div>

See conversation: #5800 (comment)

This issue requires the HTML parser to support quotes in interpolated attributes: #5815

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:htmlIssues affecting HTML (and SVG but not JSX)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions