Commit 430ec7c6 authored by David Sveningsson's avatar David Sveningsson
Browse files

feat: `dom:ready` and `dom:load` contains `source` reference

refs #115
parent 4c1d1155
Pipeline #298050023 passed with stages
in 11 minutes and 17 seconds
......@@ -50,17 +50,19 @@ Emitted for each lexer token during parsing.
```typescript
{
source: Source;
}
```
Emitted after initialization but before tokenization and parsing occurs. Can be
used to initialize state in rules.
Emitted after initialization but before tokenization and parsing occurs.
Can be used to initialize state in rules.
### `dom:ready`
```typescript
{
document: DOMTree,
source: Source;
}
```
......
......@@ -7,7 +7,7 @@ import { MetaTable } from "../meta";
import { Parser, ParserError } from "../parser";
import { Reporter } from "../reporter";
import { Rule } from "../rule";
import { ConfigReadyEvent, Event, EventHandler } from "../event";
import { ConfigReadyEvent, DOMLoadEvent, EventHandler } from "../event";
import { Plugin } from "../plugin";
import { Engine } from "./engine";
......@@ -558,8 +558,9 @@ describe("Engine", () => {
offset: 0,
size: 1,
};
const event: Event = {
const event: DOMLoadEvent = {
location,
source: inline("<div></div>"),
};
parser.trigger("dom:load", event);
expect(add).toHaveBeenCalledWith(
......
......@@ -182,12 +182,21 @@ export interface DoctypeEvent extends Event {
valueLocation: Location;
}
/**
* Event emitted after initialization but before tokenization and parsing occurs.
* Can be used to initialize state in rules.
*/
export interface DOMLoadEvent extends Event {
source: Source;
}
/**
* Event emitted when DOM tree is fully constructed.
*/
export interface DOMReadyEvent extends Event {
/** DOM Tree */
document: DOMTree;
source: Source;
}
export interface TriggerEventMap {
......@@ -198,7 +207,7 @@ export interface TriggerEventMap {
"tag:end": TagEndEvent;
"tag:ready": TagReadyEvent;
"element:ready": ElementReadyEvent;
"dom:load": Event;
"dom:load": DOMLoadEvent;
"dom:ready": DOMReadyEvent;
doctype: DoctypeEvent;
attr: AttributeEvent;
......@@ -217,7 +226,7 @@ export interface ListenEventMap {
"tag:end": TagEndEvent;
"tag:ready": TagReadyEvent;
"element:ready": ElementReadyEvent;
"dom:load": Event;
"dom:load": DOMLoadEvent;
"dom:ready": DOMReadyEvent;
doctype: DoctypeEvent;
attr: AttributeEvent;
......
......@@ -65,6 +65,7 @@ export class Parser {
/* trigger any rules waiting for DOM load event */
this.trigger("dom:load", {
source,
location: null,
});
......@@ -131,6 +132,7 @@ export class Parser {
/* trigger any rules waiting for DOM ready */
this.trigger("dom:ready", {
document: this.dom,
source,
/* disable location for this event so rules can use implicit node location
* instead */
......
Supports Markdown
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