UNPKG

2.73 kBTypeScriptView Raw
1import type { TAG_ID } from './html.js';
2export declare enum TokenType {
3 CHARACTER = 0,
4 NULL_CHARACTER = 1,
5 WHITESPACE_CHARACTER = 2,
6 START_TAG = 3,
7 END_TAG = 4,
8 COMMENT = 5,
9 DOCTYPE = 6,
10 EOF = 7,
11 HIBERNATION = 8
12}
13export interface Location {
14 /** One-based line index of the first character. */
15 startLine: number;
16 /** One-based column index of the first character. */
17 startCol: number;
18 /** Zero-based first character index. */
19 startOffset: number;
20 /** One-based line index of the last character. */
21 endLine: number;
22 /** One-based column index of the last character. Points directly *after* the last character. */
23 endCol: number;
24 /** Zero-based last character index. Points directly *after* the last character. */
25 endOffset: number;
26}
27export interface LocationWithAttributes extends Location {
28 /** Start tag attributes' location info. */
29 attrs?: Record<string, Location>;
30}
31export interface ElementLocation extends LocationWithAttributes {
32 /** Element's start tag location info. */
33 startTag?: Location;
34 /**
35 * Element's end tag location info.
36 * This property is undefined, if the element has no closing tag.
37 */
38 endTag?: Location;
39}
40interface TokenBase {
41 readonly type: TokenType;
42 location: Location | null;
43}
44export interface DoctypeToken extends TokenBase {
45 readonly type: TokenType.DOCTYPE;
46 name: string | null;
47 forceQuirks: boolean;
48 publicId: string | null;
49 systemId: string | null;
50}
51export interface Attribute {
52 /** The name of the attribute. */
53 name: string;
54 /** The namespace of the attribute. */
55 namespace?: string;
56 /** The namespace-related prefix of the attribute. */
57 prefix?: string;
58 /** The value of the attribute. */
59 value: string;
60}
61export interface TagToken extends TokenBase {
62 readonly type: TokenType.START_TAG | TokenType.END_TAG;
63 tagName: string;
64 /** Used to cache the ID of the tag name. */
65 tagID: TAG_ID;
66 selfClosing: boolean;
67 ackSelfClosing: boolean;
68 attrs: Attribute[];
69 location: LocationWithAttributes | null;
70}
71export declare function getTokenAttr(token: TagToken, attrName: string): string | null;
72export interface CommentToken extends TokenBase {
73 readonly type: TokenType.COMMENT;
74 data: string;
75}
76export interface EOFToken extends TokenBase {
77 readonly type: TokenType.EOF;
78}
79export interface CharacterToken extends TokenBase {
80 type: TokenType.CHARACTER | TokenType.NULL_CHARACTER | TokenType.WHITESPACE_CHARACTER;
81 chars: string;
82}
83export type Token = DoctypeToken | TagToken | CommentToken | EOFToken | CharacterToken;
84export {};
85//# sourceMappingURL=token.d.ts.map
\No newline at end of file