Skip to content

Commit

Permalink
fix(node): Correct parse5 location types
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Mar 19, 2022
1 parent e6fc386 commit 0fcbbb8
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ const nodeTypes = new Map<ElementType, number>([
[ElementType.Root, 9],
]);

interface SourceCodeLocation {
/** One-based line index of the first character. */
startLine: number;
/** One-based column index of the first character. */
startCol: number;
/** Zero-based first character index. */
startOffset: number;
/** One-based line index of the last character. */
endLine: number;
/** One-based column index of the last character. Points directly *after* the last character. */
endCol: number;
/** Zero-based last character index. Points directly *after* the last character. */
endOffset: number;
}

interface TagSourceCodeLocation extends SourceCodeLocation {
startTag?: SourceCodeLocation;
endTag?: SourceCodeLocation;
}

/**
* This object will be used as the prototype for Nodes when creating a
* DOM-Level-1-compliant structure.
Expand All @@ -36,14 +56,7 @@ export class Node {
*
* Available if parsing with parse5 and location info is enabled.
*/
sourceCodeLocation?: {
startOffset: number;
endOffset: number;
startLine: number;
endLine: number;
startColumn: number;
endColumn: number;
};
sourceCodeLocation?: SourceCodeLocation | null;

/**
*
Expand Down Expand Up @@ -265,6 +278,13 @@ export class Element extends NodeWithChildren {
super(type, children);
}

/**
* `parse5` source code location info, with start & end tags.
*
* Available if parsing with parse5 and location info is enabled.
*/
sourceCodeLocation?: TagSourceCodeLocation | null;

// DOM Level 1 aliases

/**
Expand Down

0 comments on commit 0fcbbb8

Please sign in to comment.