Skip to content

Comments aren't emitted if they are in a tag #170

@AngusMorton

Description

@AngusMorton

Version: 5.5.1

I suspect this is a known limitation and/or expected behaviour, but it was surprising! For context, I'm building a prettier plugin that uses the htmljs-parser directly to format Marko files.

Details

There are two related issues:

  • Comments within an open tag are not emitted in onComment. They are included in the value of onAttrValue.
  • When parsing a tag with a comment before the first attribute, the parser does not emit the comment (as far as I can tell).
<meta 
    // I disappear when consumed by the htmljs-parser.
    name="viewport" 
>

onComment is never called, and there is no attribute value, so the comment is removed if processed by dependent tooling like the marko compiler (and therefore marko-plugin-prettier).

Using HTML-style comments also throws an error because the parser expects a TypeScript type argument.

<meta 
    <!-- I throw Unexpected types argument -->
    name="viewport" 
>

While after the attribute, the value is included in onAttrValue of the previous attribute.

<meta 
    name="viewport" 
    // I'm included in name="viewport".
>

it parsed as an onAttrValue with a value of:

"viewport" 
    // I'm included in name="viewport".

I would have expected two values emitted, onAttrValue of "viewport" and onComment with // I'm included in name="viewport"..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions