@markuplint/ml-ast 4.0.0-dev.28 → 4.0.0-rc.0

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 +121 -77
  3. package/package.json +2 -2
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2019 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,113 +1,149 @@
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
- candidate?: string;
91
- isDuplicatable: boolean;
92
- parentNode: null;
93
- nextNode: null;
94
- prevNode: null;
95
- isFragment: false;
96
- 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;
97
104
  }
98
- export interface MLASTPreprocessorSpecificAttr extends MLASTAbstractNode {
99
- readonly type: 'ps-attr';
100
- readonly potentialName: string;
101
- readonly potentialValue: string;
102
- readonly valueType: 'string' | 'number' | 'boolean' | 'code';
103
- isDuplicatable: boolean;
105
+ export interface MLASTSpreadAttr extends MLASTToken {
106
+ readonly type: 'spread';
107
+ readonly nodeName: '#spread';
104
108
  }
105
109
  export interface MLASTDocument {
106
- nodeList: MLASTNode[];
110
+ readonly raw: string;
111
+ readonly nodeList: readonly MLASTNodeTreeItem[];
107
112
  readonly isFragment: boolean;
108
- unknownParseError?: string;
113
+ readonly unknownParseError?: string;
109
114
  }
115
+ /**
116
+ * @deprecated Use `MLParser` instead. This will be dropped in v5.
117
+ */
110
118
  export interface MLMarkupLanguageParser {
119
+ /**
120
+ * @deprecated
121
+ */
122
+ parse(sourceCode: string, options?: ParserOptions & {
123
+ readonly offsetOffset?: number;
124
+ readonly offsetLine?: number;
125
+ readonly offsetColumn?: number;
126
+ }): MLASTDocument;
127
+ /**
128
+ * @default "omittable"
129
+ * @deprecated
130
+ */
131
+ endTag?: EndTagType;
132
+ /**
133
+ * Detect value as a true if its attribute is booleanish value and omitted.
134
+ *
135
+ * Ex:
136
+ * ```jsx
137
+ * <Component aria-hidden />
138
+ * ```
139
+ *
140
+ * In the above, the `aria-hidden` is `true`.
141
+ *
142
+ * @deprecated
143
+ */
144
+ booleanish?: boolean;
145
+ }
146
+ export interface MLParser {
111
147
  parse(sourceCode: string, options?: ParserOptions & {
112
148
  readonly offsetOffset?: number;
113
149
  readonly offsetLine?: number;
@@ -128,6 +164,10 @@ export interface MLMarkupLanguageParser {
128
164
  * In the above, the `aria-hidden` is `true`.
129
165
  */
130
166
  booleanish?: boolean;
167
+ tagNameCaseSensitive?: boolean;
168
+ }
169
+ export interface MLParserModule {
170
+ readonly parser: MLParser;
131
171
  }
132
172
  /**
133
173
  * The end tag omittable type.
@@ -143,7 +183,11 @@ export type ParserOptions = {
143
183
  };
144
184
  export type ParserAuthoredElementNameDistinguishing = string | Readonly<RegExp> | Readonly<ParserAuthoredElementNameDistinguishingFunction> | readonly (string | Readonly<RegExp> | ParserAuthoredElementNameDistinguishingFunction)[];
145
185
  export type ParserAuthoredElementNameDistinguishingFunction = (name: string) => boolean;
186
+ /**
187
+ * @deprecated
188
+ */
146
189
  export type Parse = MLMarkupLanguageParser['parse'];
147
- export type Walker = (node: MLASTNode, depth: number) => void;
190
+ export type Walker<Node extends MLASTNodeTreeItem> = (node: Node, sequentailPrevNode: MLASTNodeTreeItem | null, depth: number) => void;
148
191
  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';
149
192
  export type Namespace = 'html' | 'svg' | 'mml' | 'xlink';
193
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-ast",
3
- "version": "4.0.0-dev.28+0131de5e",
3
+ "version": "4.0.0-rc.0",
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": "0131de5ea9dd6d3fd5472d7b414b66644c758881"
26
+ "gitHead": "3fdeb45cb69ed52b3a215a7520cea1181601443f"
27
27
  }