svg-eslint-parser 0.0.5 → 0.0.6

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.
package/README.md CHANGED
@@ -10,7 +10,16 @@
10
10
  > [!IMPORTANT]
11
11
  > Status: Work In Progress, not ready for production.
12
12
  >
13
- > API is not stale now, Use at your own risk.
13
+ > API is not stable now, use at your own risk.
14
+
15
+ ## Features
16
+
17
+ - ✅ **ESLint Compatible**: Produces AST compatible with ESLint's parser interface
18
+ - 🎯 **Type Safe**: Full TypeScript support with comprehensive type definitions
19
+ - 🔍 **Rich Utilities**: Built-in functions for searching, traversing, and manipulating AST
20
+ - 📊 **Detailed AST**: 16 node types covering all SVG/XML constructs
21
+ - 🚀 **Zero Dependencies**: Minimal runtime dependencies for fast installation
22
+ - 🎪 **Interactive Playground**: Try it online at [svg-eslint-parser.ntnyq.com](https://svg-eslint-parser.ntnyq.com/play)
14
23
 
15
24
  ## Install
16
25
 
@@ -26,12 +35,188 @@ yarn add svg-eslint-parser -D
26
35
  pnpm add svg-eslint-parser -D
27
36
  ```
28
37
 
38
+ ## Usage
39
+
40
+ ### Basic Parsing
41
+
42
+ ```typescript
43
+ import { parse, parseForESLint } from 'svg-eslint-parser'
44
+
45
+ // For direct use
46
+ const document = parse('<svg><circle cx="50" cy="50" r="40" /></svg>')
47
+ console.log(document.type) // 'Document'
48
+
49
+ // For ESLint integration
50
+ const result = parseForESLint('<svg><circle cx="50" cy="50" r="40" /></svg>')
51
+ console.log(result.ast.type) // 'Program'
52
+ ```
53
+
54
+ ### With ESLint
55
+
56
+ ```javascript
57
+ import pluginSVG from 'eslint-plugin-svg'
58
+ import * as parserSVG from 'svg-eslint-parser'
59
+
60
+ export default [
61
+ {
62
+ name: 'svg/rules',
63
+ files: ['**/*.svg'],
64
+ plugins: {
65
+ svg: pluginSVG,
66
+ },
67
+ languageOptions: {
68
+ parser: parserSVG,
69
+ },
70
+ rules: {
71
+ 'svg/no-empty-title': 'error',
72
+ },
73
+ },
74
+ ]
75
+ ```
76
+
77
+ ### Using Utilities
78
+
79
+ ```typescript
80
+ import {
81
+ parseForESLint,
82
+ findNodeByType,
83
+ NodeTypes,
84
+ traverseAST,
85
+ } from 'svg-eslint-parser'
86
+
87
+ const { ast } = parseForESLint(svgSource)
88
+ const document = ast.body[0]
89
+
90
+ // Find all tag nodes
91
+ const tags = findNodeByType(document, NodeTypes.Tag)
92
+ console.log(`Found ${tags.length} tags`)
93
+
94
+ // Traverse with visitor pattern
95
+ traverseAST(document, {
96
+ enter(node, parent) {
97
+ console.log('Visiting:', node.type)
98
+ // Return false to skip children
99
+ if (node.type === 'Comment') return false
100
+ },
101
+ leave(node, parent) {
102
+ console.log('Leaving:', node.type)
103
+ },
104
+ })
105
+ ```
106
+
107
+ ## API
108
+
109
+ ### Parser Functions
110
+
111
+ #### `parseForESLint(code: string, options?: ParserOptions)`
112
+
113
+ Returns an ESLint-compatible result with AST, visitor keys, and services.
114
+
115
+ #### `parse(code: string, options?: ParserOptions)`
116
+
117
+ Returns a Document node directly.
118
+
119
+ ### Utility Functions
120
+
121
+ #### Search & Traversal
122
+
123
+ - `findNodeByType<T>(node, type)` - Find all nodes of a specific type
124
+ - `findFirstNodeByType<T>(node, type)` - Find first node of a specific type
125
+ - `traverseAST(node, visitor)` - Visitor pattern traversal with enter/leave hooks
126
+ - `walkAST(node, callback)` - Simple traversal with callback
127
+
128
+ #### Validation
129
+
130
+ - `validateNode(node)` - Validate node structure
131
+ - `isNodeType<T>(node, type)` - Type guard function
132
+
133
+ #### Manipulation
134
+
135
+ - `cloneNode<T>(node)` - Deep clone without parent references
136
+ - `cloneNodeWithParent<T>(node, parent?)` - Clone preserving parent refs
137
+ - `filterNodes(node, predicate)` - Filter nodes by predicate
138
+ - `mapNodes<T>(node, mapper)` - Map over all nodes
139
+
140
+ #### Analysis
141
+
142
+ - `countNodes(node)` - Count total nodes
143
+ - `getNodeDepth(node)` - Get node depth (requires parent refs)
144
+ - `getParentChain(node)` - Get ancestor chain (requires parent refs)
145
+
146
+ ### Node Types
147
+
148
+ The parser defines 34 node types:
149
+
150
+ **Document Structure**: `Program`, `Document`
151
+
152
+ **Elements**: `Tag`, `OpenTagStart`, `OpenTagEnd`, `CloseTag`
153
+
154
+ **Attributes**: `Attribute`, `AttributeKey`, `AttributeValue`, `AttributeValueWrapperStart`, `AttributeValueWrapperEnd`
155
+
156
+ **Text & Comments**: `Text`, `Comment`, `CommentOpen`, `CommentContent`, `CommentClose`
157
+
158
+ **XML Declaration**: `XMLDeclaration`, `XMLDeclarationOpen`, `XMLDeclarationClose`, `XMLDeclarationAttribute`, `XMLDeclarationAttributeKey`, `XMLDeclarationAttributeValue`, `XMLDeclarationAttributeValueWrapperStart`, `XMLDeclarationAttributeValueWrapperEnd`
159
+
160
+ **DOCTYPE**: `Doctype`, `DoctypeOpen`, `DoctypeClose`, `DoctypeAttribute`, `DoctypeAttributeValue`, `DoctypeAttributeWrapperStart`, `DoctypeAttributeWrapperEnd`
161
+
162
+ **Error Handling**: `Error`
163
+
164
+ ## Documentation
165
+
166
+ Full documentation is available at [svg-eslint-parser.ntnyq.com](https://svg-eslint-parser.ntnyq.com):
167
+
168
+ - [API Documentation](https://svg-eslint-parser.ntnyq.com/api/)
169
+ - [AST Structure](https://svg-eslint-parser.ntnyq.com/api/ast)
170
+ - [Utilities Guide](https://svg-eslint-parser.ntnyq.com/api/utilities)
171
+ - [Migration Guide](https://svg-eslint-parser.ntnyq.com/guide/migration)
172
+
29
173
  ## Playground
30
174
 
31
- You can try the parser in [playground](https://svg-eslint-parser.ntnyq.com/play).
175
+ You can try the parser in the [interactive playground](https://svg-eslint-parser.ntnyq.com/play).
32
176
 
33
177
  Feel free to open an issue if you have any suggestions or find any bugs.
34
178
 
179
+ ## Example: Finding All Circles
180
+
181
+ ```typescript
182
+ import { parseForESLint, findNodeByType, NodeTypes } from 'svg-eslint-parser'
183
+
184
+ const svgCode = `
185
+ <svg width="200" height="200">
186
+ <circle cx="50" cy="50" r="40" fill="red" />
187
+ <circle cx="150" cy="150" r="30" fill="blue" />
188
+ <rect x="10" y="10" width="50" height="50" />
189
+ </svg>
190
+ `
191
+
192
+ const { ast } = parseForESLint(svgCode)
193
+ const document = ast.body[0]
194
+
195
+ // Find all tags and filter for circles
196
+ const allTags = findNodeByType(document, NodeTypes.Tag)
197
+ const circles = allTags.filter(tag => tag.name === 'circle')
198
+
199
+ console.log(`Found ${circles.length} circles`)
200
+
201
+ circles.forEach((circle, i) => {
202
+ const cx = circle.attributes.find(attr => attr.key.value === 'cx')
203
+ const cy = circle.attributes.find(attr => attr.key.value === 'cy')
204
+ const r = circle.attributes.find(attr => attr.key.value === 'r')
205
+
206
+ console.log(
207
+ `Circle ${i + 1}: cx=${cx?.value?.value}, cy=${cy?.value?.value}, r=${r?.value?.value}`,
208
+ )
209
+ })
210
+ ```
211
+
212
+ Output:
213
+
214
+ ```
215
+ Found 2 circles
216
+ Circle 1: cx=50, cy=50, r=40
217
+ Circle 2: cx=150, cy=150, r=30
218
+ ```
219
+
35
220
  ## Links
36
221
 
37
222
  - [Scalable Vector Graphics (SVG) 2](https://www.w3.org/TR/SVG2/)
package/dist/index.d.ts CHANGED
@@ -61,69 +61,65 @@ declare enum NodeTypes {
61
61
  Attribute = "Attribute",
62
62
  AttributeKey = "AttributeKey",
63
63
  AttributeValue = "AttributeValue",
64
- AttributeValueWrapperEnd = "AttributeValueWrapperEnd",
65
- AttributeValueWrapperStart = "AttributeValueWrapperStart",
66
- CloseTag = "CloseTag",
67
64
  Comment = "Comment",
68
- CommentClose = "CommentClose",
69
- CommentContent = "CommentContent",
70
- CommentOpen = "CommentOpen",
71
65
  Doctype = "Doctype",
72
66
  DoctypeAttribute = "DoctypeAttribute",
73
67
  DoctypeAttributeValue = "DoctypeAttributeValue",
74
- DoctypeAttributeWrapperEnd = "DoctypeAttributeWrapperEnd",
75
- DoctypeAttributeWrapperStart = "DoctypeAttributeWrapperStart",
76
- DoctypeClose = "DoctypeClose",
77
- DoctypeOpen = "DoctypeOpen",
78
68
  Document = "Document",
79
- OpenTagEnd = "OpenTagEnd",
80
- OpenTagStart = "OpenTagStart",
69
+ Error = "Error",
81
70
  Program = "Program",
82
71
  Tag = "Tag",
83
72
  Text = "Text",
84
73
  XMLDeclaration = "XMLDeclaration",
85
74
  XMLDeclarationAttribute = "XMLDeclarationAttribute",
86
75
  XMLDeclarationAttributeKey = "XMLDeclarationAttributeKey",
87
- XMLDeclarationAttributeValue = "XMLDeclarationAttributeValue",
88
- XMLDeclarationAttributeValueWrapperEnd = "XMLDeclarationAttributeValueWrapperEnd",
89
- XMLDeclarationAttributeValueWrapperStart = "XMLDeclarationAttributeValueWrapperStart",
90
- XMLDeclarationClose = "XMLDeclarationClose",
91
- XMLDeclarationOpen = "XMLDeclarationOpen",
76
+ XMLDeclarationAttributeValue = "XMLDeclarationAttributeValue"
92
77
  }
93
78
  //#endregion
94
79
  //#region src/constants/tokenTypes.d.ts
95
80
  declare enum TokenTypes {
96
- Attribute = "Attribute",
81
+ /**
82
+ * @pg Content tokens
83
+ */
84
+ Text = "Text",
85
+ /**
86
+ * @pg Attribute tokens
87
+ */
97
88
  AttributeAssignment = "AttributeAssignment",
98
89
  AttributeKey = "AttributeKey",
99
90
  AttributeValue = "AttributeValue",
100
91
  AttributeValueWrapperEnd = "AttributeValueWrapperEnd",
101
92
  AttributeValueWrapperStart = "AttributeValueWrapperStart",
102
- CloseTag = "CloseTag",
103
- Comment = "Comment",
104
- CommentClose = "CommentClose",
105
- CommentContent = "CommentContent",
106
- CommentOpen = "CommentOpen",
107
- Doctype = "Doctype",
93
+ /**
94
+ * @pg Doctype tokens
95
+ */
108
96
  DoctypeAttributeValue = "DoctypeAttributeValue",
109
97
  DoctypeAttributeWrapperEnd = "DoctypeAttributeWrapperEnd",
110
98
  DoctypeAttributeWrapperStart = "DoctypeAttributeWrapperStart",
111
99
  DoctypeClose = "DoctypeClose",
112
100
  DoctypeOpen = "DoctypeOpen",
113
- Document = "Document",
101
+ /**
102
+ * @pg Tag tokens
103
+ */
104
+ CloseTag = "CloseTag",
114
105
  OpenTagEnd = "OpenTagEnd",
115
106
  OpenTagStart = "OpenTagStart",
116
- Program = "Program",
117
- Tag = "Tag",
118
- Text = "Text",
119
- XMLDeclarationAttribute = "XMLDeclarationAttribute",
107
+ /**
108
+ * @pg Comment tokens
109
+ */
110
+ CommentClose = "CommentClose",
111
+ CommentContent = "CommentContent",
112
+ CommentOpen = "CommentOpen",
113
+ /**
114
+ * @pg XML Declaration tokens
115
+ */
120
116
  XMLDeclarationAttributeAssignment = "XMLDeclarationAttributeAssignment",
121
117
  XMLDeclarationAttributeKey = "XMLDeclarationAttributeKey",
122
118
  XMLDeclarationAttributeValue = "XMLDeclarationAttributeValue",
123
119
  XMLDeclarationAttributeValueWrapperEnd = "XMLDeclarationAttributeValueWrapperEnd",
124
120
  XMLDeclarationAttributeValueWrapperStart = "XMLDeclarationAttributeValueWrapperStart",
125
121
  XMLDeclarationClose = "XMLDeclarationClose",
126
- XMLDeclarationOpen = "XMLDeclarationOpen",
122
+ XMLDeclarationOpen = "XMLDeclarationOpen"
127
123
  }
128
124
  //#endregion
129
125
  //#region src/constants/specialChar.d.ts
@@ -186,7 +182,7 @@ declare enum TokenizerContextTypes {
186
182
  XMLDeclarationAttributeValue = "XMLDeclarationAttributeValue",
187
183
  XMLDeclarationAttributeValueWrapped = "XMLDeclarationAttributeValueWrapped",
188
184
  XMLDeclarationClose = "XMLDeclarationClose",
189
- XMLDeclarationOpen = "XMLDeclarationOpen",
185
+ XMLDeclarationOpen = "XMLDeclarationOpen"
190
186
  }
191
187
  //#endregion
192
188
  //#region src/constants/constructTreeContextTypes.d.ts
@@ -204,7 +200,7 @@ declare enum ConstructTreeContextTypes {
204
200
  XMLDeclaration = "XMLDeclaration",
205
201
  XMLDeclarationAttribute = "XMLDeclarationAttribute",
206
202
  XMLDeclarationAttributes = "XMLDeclarationAttributes",
207
- XMLDeclarationAttributeValue = "XMLDeclarationAttributeValue",
203
+ XMLDeclarationAttributeValue = "XMLDeclarationAttributeValue"
208
204
  }
209
205
  //#endregion
210
206
  //#region src/types/ast/common.d.ts
@@ -238,7 +234,7 @@ interface SourceLocation {
238
234
  /**
239
235
  * any token
240
236
  */
241
- type AnyToken = Token<TokenTypes.Attribute> | Token<TokenTypes.AttributeAssignment> | Token<TokenTypes.AttributeKey> | Token<TokenTypes.AttributeValue> | Token<TokenTypes.AttributeValueWrapperEnd> | Token<TokenTypes.AttributeValueWrapperStart> | Token<TokenTypes.CloseTag> | Token<TokenTypes.Comment> | Token<TokenTypes.CommentClose> | Token<TokenTypes.CommentContent> | Token<TokenTypes.CommentOpen> | Token<TokenTypes.Doctype> | Token<TokenTypes.DoctypeAttributeValue> | Token<TokenTypes.DoctypeAttributeWrapperEnd> | Token<TokenTypes.DoctypeAttributeWrapperStart> | Token<TokenTypes.DoctypeClose> | Token<TokenTypes.DoctypeOpen> | Token<TokenTypes.Document> | Token<TokenTypes.OpenTagEnd> | Token<TokenTypes.OpenTagStart> | Token<TokenTypes.Program> | Token<TokenTypes.Tag> | Token<TokenTypes.Text> | Token<TokenTypes.XMLDeclarationAttribute> | Token<TokenTypes.XMLDeclarationAttributeAssignment> | Token<TokenTypes.XMLDeclarationAttributeKey> | Token<TokenTypes.XMLDeclarationAttributeValue> | Token<TokenTypes.XMLDeclarationAttributeValueWrapperEnd> | Token<TokenTypes.XMLDeclarationAttributeValueWrapperStart> | Token<TokenTypes.XMLDeclarationClose> | Token<TokenTypes.XMLDeclarationOpen>;
237
+ type AnyToken = Token<TokenTypes.AttributeAssignment> | Token<TokenTypes.AttributeKey> | Token<TokenTypes.AttributeValue> | Token<TokenTypes.AttributeValueWrapperEnd> | Token<TokenTypes.AttributeValueWrapperStart> | Token<TokenTypes.CloseTag> | Token<TokenTypes.CommentClose> | Token<TokenTypes.CommentContent> | Token<TokenTypes.CommentOpen> | Token<TokenTypes.DoctypeAttributeValue> | Token<TokenTypes.DoctypeAttributeWrapperEnd> | Token<TokenTypes.DoctypeAttributeWrapperStart> | Token<TokenTypes.DoctypeClose> | Token<TokenTypes.DoctypeOpen> | Token<TokenTypes.OpenTagEnd> | Token<TokenTypes.OpenTagStart> | Token<TokenTypes.Text> | Token<TokenTypes.XMLDeclarationAttributeAssignment> | Token<TokenTypes.XMLDeclarationAttributeKey> | Token<TokenTypes.XMLDeclarationAttributeValue> | Token<TokenTypes.XMLDeclarationAttributeValueWrapperEnd> | Token<TokenTypes.XMLDeclarationAttributeValueWrapperStart> | Token<TokenTypes.XMLDeclarationClose> | Token<TokenTypes.XMLDeclarationOpen>;
242
238
  /**
243
239
  * token
244
240
  */
@@ -263,117 +259,99 @@ interface SimpleNode<T extends NodeTypes> extends BaseNode {
263
259
  }
264
260
  type TextNode = SimpleNode<NodeTypes.Text>;
265
261
  /**
266
- * attribute
262
+ * attribute nodes
267
263
  * @pg
268
264
  */
269
265
  type AttributeKeyNode = SimpleNode<NodeTypes.AttributeKey>;
266
+ type AttributeValueNode = SimpleNode<NodeTypes.AttributeValue>;
270
267
  interface AttributeNode extends BaseNode {
271
268
  key: AttributeKeyNode;
272
269
  type: NodeTypes.Attribute;
273
270
  value: AttributeValueNode;
274
- endWrapper?: AttributeValueWrapperEndNode;
275
- startWrapper?: AttributeValueWrapperStartNode;
271
+ quoteChar?: '"' | "'" | undefined;
276
272
  }
277
- type AttributeValueNode = SimpleNode<NodeTypes.AttributeValue>;
278
- type AttributeValueWrapperEndNode = SimpleNode<NodeTypes.AttributeValueWrapperEnd>;
279
- type AttributeValueWrapperStartNode = SimpleNode<NodeTypes.AttributeValueWrapperStart>;
280
273
  /**
281
- * comment
274
+ * comment nodes
282
275
  * @pg
283
276
  */
284
- type CommentCloseNode = SimpleNode<NodeTypes.CommentClose>;
285
- type CommentContentNode = SimpleNode<NodeTypes.CommentContent>;
286
277
  interface CommentNode extends BaseNode {
287
- close: CommentCloseNode;
288
- open: CommentOpenNode;
278
+ content: string;
289
279
  type: NodeTypes.Comment;
290
- value: CommentContentNode;
291
280
  }
292
- type CommentOpenNode = SimpleNode<NodeTypes.CommentOpen>;
293
281
  /**
294
- * doctype
282
+ * doctype nodes
295
283
  * @pg
296
284
  */
285
+ type DoctypeAttributeValueNode = SimpleNode<NodeTypes.DoctypeAttributeValue>;
297
286
  interface DoctypeAttributeNode extends BaseNode {
298
287
  type: NodeTypes.DoctypeAttribute;
299
- endWrapper?: DoctypeAttributeWrapperEndNode;
300
- startWrapper?: DoctypeAttributeWrapperStartNode;
288
+ quoteChar?: '"' | "'" | undefined;
301
289
  value?: DoctypeAttributeValueNode;
302
290
  }
303
- type DoctypeAttributeValueNode = SimpleNode<NodeTypes.DoctypeAttributeValue>;
304
- type DoctypeAttributeWrapperEndNode = SimpleNode<NodeTypes.DoctypeAttributeWrapperEnd>;
305
- type DoctypeAttributeWrapperStartNode = SimpleNode<NodeTypes.DoctypeAttributeWrapperStart>;
306
- type DoctypeCloseNode = SimpleNode<NodeTypes.DoctypeClose>;
307
291
  interface DoctypeNode extends BaseNode {
308
292
  attributes: DoctypeAttributeNode[];
309
- close: DoctypeCloseNode;
310
- open: DoctypeOpenNode;
311
293
  type: NodeTypes.Doctype;
312
294
  }
313
- type DoctypeOpenNode = SimpleNode<NodeTypes.DoctypeOpen>;
314
295
  /**
315
- * tag
296
+ * tag nodes
316
297
  * @pg
317
298
  */
318
- type CloseTagNode = SimpleNode<NodeTypes.CloseTag>;
319
- type OpenTagEndNode = SimpleNode<NodeTypes.OpenTagEnd>;
320
- type OpenTagStartNode = SimpleNode<NodeTypes.OpenTagStart>;
321
299
  interface TagNode extends BaseNode {
322
300
  attributes: AttributeNode[];
323
301
  children: NestableNode[];
324
302
  name: string;
325
- openEnd: OpenTagEndNode;
326
- openStart: OpenTagStartNode;
327
303
  selfClosing: boolean;
328
304
  type: NodeTypes.Tag;
329
- close?: CloseTagNode;
330
305
  }
331
306
  /**
332
- * XML declaration
307
+ * XML declaration nodes
333
308
  */
334
309
  type XMLDeclarationAttributeKeyNode = SimpleNode<NodeTypes.XMLDeclarationAttributeKey>;
310
+ type XMLDeclarationAttributeValueNode = SimpleNode<NodeTypes.XMLDeclarationAttributeValue>;
335
311
  interface XMLDeclarationAttributeNode extends BaseNode {
336
312
  key: XMLDeclarationAttributeKeyNode;
337
313
  type: NodeTypes.XMLDeclarationAttribute;
338
314
  value: XMLDeclarationAttributeValueNode;
339
- endWrapper?: XMLDeclarationAttributeValueWrapperEndNode;
340
- startWrapper?: XMLDeclarationAttributeValueWrapperStartNode;
315
+ quoteChar?: '"' | "'" | undefined;
341
316
  }
342
- type XMLDeclarationAttributeValueNode = SimpleNode<NodeTypes.XMLDeclarationAttributeValue>;
343
- type XMLDeclarationAttributeValueWrapperEndNode = SimpleNode<NodeTypes.XMLDeclarationAttributeValueWrapperEnd>;
344
- type XMLDeclarationAttributeValueWrapperStartNode = SimpleNode<NodeTypes.XMLDeclarationAttributeValueWrapperStart>;
345
- type XMLDeclarationCloseNode = SimpleNode<NodeTypes.XMLDeclarationClose>;
346
317
  interface XMLDeclarationNode extends BaseNode {
347
318
  attributes: XMLDeclarationAttributeNode[];
348
- close: XMLDeclarationCloseNode;
349
- open: XMLDeclarationOpenNode;
350
319
  type: NodeTypes.XMLDeclaration;
351
320
  }
352
- type XMLDeclarationOpenNode = SimpleNode<NodeTypes.XMLDeclarationOpen>;
321
+ /**
322
+ * error nodes
323
+ * @pg
324
+ */
325
+ interface ErrorNode extends BaseNode {
326
+ code: string;
327
+ message: string;
328
+ type: NodeTypes.Error;
329
+ recoveredNode?: AnyNode;
330
+ }
353
331
  /**
354
332
  * nestable node
355
333
  * @pg
356
334
  */
357
- type NestableNode = CommentNode | TagNode | TextNode | XMLDeclarationNode;
335
+ type NestableNode = CommentNode | DoctypeNode | TagNode | TextNode | XMLDeclarationNode;
358
336
  /**
359
337
  * program
360
338
  * @pg
361
339
  */
362
- interface DocumentNode extends BaseNode {
363
- children: NestableNode[];
364
- type: NodeTypes.Document;
365
- }
366
340
  interface Program extends BaseNode {
367
341
  body: DocumentNode[];
368
- comments: CommentContentNode[];
342
+ comments: string[];
369
343
  tokens: AnyToken[];
370
344
  type: NodeTypes.Program;
371
345
  }
346
+ interface DocumentNode extends BaseNode {
347
+ children: NestableNode[];
348
+ type: NodeTypes.Document;
349
+ }
372
350
  /**
373
351
  * any node
374
352
  * @pg
375
353
  */
376
- type AnyNode = AttributeKeyNode | AttributeNode | AttributeValueNode | AttributeValueWrapperEndNode | AttributeValueWrapperStartNode | CloseTagNode | CommentCloseNode | CommentContentNode | CommentNode | CommentOpenNode | DoctypeAttributeNode | DoctypeAttributeValueNode | DoctypeAttributeWrapperEndNode | DoctypeAttributeWrapperStartNode | DoctypeCloseNode | DoctypeNode | DoctypeOpenNode | DocumentNode | OpenTagEndNode | OpenTagStartNode | Program | TagNode | TextNode | XMLDeclarationAttributeKeyNode | XMLDeclarationAttributeNode | XMLDeclarationAttributeValueNode | XMLDeclarationAttributeValueWrapperEndNode | XMLDeclarationAttributeValueWrapperStartNode | XMLDeclarationCloseNode | XMLDeclarationNode | XMLDeclarationOpenNode;
354
+ type AnyNode = AttributeKeyNode | AttributeNode | AttributeValueNode | CommentNode | DoctypeAttributeNode | DoctypeAttributeValueNode | DoctypeNode | DocumentNode | ErrorNode | Program | TagNode | TextNode | XMLDeclarationAttributeKeyNode | XMLDeclarationAttributeNode | XMLDeclarationAttributeValueNode | XMLDeclarationNode;
377
355
  //#endregion
378
356
  //#region src/types/parse.d.ts
379
357
  interface Options {
@@ -408,11 +386,11 @@ interface ParseResult {
408
386
  }
409
387
  //#endregion
410
388
  //#region src/types/contextualNode.d.ts
411
- type AnyContextualNode = ContextualAttributeNode | ContextualCommentNode | ContextualDoctypeAttributeNode | ContextualDoctypeNode | ContextualDocumentNode | ContextualTagNode | ContextualXMLDeclarationAttributeNode | ContextuaLXMLDeclarationNode;
389
+ type AnyContextualNode = ContextualAttributeNode | ContextualCommentNode | ContextualDoctypeAttributeNode | ContextualDoctypeNode | ContextualDocumentNode | ContextualTagNode | ContextualXMLDeclarationAttributeNode | ContextualXMLDeclarationNode;
412
390
  type ContextualAttributeNode = ContextualNode<AttributeNode, 'key' | 'value'>;
413
- type ContextualCommentNode = ContextualNode<CommentNode, 'close' | 'open' | 'value'>;
414
- type ContextualDoctypeAttributeNode = ContextualNode<DoctypeAttributeNode, 'value'>;
415
- type ContextualDoctypeNode = ContextualNode<DoctypeNode, 'close' | 'open'> & {
391
+ type ContextualCommentNode = ContextualNode<CommentNode, 'content'>;
392
+ type ContextualDoctypeAttributeNode = ContextualNode<DoctypeAttributeNode, 'type' | 'value'>;
393
+ type ContextualDoctypeNode = ContextualNode<DoctypeNode, 'attributes'> & {
416
394
  attributes: ContextualDoctypeAttributeNode[];
417
395
  };
418
396
  type ContextualDocumentNode = Omit<ContextualNode<DocumentNode, never>, 'children'> & {
@@ -421,12 +399,12 @@ type ContextualDocumentNode = Omit<ContextualNode<DocumentNode, never>, 'childre
421
399
  type ContextualNode<T extends AnyNode, K extends keyof T> = PartialBy<T, K> & {
422
400
  parentRef?: any;
423
401
  };
424
- type ContextualTagNode = ContextualNode<TagNode, 'close' | 'name' | 'openEnd' | 'openStart' | 'selfClosing'> & {
402
+ type ContextualTagNode = ContextualNode<TagNode, 'attributes' | 'children' | 'name' | 'selfClosing'> & {
425
403
  attributes: ContextualAttributeNode[];
426
404
  children: Array<ContextualCommentNode | ContextualDoctypeNode | ContextualTagNode | TagNode['children'][number]>;
427
405
  };
428
406
  type ContextualXMLDeclarationAttributeNode = ContextualNode<XMLDeclarationAttributeNode, 'key' | 'value'>;
429
- type ContextuaLXMLDeclarationNode = ContextualNode<XMLDeclarationNode, 'close' | 'open'> & {
407
+ type ContextualXMLDeclarationNode = ContextualNode<XMLDeclarationNode, 'attributes'> & {
430
408
  attributes: ContextualXMLDeclarationAttributeNode[];
431
409
  };
432
410
  type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
@@ -523,15 +501,124 @@ interface TokenizeHandler {
523
501
  handleContentEnd?: (state: TokenizerState) => void;
524
502
  }
525
503
  declare namespace index_d_exports {
526
- export { AnyContextualNode, AnyNode, AnyToken, AttributeKeyNode, AttributeNode, AttributeValueNode, AttributeValueWrapperEndNode, AttributeValueWrapperStartNode, BaseNode, CloseTagNode, CommentCloseNode, CommentContentNode, CommentNode, CommentOpenNode, ConstructTreeHandler, ConstructTreeState, ContextuaLXMLDeclarationNode, ContextualAttributeNode, ContextualCommentNode, ContextualDoctypeAttributeNode, ContextualDoctypeNode, ContextualDocumentNode, ContextualNode, ContextualTagNode, ContextualXMLDeclarationAttributeNode, DoctypeAttributeNode, DoctypeAttributeValueNode, DoctypeAttributeWrapperEndNode, DoctypeAttributeWrapperStartNode, DoctypeCloseNode, DoctypeNode, DoctypeOpenNode, DocumentNode, Locations, NestableNode, OpenTagEndNode, OpenTagStartNode, Options, ParseForESLintResult, ParseResult, PartialBy, Position, Program, Range, SimpleNode, SourceLocation, TagNode, TextNode, Token, TokenizeHandler, TokenizerState, XMLDeclarationAttributeKeyNode, XMLDeclarationAttributeNode, XMLDeclarationAttributeValueNode, XMLDeclarationAttributeValueWrapperEndNode, XMLDeclarationAttributeValueWrapperStartNode, XMLDeclarationCloseNode, XMLDeclarationNode, XMLDeclarationOpenNode };
504
+ export { AnyContextualNode, AnyNode, AnyToken, AttributeKeyNode, AttributeNode, AttributeValueNode, BaseNode, CommentNode, ConstructTreeHandler, ConstructTreeState, ContextualAttributeNode, ContextualCommentNode, ContextualDoctypeAttributeNode, ContextualDoctypeNode, ContextualDocumentNode, ContextualNode, ContextualTagNode, ContextualXMLDeclarationAttributeNode, ContextualXMLDeclarationNode, DoctypeAttributeNode, DoctypeAttributeValueNode, DoctypeNode, DocumentNode, ErrorNode, Locations, NestableNode, Options, ParseForESLintResult, ParseResult, PartialBy, Position, Program, Range, SimpleNode, SourceLocation, TagNode, TextNode, Token, TokenizeHandler, TokenizerState, XMLDeclarationAttributeKeyNode, XMLDeclarationAttributeNode, XMLDeclarationAttributeValueNode, XMLDeclarationNode };
527
505
  }
528
506
  //#endregion
529
507
  //#region src/parser/parseForESLint.d.ts
530
508
  declare function parseForESLint(source: string, options?: Options): ParseForESLintResult;
531
509
  //#endregion
510
+ //#region src/utils/cloneNode.d.ts
511
+ /**
512
+ * Deep clone a node, removing parent references
513
+ * @param node - Node to clone
514
+ * @returns Cloned node
515
+ */
516
+ declare function cloneNode<T extends AnyNode>(node: T): T;
517
+ /**
518
+ * Deep clone a node, preserving parent references
519
+ * @param node - Node to clone
520
+ * @param parent - Parent node for the cloned node
521
+ * @returns Cloned node with parent references
522
+ */
523
+ declare function cloneNodeWithParent<T extends AnyNode>(node: T, parent?: AnyNode): T;
524
+ //#endregion
525
+ //#region src/utils/nodeHelpers.d.ts
526
+ /**
527
+ * Filter nodes by a predicate function
528
+ * @param node - Root node to filter from
529
+ * @param predicate - Filter function
530
+ * @returns Array of matching nodes
531
+ */
532
+ declare function filterNodes(node: AnyNode, predicate: (node: AnyNode) => boolean): AnyNode[];
533
+ /**
534
+ * Map over all nodes in the AST
535
+ * @param node - Root node to map from
536
+ * @param mapper - Mapping function
537
+ * @returns Transformed node
538
+ */
539
+ declare function mapNodes<T extends AnyNode>(node: T, mapper: (node: AnyNode) => AnyNode): T;
540
+ /**
541
+ * Get all parent nodes from a node up to the root
542
+ * @param node - Starting node
543
+ * @returns Array of parent nodes (from immediate parent to root)
544
+ */
545
+ declare function getParentChain(node: any): AnyNode[];
546
+ /**
547
+ * Get the depth of a node in the AST (distance from root)
548
+ * @param node - Node to measure
549
+ * @returns Depth level (root = 0)
550
+ */
551
+ declare function getNodeDepth(node: any): number;
552
+ /**
553
+ * Count total number of nodes in the AST
554
+ * @param node - Root node
555
+ * @returns Total node count
556
+ */
557
+ declare function countNodes(node: AnyNode): number;
558
+ //#endregion
559
+ //#region src/utils/traverseAST.d.ts
560
+ /**
561
+ * Visitor function for AST traversal
562
+ */
563
+ type ASTVisitor = {
564
+ /**
565
+ * Called when entering a node
566
+ * Return false to skip traversing children
567
+ */
568
+ enter?: (node: AnyNode, parent: AnyNode | null) => void | boolean;
569
+ /**
570
+ * Called when leaving a node
571
+ */
572
+ leave?: (node: AnyNode, parent: AnyNode | null) => void;
573
+ };
574
+ /**
575
+ * Traverse the AST with a visitor pattern
576
+ * @param node - Root node to traverse from
577
+ * @param visitor - Visitor object with enter/leave hooks
578
+ * @param parent - Parent node (used internally)
579
+ */
580
+ declare function traverseAST(node: AnyNode, visitor: ASTVisitor, parent?: AnyNode | null): void;
581
+ /**
582
+ * Simple traversal function that calls a callback for each node
583
+ * @param node - Root node to traverse from
584
+ * @param callback - Function to call for each node
585
+ */
586
+ declare function walkAST(node: AnyNode, callback: (node: AnyNode, parent: AnyNode | null) => void): void;
587
+ //#endregion
588
+ //#region src/utils/validateNode.d.ts
589
+ /**
590
+ * Validate if a node matches its expected structure
591
+ * @param node - Node to validate
592
+ * @returns True if node is valid
593
+ */
594
+ declare function validateNode(node: AnyNode): boolean;
595
+ /**
596
+ * Check if a node is of a specific type with type guard
597
+ * @param node - Node to check
598
+ * @param type - Expected node type
599
+ * @returns True if node is of the specified type
600
+ */
601
+ declare function isNodeType<T extends NodeTypes>(node: AnyNode, type: T): boolean;
602
+ //#endregion
603
+ //#region src/utils/findNodeByType.d.ts
604
+ /**
605
+ * Find all nodes of a specific type in the AST
606
+ * @param node - Root node to search from
607
+ * @param type - Node type to search for
608
+ * @returns Array of matching nodes
609
+ */
610
+ declare function findNodeByType<T extends NodeTypes>(node: AnyNode, type: T): AnyNode[];
611
+ /**
612
+ * Find the first node of a specific type in the AST
613
+ * @param node - Root node to search from
614
+ * @param type - Node type to search for
615
+ * @returns First matching node or undefined
616
+ */
617
+ declare function findFirstNodeByType<T extends NodeTypes>(node: AnyNode, type: T): AnyNode | undefined;
618
+ //#endregion
532
619
  //#region src/index.d.ts
533
620
  declare const name: string;
534
621
  declare const VisitorKeys: eslint0.SourceCode.VisitorKeys;
535
622
  declare function parse(code: string, options?: Options): Program;
536
623
  //#endregion
537
- export { type index_d_exports as AST, AnyContextualNode, AnyNode, AnyToken, AttributeKeyNode, AttributeNode, AttributeValueNode, AttributeValueWrapperEndNode, AttributeValueWrapperStartNode, BaseNode, COMMENT_END, COMMENT_START, CloseTagNode, CommentCloseNode, CommentContentNode, CommentNode, CommentOpenNode, ConstructTreeContextTypes, ConstructTreeHandler, ConstructTreeState, ContextuaLXMLDeclarationNode, ContextualAttributeNode, ContextualCommentNode, ContextualDoctypeAttributeNode, ContextualDoctypeNode, ContextualDocumentNode, ContextualNode, ContextualTagNode, ContextualXMLDeclarationAttributeNode, DEPRECATED_SVG_ELEMENTS, DoctypeAttributeNode, DoctypeAttributeValueNode, DoctypeAttributeWrapperEndNode, DoctypeAttributeWrapperStartNode, DoctypeCloseNode, DoctypeNode, DoctypeOpenNode, DocumentNode, Locations, NestableNode, NodeTypes, OpenTagEndNode, OpenTagStartNode, Options, ParseError, ParseForESLintResult, ParseResult, PartialBy, Position, Program, RE_CLOSE_TAG_NAME, RE_INCOMPLETE_CLOSING_TAG, RE_OPEN_TAG_NAME, RE_OPEN_TAG_START, Range, SELF_CLOSING_ELEMENTS, SPECIAL_CHAR, SVG_ELEMENTS, SimpleNode, SourceLocation, TagNode, TextNode, Token, TokenTypes, TokenizeHandler, TokenizerContextTypes, TokenizerState, VisitorKeys, XMLDeclarationAttributeKeyNode, XMLDeclarationAttributeNode, XMLDeclarationAttributeValueNode, XMLDeclarationAttributeValueWrapperEndNode, XMLDeclarationAttributeValueWrapperStartNode, XMLDeclarationCloseNode, XMLDeclarationNode, XMLDeclarationOpenNode, XML_DECLARATION_END, XML_DECLARATION_START, meta, name, parse, parseForESLint };
624
+ export { type index_d_exports as AST, type ASTVisitor, AnyContextualNode, AnyNode, AnyToken, AttributeKeyNode, AttributeNode, AttributeValueNode, BaseNode, COMMENT_END, COMMENT_START, CommentNode, ConstructTreeContextTypes, ConstructTreeHandler, ConstructTreeState, ContextualAttributeNode, ContextualCommentNode, ContextualDoctypeAttributeNode, ContextualDoctypeNode, ContextualDocumentNode, ContextualNode, ContextualTagNode, ContextualXMLDeclarationAttributeNode, ContextualXMLDeclarationNode, DEPRECATED_SVG_ELEMENTS, DoctypeAttributeNode, DoctypeAttributeValueNode, DoctypeNode, DocumentNode, ErrorNode, Locations, NestableNode, NodeTypes, Options, ParseError, ParseForESLintResult, ParseResult, PartialBy, Position, Program, RE_CLOSE_TAG_NAME, RE_INCOMPLETE_CLOSING_TAG, RE_OPEN_TAG_NAME, RE_OPEN_TAG_START, Range, SELF_CLOSING_ELEMENTS, SPECIAL_CHAR, SVG_ELEMENTS, SimpleNode, SourceLocation, TagNode, TextNode, Token, TokenTypes, TokenizeHandler, TokenizerContextTypes, TokenizerState, VisitorKeys, XMLDeclarationAttributeKeyNode, XMLDeclarationAttributeNode, XMLDeclarationAttributeValueNode, XMLDeclarationNode, XML_DECLARATION_END, XML_DECLARATION_START, cloneNode, cloneNodeWithParent, countNodes, filterNodes, findFirstNodeByType, findNodeByType, getNodeDepth, getParentChain, isNodeType, mapNodes, meta, name, parse, parseForESLint, traverseAST, validateNode, walkAST };