svg-eslint-parser 0.0.7 → 0.1.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.
- package/README.md +10 -14
- package/dist/chunk-pbuEa-1d.js +13 -0
- package/dist/index.d.ts +31 -23
- package/dist/index.js +434 -506
- package/package.json +31 -29
- package/dist/chunk-CzXV76rE.js +0 -18
package/README.md
CHANGED
|
@@ -85,10 +85,10 @@ import {
|
|
|
85
85
|
} from 'svg-eslint-parser'
|
|
86
86
|
|
|
87
87
|
const { ast } = parseForESLint(svgSource)
|
|
88
|
-
const document = ast.
|
|
88
|
+
const document = ast.document
|
|
89
89
|
|
|
90
90
|
// Find all tag nodes
|
|
91
|
-
const tags = findNodeByType(document, NodeTypes.
|
|
91
|
+
const tags = findNodeByType(document, NodeTypes.Element)
|
|
92
92
|
console.log(`Found ${tags.length} tags`)
|
|
93
93
|
|
|
94
94
|
// Traverse with visitor pattern
|
|
@@ -145,22 +145,18 @@ Returns a Document node directly.
|
|
|
145
145
|
|
|
146
146
|
### Node Types
|
|
147
147
|
|
|
148
|
-
The parser
|
|
148
|
+
The parser currently exposes 16 AST node types:
|
|
149
149
|
|
|
150
|
-
**Document
|
|
150
|
+
**Program & Document**: `Program`, `Document`
|
|
151
151
|
|
|
152
|
-
**
|
|
152
|
+
**Element Tree**: `Element`, `Attribute`, `AttributeKey`, `AttributeValue`, `Text`, `Comment`
|
|
153
153
|
|
|
154
|
-
**
|
|
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`
|
|
154
|
+
**Declarations**: `Doctype`, `DoctypeAttribute`, `DoctypeAttributeValue`, `XMLDeclaration`, `XMLDeclarationAttribute`, `XMLDeclarationAttributeKey`, `XMLDeclarationAttributeValue`
|
|
161
155
|
|
|
162
156
|
**Error Handling**: `Error`
|
|
163
157
|
|
|
158
|
+
`NodeTypes.Tag` is still available as a deprecated alias of `NodeTypes.Element` for backward compatibility.
|
|
159
|
+
|
|
164
160
|
## Documentation
|
|
165
161
|
|
|
166
162
|
Full documentation is available at [svg-eslint-parser.ntnyq.com](https://svg-eslint-parser.ntnyq.com):
|
|
@@ -190,10 +186,10 @@ const svgCode = `
|
|
|
190
186
|
`
|
|
191
187
|
|
|
192
188
|
const { ast } = parseForESLint(svgCode)
|
|
193
|
-
const document = ast.
|
|
189
|
+
const document = ast.document
|
|
194
190
|
|
|
195
191
|
// Find all tags and filter for circles
|
|
196
|
-
const allTags = findNodeByType(document, NodeTypes.
|
|
192
|
+
const allTags = findNodeByType(document, NodeTypes.Element)
|
|
197
193
|
const circles = allTags.filter(tag => tag.name === 'circle')
|
|
198
194
|
|
|
199
195
|
console.log(`Found ${circles.length} circles`)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _$eslint from "eslint";
|
|
2
2
|
import { SourceCode } from "eslint";
|
|
3
3
|
|
|
4
4
|
//#region src/meta.d.ts
|
|
@@ -66,9 +66,11 @@ declare enum NodeTypes {
|
|
|
66
66
|
DoctypeAttribute = "DoctypeAttribute",
|
|
67
67
|
DoctypeAttributeValue = "DoctypeAttributeValue",
|
|
68
68
|
Document = "Document",
|
|
69
|
+
Element = "Element",
|
|
69
70
|
Error = "Error",
|
|
70
71
|
Program = "Program",
|
|
71
|
-
|
|
72
|
+
/** @deprecated Use Element instead. */
|
|
73
|
+
Tag = "Element",
|
|
72
74
|
Text = "Text",
|
|
73
75
|
XMLDeclaration = "XMLDeclaration",
|
|
74
76
|
XMLDeclarationAttribute = "XMLDeclarationAttribute",
|
|
@@ -271,7 +273,7 @@ type AttributeValueNode = SimpleNode<NodeTypes.AttributeValue>;
|
|
|
271
273
|
interface AttributeNode extends BaseNode {
|
|
272
274
|
key: AttributeKeyNode;
|
|
273
275
|
type: NodeTypes.Attribute;
|
|
274
|
-
value
|
|
276
|
+
value?: AttributeValueNode;
|
|
275
277
|
quoteChar?: '"' | "'" | undefined;
|
|
276
278
|
}
|
|
277
279
|
/**
|
|
@@ -297,16 +299,18 @@ interface DoctypeNode extends BaseNode {
|
|
|
297
299
|
type: NodeTypes.Doctype;
|
|
298
300
|
}
|
|
299
301
|
/**
|
|
300
|
-
*
|
|
302
|
+
* element nodes
|
|
301
303
|
* @pg
|
|
302
304
|
*/
|
|
303
|
-
interface
|
|
305
|
+
interface ElementNode extends BaseNode {
|
|
304
306
|
attributes: AttributeNode[];
|
|
305
|
-
children:
|
|
307
|
+
children: ElementChildNode[];
|
|
306
308
|
name: string;
|
|
307
309
|
selfClosing: boolean;
|
|
308
|
-
type: NodeTypes.
|
|
310
|
+
type: NodeTypes.Element;
|
|
309
311
|
}
|
|
312
|
+
/** @deprecated Use ElementNode instead. */
|
|
313
|
+
type TagNode = ElementNode;
|
|
310
314
|
/**
|
|
311
315
|
* XML declaration nodes
|
|
312
316
|
*/
|
|
@@ -315,7 +319,7 @@ type XMLDeclarationAttributeValueNode = SimpleNode<NodeTypes.XMLDeclarationAttri
|
|
|
315
319
|
interface XMLDeclarationAttributeNode extends BaseNode {
|
|
316
320
|
key: XMLDeclarationAttributeKeyNode;
|
|
317
321
|
type: NodeTypes.XMLDeclarationAttribute;
|
|
318
|
-
value
|
|
322
|
+
value?: XMLDeclarationAttributeValueNode;
|
|
319
323
|
quoteChar?: '"' | "'" | undefined;
|
|
320
324
|
}
|
|
321
325
|
interface XMLDeclarationNode extends BaseNode {
|
|
@@ -333,29 +337,31 @@ interface ErrorNode extends BaseNode {
|
|
|
333
337
|
recoveredNode?: AnyNode;
|
|
334
338
|
}
|
|
335
339
|
/**
|
|
336
|
-
*
|
|
340
|
+
* child node
|
|
337
341
|
* @pg
|
|
338
342
|
*/
|
|
339
|
-
type
|
|
343
|
+
type DocumentChildNode = XMLDeclarationNode | DoctypeNode | ElementNode | CommentNode | TextNode;
|
|
344
|
+
type ElementChildNode = ElementNode | CommentNode | TextNode;
|
|
340
345
|
/**
|
|
341
346
|
* program
|
|
342
347
|
* @pg
|
|
343
348
|
*/
|
|
344
349
|
interface Program extends BaseNode {
|
|
345
|
-
body:
|
|
350
|
+
body: [];
|
|
346
351
|
comments: ESLintComment[];
|
|
352
|
+
document: DocumentNode;
|
|
347
353
|
tokens: AnyToken[];
|
|
348
354
|
type: NodeTypes.Program;
|
|
349
355
|
}
|
|
350
356
|
interface DocumentNode extends BaseNode {
|
|
351
|
-
children:
|
|
357
|
+
children: DocumentChildNode[];
|
|
352
358
|
type: NodeTypes.Document;
|
|
353
359
|
}
|
|
354
360
|
/**
|
|
355
361
|
* any node
|
|
356
362
|
* @pg
|
|
357
363
|
*/
|
|
358
|
-
type AnyNode = AttributeKeyNode | AttributeNode | AttributeValueNode | CommentNode | DoctypeAttributeNode | DoctypeAttributeValueNode | DoctypeNode | DocumentNode |
|
|
364
|
+
type AnyNode = AttributeKeyNode | AttributeNode | AttributeValueNode | CommentNode | DoctypeAttributeNode | DoctypeAttributeValueNode | DoctypeNode | DocumentNode | ElementNode | ErrorNode | Program | TextNode | XMLDeclarationAttributeKeyNode | XMLDeclarationAttributeNode | XMLDeclarationAttributeValueNode | XMLDeclarationNode;
|
|
359
365
|
//#endregion
|
|
360
366
|
//#region src/types/parse.d.ts
|
|
361
367
|
interface Options {
|
|
@@ -390,7 +396,7 @@ interface ParseResult {
|
|
|
390
396
|
}
|
|
391
397
|
//#endregion
|
|
392
398
|
//#region src/types/contextualNode.d.ts
|
|
393
|
-
type AnyContextualNode = ContextualAttributeNode | ContextualCommentNode | ContextualDoctypeAttributeNode | ContextualDoctypeNode | ContextualDocumentNode |
|
|
399
|
+
type AnyContextualNode = ContextualAttributeNode | ContextualCommentNode | ContextualDoctypeAttributeNode | ContextualDoctypeNode | ContextualDocumentNode | ContextualElementNode | ContextualXMLDeclarationAttributeNode | ContextualXMLDeclarationNode;
|
|
394
400
|
type ContextualAttributeNode = ContextualNode<AttributeNode, 'key' | 'value'>;
|
|
395
401
|
type ContextualCommentNode = ContextualNode<CommentNode, 'content'>;
|
|
396
402
|
type ContextualDoctypeAttributeNode = ContextualNode<DoctypeAttributeNode, 'type' | 'value'>;
|
|
@@ -398,15 +404,17 @@ type ContextualDoctypeNode = ContextualNode<DoctypeNode, 'attributes'> & {
|
|
|
398
404
|
attributes: ContextualDoctypeAttributeNode[];
|
|
399
405
|
};
|
|
400
406
|
type ContextualDocumentNode = Omit<ContextualNode<DocumentNode, never>, 'children'> & {
|
|
401
|
-
children: Array<DocumentNode['children'][number] |
|
|
407
|
+
children: Array<DocumentNode['children'][number] | ContextualCommentNode | ContextualDoctypeNode | ContextualElementNode | ContextualXMLDeclarationNode>;
|
|
402
408
|
};
|
|
403
409
|
type ContextualNode<T extends AnyNode, K extends keyof T> = PartialBy<T, K> & {
|
|
404
410
|
parentRef?: any;
|
|
405
411
|
};
|
|
406
|
-
type
|
|
412
|
+
type ContextualElementNode = ContextualNode<ElementNode, 'attributes' | 'children' | 'name' | 'selfClosing'> & {
|
|
407
413
|
attributes: ContextualAttributeNode[];
|
|
408
|
-
children: Array<ContextualCommentNode |
|
|
414
|
+
children: Array<ContextualCommentNode | ContextualElementNode | ElementNode['children'][number]>;
|
|
409
415
|
};
|
|
416
|
+
/** @deprecated Use ContextualElementNode instead. */
|
|
417
|
+
type ContextualTagNode = ContextualElementNode;
|
|
410
418
|
type ContextualXMLDeclarationAttributeNode = ContextualNode<XMLDeclarationAttributeNode, 'key' | 'value'>;
|
|
411
419
|
type ContextualXMLDeclarationNode = ContextualNode<XMLDeclarationNode, 'attributes'> & {
|
|
412
420
|
attributes: ContextualXMLDeclarationAttributeNode[];
|
|
@@ -483,9 +491,9 @@ type ContextParams = {
|
|
|
483
491
|
};
|
|
484
492
|
//#endregion
|
|
485
493
|
//#region src/types/constructTreeState.d.ts
|
|
486
|
-
type ConstructTreeState<
|
|
494
|
+
type ConstructTreeState<Node extends AnyContextualNode> = {
|
|
487
495
|
caretPosition: number;
|
|
488
|
-
currentNode:
|
|
496
|
+
currentNode: Node;
|
|
489
497
|
rootNode: DocumentNode;
|
|
490
498
|
currentContext: {
|
|
491
499
|
type: ConstructTreeContextTypes;
|
|
@@ -505,7 +513,7 @@ interface TokenizeHandler {
|
|
|
505
513
|
handleContentEnd?: (state: TokenizerState) => void;
|
|
506
514
|
}
|
|
507
515
|
declare namespace index_d_exports {
|
|
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,
|
|
516
|
+
export { AnyContextualNode, AnyNode, AnyToken, AttributeKeyNode, AttributeNode, AttributeValueNode, BaseNode, CommentNode, ConstructTreeHandler, ConstructTreeState, ContextualAttributeNode, ContextualCommentNode, ContextualDoctypeAttributeNode, ContextualDoctypeNode, ContextualDocumentNode, ContextualElementNode, ContextualNode, ContextualTagNode, ContextualXMLDeclarationAttributeNode, ContextualXMLDeclarationNode, DoctypeAttributeNode, DoctypeAttributeValueNode, DoctypeNode, DocumentChildNode, DocumentNode, ESLintComment, ElementChildNode, ElementNode, ErrorNode, Locations, Options, ParseForESLintResult, ParseResult, PartialBy, Position, Program, Range, SimpleNode, SourceLocation, TagNode, TextNode, Token, TokenizeHandler, TokenizerState, XMLDeclarationAttributeKeyNode, XMLDeclarationAttributeNode, XMLDeclarationAttributeValueNode, XMLDeclarationNode };
|
|
509
517
|
}
|
|
510
518
|
//#endregion
|
|
511
519
|
//#region src/parser/parseForESLint.d.ts
|
|
@@ -622,7 +630,7 @@ declare function findFirstNodeByType<T extends NodeTypes>(node: AnyNode, type: T
|
|
|
622
630
|
//#endregion
|
|
623
631
|
//#region src/index.d.ts
|
|
624
632
|
declare const name: string;
|
|
625
|
-
declare const VisitorKeys:
|
|
626
|
-
declare function parse(code: string, options?: Options):
|
|
633
|
+
declare const VisitorKeys: _$eslint.SourceCode.VisitorKeys;
|
|
634
|
+
declare function parse(code: string, options?: Options): DocumentNode;
|
|
627
635
|
//#endregion
|
|
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,
|
|
636
|
+
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, ContextualElementNode, ContextualNode, ContextualTagNode, ContextualXMLDeclarationAttributeNode, ContextualXMLDeclarationNode, DEPRECATED_SVG_ELEMENTS, DoctypeAttributeNode, DoctypeAttributeValueNode, DoctypeNode, DocumentChildNode, DocumentNode, ESLintComment, ElementChildNode, ElementNode, ErrorNode, Locations, 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 };
|