svg-eslint-parser 0.0.5 → 0.0.7

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
  */
@@ -262,118 +258,104 @@ interface SimpleNode<T extends NodeTypes> extends BaseNode {
262
258
  value: string;
263
259
  }
264
260
  type TextNode = SimpleNode<NodeTypes.Text>;
261
+ interface ESLintComment extends Locations {
262
+ type: 'Block' | 'Line';
263
+ value: string;
264
+ }
265
265
  /**
266
- * attribute
266
+ * attribute nodes
267
267
  * @pg
268
268
  */
269
269
  type AttributeKeyNode = SimpleNode<NodeTypes.AttributeKey>;
270
+ type AttributeValueNode = SimpleNode<NodeTypes.AttributeValue>;
270
271
  interface AttributeNode extends BaseNode {
271
272
  key: AttributeKeyNode;
272
273
  type: NodeTypes.Attribute;
273
274
  value: AttributeValueNode;
274
- endWrapper?: AttributeValueWrapperEndNode;
275
- startWrapper?: AttributeValueWrapperStartNode;
275
+ quoteChar?: '"' | "'" | undefined;
276
276
  }
277
- type AttributeValueNode = SimpleNode<NodeTypes.AttributeValue>;
278
- type AttributeValueWrapperEndNode = SimpleNode<NodeTypes.AttributeValueWrapperEnd>;
279
- type AttributeValueWrapperStartNode = SimpleNode<NodeTypes.AttributeValueWrapperStart>;
280
277
  /**
281
- * comment
278
+ * comment nodes
282
279
  * @pg
283
280
  */
284
- type CommentCloseNode = SimpleNode<NodeTypes.CommentClose>;
285
- type CommentContentNode = SimpleNode<NodeTypes.CommentContent>;
286
281
  interface CommentNode extends BaseNode {
287
- close: CommentCloseNode;
288
- open: CommentOpenNode;
282
+ content: string;
289
283
  type: NodeTypes.Comment;
290
- value: CommentContentNode;
291
284
  }
292
- type CommentOpenNode = SimpleNode<NodeTypes.CommentOpen>;
293
285
  /**
294
- * doctype
286
+ * doctype nodes
295
287
  * @pg
296
288
  */
289
+ type DoctypeAttributeValueNode = SimpleNode<NodeTypes.DoctypeAttributeValue>;
297
290
  interface DoctypeAttributeNode extends BaseNode {
298
291
  type: NodeTypes.DoctypeAttribute;
299
- endWrapper?: DoctypeAttributeWrapperEndNode;
300
- startWrapper?: DoctypeAttributeWrapperStartNode;
292
+ quoteChar?: '"' | "'" | undefined;
301
293
  value?: DoctypeAttributeValueNode;
302
294
  }
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
295
  interface DoctypeNode extends BaseNode {
308
296
  attributes: DoctypeAttributeNode[];
309
- close: DoctypeCloseNode;
310
- open: DoctypeOpenNode;
311
297
  type: NodeTypes.Doctype;
312
298
  }
313
- type DoctypeOpenNode = SimpleNode<NodeTypes.DoctypeOpen>;
314
299
  /**
315
- * tag
300
+ * tag nodes
316
301
  * @pg
317
302
  */
318
- type CloseTagNode = SimpleNode<NodeTypes.CloseTag>;
319
- type OpenTagEndNode = SimpleNode<NodeTypes.OpenTagEnd>;
320
- type OpenTagStartNode = SimpleNode<NodeTypes.OpenTagStart>;
321
303
  interface TagNode extends BaseNode {
322
304
  attributes: AttributeNode[];
323
305
  children: NestableNode[];
324
306
  name: string;
325
- openEnd: OpenTagEndNode;
326
- openStart: OpenTagStartNode;
327
307
  selfClosing: boolean;
328
308
  type: NodeTypes.Tag;
329
- close?: CloseTagNode;
330
309
  }
331
310
  /**
332
- * XML declaration
311
+ * XML declaration nodes
333
312
  */
