Skip to content

endIndex less than startIndex for implied tags #896

@thewilkybarkid

Description

@thewilkybarkid

If I have

const p = new Parser({ onclosetag(name) {
  console.log({
    name,
    startIndex: p.startIndex,
    endIndex: p.endIndex,
  })
}})

and I run

p.write("<p>Foo</p><hr>");

I get

{ name: 'p', startIndex: 6, endIndex: 9 }
{ name: 'hr', startIndex: 10, endIndex: 13 }

But if I don't include the optional end tag for the <p>:

p.write("<p>Foo<hr>");

I get

{ name: 'p', startIndex: 6, endIndex: 9 }
{ name: 'hr', startIndex: 10, endIndex: 9 }

The endIndex for the hr doesn't seem to have been set, so it's the same as for the <p>. This trips up PostHTML's sourceLocations option (posthtml/posthtml-parser#63), which finds an endIndex less than a startIndex. This option is now used by Parcel, leading to parcel-bundler/parcel#6672.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions