Commit 803ddaee authored by David Sveningsson's avatar David Sveningsson

feat(parser): include valueLocation in doctype event

[skip release]
parent a5482eb3
......@@ -29,13 +29,18 @@ Emitted after the parsing has finished loading the DOM tree.
```typescript
{
location: Location,
value: string,
valueLocation: Location,
}
```
Emitted when a doctype is encountered. `value` is the doctype (without
`<doctype` and `>`).
`location` refers to the doctype opening tag and `valueLocation` to the value
(as described above)
## `tag:open`
```typescript
......
......@@ -98,6 +98,9 @@ export interface DirectiveEvent extends Event {
export interface DoctypeEvent extends Event {
/** Selected doctype */
value: string;
/** Location of doctype value */
valueLocation: Location;
}
/**
......
......@@ -790,7 +790,15 @@ describe("parser", () => {
describe("should parse", () => {
it("doctype", () => {
const dom = parser.parseHtml("<!doctype foobar>");
expect(events.shift()).toEqual({ event: "doctype", value: "foobar" });
expect(events.shift()).toEqual({
event: "doctype",
value: "foobar",
valueLocation: expect.objectContaining({
line: 1,
column: 11,
size: 6,
}),
});
expect(events.shift()).toBeUndefined();
expect(dom.doctype).toEqual("foobar");
});
......
......@@ -434,6 +434,7 @@ export class Parser {
this.dom.doctype = value;
this.trigger("doctype", {
value,
valueLocation: tokens[0].location,
location: startToken.location,
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment