@markuplint/ml-ast 4.0.0-dev.10 → 4.0.0-dev.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/lib/types.d.ts +118 -78
  3. package/package.json +2 -2
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2023 Yusuke Hirao
3
+ Copyright (c) 2017-2024 Yusuke Hirao
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/lib/types.d.ts CHANGED
@@ -1,114 +1,124 @@
1
- export interface MLToken {
1
+ export type MLASTNodeType = 'doctype' | 'starttag' | 'endtag' | 'comment' | 'text' | 'omittedtag' | 'psblock' | 'invalid' | 'attr' | 'spread';
2
+ /**
3
+ * Element type
4
+ *
5
+ * - `html`: From native HTML Standard
6
+ * - `web-component`: As the Web Component according to HTML Standard
7
+ * - `authored`: Authored element (JSX Element etc.) through the view framework or the template engine.
8
+ */
9
+ export type ElementType = 'html' | 'web-component' | 'authored';
10
+ export type MLASTNode = MLASTDoctype | MLASTTag | MLASTComment | MLASTText | MLASTPreprocessorSpecificBlock | MLASTInvalid | MLASTAttr;
11
+ export type MLASTParentNode = MLASTElement | MLASTPreprocessorSpecificBlock;
12
+ export type MLASTNodeTreeItem = MLASTChildNode | MLASTDoctype;
13
+ export type MLASTChildNode = MLASTTag | MLASTText | MLASTComment | MLASTPreprocessorSpecificBlock | MLASTInvalid;
14
+ export type MLASTTag = MLASTElement | MLASTElementCloseTag;
15
+ export type MLASTAttr = MLASTHTMLAttr | MLASTSpreadAttr;
16
+ export interface MLASTToken {
2
17
  readonly uuid: string;
3
- raw: string;
4
- startOffset: number;
5
- endOffset: number;
6
- startLine: number;
7
- endLine: number;
8
- startCol: number;
9
- endCol: number;
10
- [extendKey: `__${string}`]: string | number | boolean | null;
18
+ readonly raw: string;
19
+ readonly startOffset: number;
20
+ readonly endOffset: number;
21
+ readonly startLine: number;
22
+ readonly endLine: number;
23
+ readonly startCol: number;
24
+ readonly endCol: number;
11
25
  }
12
- export type MLASTNodeType = 'doctype' | 'starttag' | 'endtag' | 'comment' | 'text' | 'omittedtag' | 'psblock' | 'html-attr' | 'ps-attr';
13
- export type MLASTNode = MLASTDoctype | MLASTTag | MLASTComment | MLASTText | MLASTPreprocessorSpecificBlock | MLASTAttr;
14
- export interface MLASTAbstractNode extends MLToken {
26
+ interface MLASTAbstractNode extends MLASTToken {
15
27
  readonly type: MLASTNodeType;
16
- nodeName: string;
17
- parentNode: MLASTParentNode | null;
18
- prevNode: MLASTNode | null;
19
- nextNode: MLASTNode | null;
20
- isFragment: boolean;
21
- isGhost: boolean;
28
+ readonly nodeName: string;
29
+ readonly parentNode: MLASTParentNode | null;
22
30
  }
23
31
  export interface MLASTDoctype extends MLASTAbstractNode {
24
32
  readonly type: 'doctype';
25
- name: string;
33
+ readonly depth: number;
34
+ readonly name: string;
26
35
  readonly publicId: string;
27
36
  readonly systemId: string;
28
37
  }
29
38
  export interface MLASTElement extends MLASTAbstractNode {
30
39
  readonly type: 'starttag';
31
- namespace: string;
32
- elementType: ElementType;
33
- attributes: MLASTAttr[];
34
- hasSpreadAttr: boolean;
35
- childNodes?: MLASTNode[];
36
- pearNode: MLASTElementCloseTag | null;
37
- readonly selfClosingSolidus?: MLToken;
38
- readonly endSpace?: MLToken;
40
+ readonly depth: number;
41
+ readonly namespace: string;
42
+ readonly elementType: ElementType;
43
+ readonly attributes: readonly MLASTAttr[];
44
+ readonly hasSpreadAttr?: boolean;
45
+ readonly childNodes: readonly MLASTChildNode[];
46
+ readonly pairNode: MLASTElementCloseTag | null;
47
+ readonly selfClosingSolidus?: MLASTToken;
39
48
  readonly tagOpenChar: string;
40
49
  readonly tagCloseChar: string;
50
+ readonly isGhost: boolean;
41
51
  }
42
- /**
43
- * Element type
44
- *
45
- * - `html`: From native HTML Standard
46
- * - `web-component`: As the Web Component according to HTML Standard
47
- * - `authored`: Authored element (JSX Element etc.) through the view framework or the template engine.
48
- */
49
- export type ElementType = 'html' | 'web-component' | 'authored';
50
52
  export interface MLASTElementCloseTag extends MLASTAbstractNode {
51
53
  readonly type: 'endtag';
52
- readonly namespace: string;
53
- attributes: MLASTAttr[];
54
- childNodes?: MLASTNode[];
55
- pearNode: MLASTTag | null;
54
+ readonly depth: number;
55
+ readonly parentNode: null;
56
+ readonly pairNode: MLASTElement;
56
57
  readonly tagOpenChar: string;
57
58
  readonly tagCloseChar: string;
58
59
  }
59
60
  export interface MLASTPreprocessorSpecificBlock extends MLASTAbstractNode {
60
61
  readonly type: 'psblock';
61
- nodeName: string;
62
- parentNode: MLASTParentNode | null;
63
- prevNode: MLASTNode | null;
64
- nextNode: MLASTNode | null;
65
- childNodes?: MLASTNode[];
66
- branchedChildNodes?: MLASTNode[];
62
+ readonly depth: number;
63
+ readonly nodeName: string;
64
+ readonly childNodes: readonly MLASTChildNode[];
65
+ readonly branchedChildNodes?: readonly MLASTNode[];
66
+ readonly isBogus: boolean;
67
67
  }
68
- export type MLASTTag = MLASTElement | MLASTElementCloseTag;
69
- export type MLASTParentNode = MLASTElement | MLASTPreprocessorSpecificBlock;
70
68
  export interface MLASTComment extends MLASTAbstractNode {
71
69
  readonly type: 'comment';
70
+ readonly nodeName: '#comment';
71
+ readonly depth: number;
72
+ readonly isBogus: boolean;
72
73
  }
73
74
  export interface MLASTText extends MLASTAbstractNode {
74
75
  readonly type: 'text';
76
+ readonly nodeName: '#text';
77
+ readonly depth: number;
78
+ }
79
+ export interface MLASTInvalid extends MLASTAbstractNode {
80
+ readonly type: 'invalid';
81
+ readonly nodeName: '#invalid';
82
+ readonly depth: number;
83
+ readonly kind?: Exclude<MLASTChildNode['type'], 'invalid'>;
84
+ readonly isBogus: true;
75
85
  }
76
- export type MLASTAttr = MLASTHTMLAttr | MLASTPreprocessorSpecificAttr;
77
- export interface MLASTHTMLAttr extends MLASTAbstractNode {
78
- readonly type: 'html-attr';
79
- spacesBeforeName: MLToken;
80
- name: MLToken;
81
- spacesBeforeEqual: MLToken;
82
- equal: MLToken;
83
- spacesAfterEqual: MLToken;
84
- startQuote: MLToken;
85
- value: MLToken;
86
- endQuote: MLToken;
87
- isDynamicValue?: true;
88
- isDirective?: true;
89
- potentialName?: string;
90
- potentialValue?: string;
91
- candidate?: string;
92
- isDuplicatable: boolean;
93
- parentNode: null;
94
- nextNode: null;
95
- prevNode: null;
96
- isFragment: false;
97
- isGhost: false;
86
+ export interface MLASTHTMLAttr extends MLASTToken {
87
+ readonly type: 'attr';
88
+ readonly nodeName: string;
89
+ readonly spacesBeforeName: MLASTToken;
90
+ readonly name: MLASTToken;
91
+ readonly spacesBeforeEqual: MLASTToken;
92
+ readonly equal: MLASTToken;
93
+ readonly spacesAfterEqual: MLASTToken;
94
+ readonly startQuote: MLASTToken;
95
+ readonly value: MLASTToken;
96
+ readonly endQuote: MLASTToken;
97
+ readonly isDynamicValue?: true;
98
+ readonly isDirective?: true;
99
+ readonly potentialName?: string;
100
+ readonly potentialValue?: string;
101
+ readonly valueType?: 'string' | 'number' | 'boolean' | 'code';
102
+ readonly candidate?: string;
103
+ readonly isDuplicatable: boolean;
98
104
  }
99
- export interface MLASTPreprocessorSpecificAttr extends MLASTAbstractNode {
100
- readonly type: 'ps-attr';
101
- readonly potentialName: string;
102
- readonly potentialValue: string;
103
- readonly valueType: 'string' | 'number' | 'boolean' | 'code';
104
- isDuplicatable: boolean;
105
+ export interface MLASTSpreadAttr extends MLASTToken {
106
+ readonly type: 'spread';
107
+ readonly nodeName: '#spread';
105
108
  }
106
109
  export interface MLASTDocument {
107
- nodeList: MLASTNode[];
110
+ readonly raw: string;
111
+ readonly nodeList: readonly MLASTNodeTreeItem[];
108
112
  readonly isFragment: boolean;
109
- unknownParseError?: string;
113
+ readonly unknownParseError?: string;
110
114
  }
115
+ /**
116
+ * @deprecated Use `MLParser` instead. This will be dropped in v5.
117
+ */
111
118
  export interface MLMarkupLanguageParser {
119
+ /**
120
+ * @deprecated
121
+ */
112
122
  parse(sourceCode: string, options?: ParserOptions & {
113
123
  readonly offsetOffset?: number;
114
124
  readonly offsetLine?: number;
@@ -116,6 +126,7 @@ export interface MLMarkupLanguageParser {
116
126
  }): MLASTDocument;
117
127
  /**
118
128
  * @default "omittable"
129
+ * @deprecated
119
130
  */
120
131
  endTag?: EndTagType;
121
132
  /**
@@ -127,9 +138,34 @@ export interface MLMarkupLanguageParser {
127
138
  * ```
128
139
  *
129
140
  * In the above, the `aria-hidden` is `true`.
141
+ *
142
+ * @deprecated
130
143
  */
131
144
  booleanish?: boolean;
132
145
  }
146
+ export interface MLParser {
147
+ parse(sourceCode: string, options?: ParserOptions & {
148
+ readonly offsetOffset?: number;
149
+ readonly offsetLine?: number;
150
+ readonly offsetColumn?: number;
151
+ }): MLASTDocument;
152
+ /**
153
+ * @default "omittable"
154
+ */
155
+ endTag?: EndTagType;
156
+ /**
157
+ * Detect value as a true if its attribute is booleanish value and omitted.
158
+ *
159
+ * Ex:
160
+ * ```jsx
161
+ * <Component aria-hidden />
162
+ * ```
163
+ *
164
+ * In the above, the `aria-hidden` is `true`.
165
+ */
166
+ booleanish?: boolean;
167
+ tagNameCaseSensitive?: boolean;
168
+ }
133
169
  /**
134
170
  * The end tag omittable type.
135
171
  *
@@ -144,7 +180,11 @@ export type ParserOptions = {
144
180
  };
145
181
  export type ParserAuthoredElementNameDistinguishing = string | Readonly<RegExp> | Readonly<ParserAuthoredElementNameDistinguishingFunction> | readonly (string | Readonly<RegExp> | ParserAuthoredElementNameDistinguishingFunction)[];
146
182
  export type ParserAuthoredElementNameDistinguishingFunction = (name: string) => boolean;
183
+ /**
184
+ * @deprecated
185
+ */
147
186
  export type Parse = MLMarkupLanguageParser['parse'];
148
- export type Walker = (node: MLASTNode, depth: number) => void;
187
+ export type Walker<Node extends MLASTNodeTreeItem> = (node: Node, sequentailPrevNode: MLASTNodeTreeItem | null, depth: number) => void;
149
188
  export type NamespaceURI = 'http://www.w3.org/1999/xhtml' | 'http://www.w3.org/2000/svg' | 'http://www.w3.org/1998/Math/MathML' | 'http://www.w3.org/1999/xlink';
150
189
  export type Namespace = 'html' | 'svg' | 'mml' | 'xlink';
190
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-ast",
3
- "version": "4.0.0-dev.10+b28398ab",
3
+ "version": "4.0.0-dev.12+2275fbeb0",
4
4
  "description": "The markuplint AST types.",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -23,5 +23,5 @@
23
23
  "build": "tsc",
24
24
  "clean": "tsc --build --clean"
25
25
  },
26
- "gitHead": "b28398ab9c8f0ad790f2915ad5da8f3a80e9b8d6"
26
+ "gitHead": "2275fbeb053605b636f080f4fafd7cd4fc57a9a3"
27
27
  }