334
313
  type XMLDeclarationAttributeKeyNode = SimpleNode<NodeTypes.XMLDeclarationAttributeKey>;
314
+ type XMLDeclarationAttributeValueNode = SimpleNode<NodeTypes.XMLDeclarationAttributeValue>;
335
315
  interface XMLDeclarationAttributeNode extends BaseNode {
336
316
  key: XMLDeclarationAttributeKeyNode;
337
317
  type: NodeTypes.XMLDeclarationAttribute;
338
318
  value: XMLDeclarationAttributeValueNode;
339
- endWrapper?: XMLDeclarationAttributeValueWrapperEndNode;
340
- startWrapper?: XMLDeclarationAttributeValueWrapperStartNode;
319
+ quoteChar?: '"' | "'" | undefined;
341
320
  }
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
321
  interface XMLDeclarationNode extends BaseNode {
347
322
  attributes: XMLDeclarationAttributeNode[];
348
- close: XMLDeclarationCloseNode;
349
- open: XMLDeclarationOpenNode;
350
323
  type: NodeTypes.XMLDeclaration;
351
324
  }
352
- type XMLDeclarationOpenNode = SimpleNode<NodeTypes.XMLDeclarationOpen>;
325
+ /**
326
+ * error nodes
327
+ * @pg
328
+ */
329
+ interface ErrorNode extends BaseNode {
330
+ code: string;
331
+ message: string;
332
+ type: NodeTypes.Error;
333
+ recoveredNode?: AnyNode;
334
+ }
353
335
  /**
354
336
  * nestable node
355
337
  * @pg
356
338
  */
357
- type NestableNode = CommentNode | TagNode | TextNode | XMLDeclarationNode;
339
+ type NestableNode = CommentNode | DoctypeNode | TagNode | TextNode | XMLDeclarationNode;
358
340
  /**
359
341
  * program
360
342
  * @pg
361
343
  */
362
- interface DocumentNode extends BaseNode {
363
- children: NestableNode[];
364
- type: NodeTypes.Document;
365
- }
366
344
  interface Program extends BaseNode {
367
345
  body: DocumentNode[];
368
- comments: CommentContentNode[];
346
+ comments: ESLintComment[];
369
347
  tokens: AnyToken[];
370
348
  type: NodeTypes.Program;
371
349
  }
350
+ interface DocumentNode extends BaseNode {
351
+ children: NestableNode[];
352
+ type: NodeTypes.Document;
353
+ }
372
354
  /**
373
355
  * any node
374
356
  * @pg
375
357
  */
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;
358
+ type AnyNode = AttributeKeyNode | AttributeNode | AttributeValueNode | CommentNode | DoctypeAttributeNode | DoctypeAttributeValueNode | DoctypeNode | DocumentNode | ErrorNode | Program | TagNode | TextNode | XMLDeclarationAttributeKeyNode | XMLDeclarationAttributeNode | XMLDeclarationAttributeValueNode | XMLDeclarationNode;
377
359
  //#endregion
378
360
  //#region src/types/parse.d.ts
379
361
  interface Options {
@@ -408,11 +390,11 @@ interface ParseResult {
408
390
  }
409
391
  //#endregion
410
392
  //#region src/types/contextualNode.d.ts
411
- type AnyContextualNode = ContextualAttributeNode | ContextualCommentNode | ContextualDoctypeAttributeNode | ContextualDoctypeNode | ContextualDocumentNode | ContextualTagNode | ContextualXMLDeclarationAttributeNode | ContextuaLXMLDeclarationNode;
393
+ type AnyContextualNode = ContextualAttributeNode | ContextualCommentNode | ContextualDoctypeAttributeNode | ContextualDoctypeNode | ContextualDocumentNode | ContextualTagNode | ContextualXMLDeclarationAttributeNode | ContextualXMLDeclarationNode;
412
394
  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'> & {
395
+ type ContextualCommentNode = ContextualNode<CommentNode, 'content'>;
396
+ type ContextualDoctypeAttributeNode = ContextualNode<DoctypeAttributeNode, 'type' | 'value'>;
397
+ type ContextualDoctypeNode = ContextualNode<DoctypeNode, 'attributes'> & {
416
398
  attributes: ContextualDoctypeAttributeNode[];
417
399
  };
418
400
  type ContextualDocumentNode = Omit<ContextualNode<DocumentNode, never>, 'children'> & {
@@ -421,12 +403,12 @@ type ContextualDocumentNode = Omit<ContextualNode<DocumentNode, never>, 'childre
421
403
  type ContextualNode<T extends AnyNode, K extends keyof T> = PartialBy<T, K> & {
422
404
  parentRef?: any;
423
405
  };
424
- type ContextualTagNode = ContextualNode<TagNode, 'close' | 'name' | 'openEnd' | 'openStart' | 'selfClosing'> & {
406
+ type ContextualTagNode = ContextualNode<TagNode, 'attributes' | 'children' | 'name' | 'selfClosing'> & {
425
407
  attributes: ContextualAttributeNode[];
426
408
  children: Array<ContextualCommentNode | ContextualDoctypeNode | ContextualTagNode | TagNode['children'][number]>;
427
409
  };
428
410
  type ContextualXMLDeclarationAttributeNode = ContextualNode<XMLDeclarationAttributeNode, 'key' | 'value'>;
429
- type ContextuaLXMLDeclarationNode = ContextualNode<XMLDeclarationNode, 'close' | 'open'> & {
411
+ type ContextualXMLDeclarationNode = ContextualNode<XMLDeclarationNode, 'attributes'> & {
430
412
  attributes: ContextualXMLDeclarationAttributeNode[];
431
413
  };
432
414
  type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
@@ -523,15 +505,124 @@ interface TokenizeHandler {
523
505
  handleContentEnd?: (state: TokenizerState) => void;
524
506
  }
525
507
  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 };
508
+ export { AnyContextualNode, AnyNode, AnyToken, AttributeKeyNode, AttributeNode, AttributeValueNode, BaseNode, CommentNode, ConstructTreeHandler, ConstructTreeState, ContextualAttributeNode, ContextualCommentNode, ContextualDoctypeAttributeNode, ContextualDoctypeNode, ContextualDocumentNode, ContextualNode, ContextualTagNode, ContextualXMLDeclarationAttributeNode, ContextualXMLDeclarationNode, DoctypeAttributeNode, DoctypeAttributeValueNode, DoctypeNode, DocumentNode, ESLintComment, ErrorNode, Locations, NestableNode, Options, ParseForESLintResult, ParseResult, PartialBy, Position, Program, Range, SimpleNode, SourceLocation, TagNode, TextNode, Token, TokenizeHandler, TokenizerState, XMLDeclarationAttributeKeyNode, XMLDeclarationAttributeNode, XMLDeclarationAttributeValueNode, XMLDeclarationNode };
527
509
  }
528
510
  //#endregion
529
511
  //#region src/parser/parseForESLint.d.ts
530
512
  declare function parseForESLint(source: string, options?: Options): ParseForESLintResult;
531
513
  //#endregion
514
+ //#region src/utils/cloneNode.d.ts
515
+ /**
516
+ * Deep clone a node, removing parent references
517
+ * @param node - Node to clone
518
+ * @returns Cloned node
519
+ */
520
+ declare function cloneNode<T extends AnyNode>(node: T): T;
521
+ /**
522
+ * Deep clone a node, preserving parent references
523
+ * @param node - Node to clone
524
+ * @param parent - Parent node for the cloned node
525
+ * @returns Cloned node with parent references
526
+ */
527
+ declare function cloneNodeWithParent<T extends AnyNode>(node: T, parent?: AnyNode): T;
528
+ //#endregion
529
+ //#region src/utils/nodeHelpers.d.ts
530
+ /**
531
+ * Filter nodes by a predicate function
532
+ * @param node - Root node to filter from
533
+ * @param predicate - Filter function
534
+ * @returns Array of matching nodes
535
+ */
536
+ declare function filterNodes(node: AnyNode, predicate: (node: AnyNode) => boolean): AnyNode[];
537
+ /**
538
+ * Map over all nodes in the AST
539
+ * @param node - Root node to map from
540
+ * @param mapper - Mapping function
541
+ * @returns Transformed node
542
+ */
543
+ declare function mapNodes<T extends AnyNode>(node: T, mapper: (node: AnyNode) => AnyNode): T;
544
+ /**
545
+ * Get all parent nodes from a node up to the root
546
+ * @param node - Starting node
547
+ * @returns Array of parent nodes (from immediate parent to root)
548
+ */
549
+ declare function getParentChain(node: any): AnyNode[];
550
+ /**
551
+ * Get the depth of a node in the AST (distance from root)
552
+ * @param node - Node to measure
553
+ * @returns Depth level (root = 0)
554
+ */
555
+ declare function getNodeDepth(node: any): number;
556
+ /**
557
+ * Count total number of nodes in the AST
558
+ * @param node - Root node
559
+ * @returns Total node count
560
+ */
561
+ declare function countNodes(node: AnyNode): number;
562
+ //#endregion
563
+ //#region src/utils/traverseAST.d.ts
564
+ /**
565
+ * Visitor function for AST traversal
566
+ */
567
+ type ASTVisitor = {
568
+ /**
569
+ * Called when entering a node
570
+ * Return false to skip traversing children
571
+ */
572
+ enter?: (node: AnyNode, parent: AnyNode | null) => void | boolean;
573
+ /**
574
+ * Called when leaving a node
575
+ */
576
+ leave?: (node: AnyNode, parent: AnyNode | null) => void;
577
+ };
578
+ /**
579
+ * Traverse the AST with a visitor pattern
580
+ * @param node - Root node to traverse from
581
+ * @param visitor - Visitor object with enter/leave hooks
582
+ * @param parent - Parent node (used internally)
583
+ */
584
+ declare function traverseAST(node: AnyNode, visitor: ASTVisitor, parent?: AnyNode | null): void;
585
+ /**
586
+ * Simple traversal function that calls a callback for each node
587
+ * @param node - Root node to traverse from
588
+ * @param callback - Function to call for each node
589
+ */
590
+ declare function walkAST(node: AnyNode, callback: (node: AnyNode, parent: AnyNode | null) => void): void;
591
+ //#endregion
592
+ //#region src/utils/validateNode.d.ts
593
+ /**
594
+ * Validate if a node matches its expected structure
595
+ * @param node - Node to validate
596
+ * @returns True if node is valid
597
+ */
598
+ declare function validateNode(node: AnyNode): boolean;
599
+ /**
600
+ * Check if a node is of a specific type with type guard
601
+ * @param node - Node to check
602
+ * @param type - Expected node type
603
+ * @returns True if node is of the specified type
604
+ */
605
+ declare function isNodeType<T extends NodeTypes>(node: AnyNode, type: T): boolean;
606
+ //#endregion
607
+ //#region src/utils/findNodeByType.d.ts
608
+ /**
609
+ * Find all nodes of a specific type in the AST
610
+ * @param node - Root node to search from
611
+ * @param type - Node type to search for
612
+ * @returns Array of matching nodes
613
+ */
614
+ declare function findNodeByType<T extends NodeTypes>(node: AnyNode, type: T): AnyNode[];
615
+ /**
616
+ * Find the first node of a specific type in the AST
617
+ * @param node - Root node to search from
618
+ * @param type - Node type to search for
619
+ * @returns First matching node or undefined
620
+ */
621
+ declare function findFirstNodeByType<T extends NodeTypes>(node: AnyNode, type: T): AnyNode | undefined;
622
+ //#endregion
532
623
  //#region src/index.d.ts
533
624
  declare const name: string;
534
625
  declare const VisitorKeys: eslint0.SourceCode.VisitorKeys;
535
626
  declare function parse(code: string, options?: Options): Program;
536
627
  //#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 };
628
+ 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, ESLintComment, 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 };