svg-eslint-parser 0.1.0 → 0.2.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 CHANGED
@@ -87,9 +87,9 @@ import {
87
87
  const { ast } = parseForESLint(svgSource)
88
88
  const document = ast.document
89
89
 
90
- // Find all tag nodes
91
- const tags = findNodeByType(document, NodeTypes.Element)
92
- console.log(`Found ${tags.length} tags`)
90
+ // Find all element nodes
91
+ const elements = findNodeByType(document, NodeTypes.Element)
92
+ console.log(`Found ${elements.length} elements`)
93
93
 
94
94
  // Traverse with visitor pattern
95
95
  traverseAST(document, {
@@ -155,8 +155,6 @@ The parser currently exposes 16 AST node types:
155
155
 
156
156
  **Error Handling**: `Error`
157
157
 
158
- `NodeTypes.Tag` is still available as a deprecated alias of `NodeTypes.Element` for backward compatibility.
159
-
160
158
  ## Documentation
161
159
 
162
160
  Full documentation is available at [svg-eslint-parser.ntnyq.com](https://svg-eslint-parser.ntnyq.com):
@@ -188,9 +186,9 @@ const svgCode = `
188
186
  const { ast } = parseForESLint(svgCode)
189
187
  const document = ast.document
190
188
 
191
- // Find all tags and filter for circles
192
- const allTags = findNodeByType(document, NodeTypes.Element)
193
- const circles = allTags.filter(tag => tag.name === 'circle')
189
+ // Find all elements and filter for circles
190
+ const allElements = findNodeByType(document, NodeTypes.Element)
191
+ const circles = allElements.filter(element => element.name === 'circle')
194
192
 
195
193
  console.log(`Found ${circles.length} circles`)
196
194
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import * as _$eslint from "eslint";
2
1
  import { SourceCode } from "eslint";
3
2
 
4
3
  //#region src/meta.d.ts
@@ -69,8 +68,6 @@ declare enum NodeTypes {
69
68
  Element = "Element",
70
69
  Error = "Error",
71
70
  Program = "Program",
72
- /** @deprecated Use Element instead. */
73
- Tag = "Element",
74
71
  Text = "Text",
75
72
  XMLDeclaration = "XMLDeclaration",
76
73
  XMLDeclarationAttribute = "XMLDeclarationAttribute",
@@ -309,8 +306,6 @@ interface ElementNode extends BaseNode {
309
306
  selfClosing: boolean;
310
307
  type: NodeTypes.Element;
311
308
  }
312
- /** @deprecated Use ElementNode instead. */
313
- type TagNode = ElementNode;
314
309
  /**
315
310
  * XML declaration nodes
316
311
  */
@@ -413,8 +408,6 @@ type ContextualElementNode = ContextualNode<ElementNode, 'attributes' | 'childre
413
408
  attributes: ContextualAttributeNode[];
414
409
  children: Array<ContextualCommentNode | ContextualElementNode | ElementNode['children'][number]>;
415
410
  };
416
- /** @deprecated Use ContextualElementNode instead. */
417
- type ContextualTagNode = ContextualElementNode;
418
411
  type ContextualXMLDeclarationAttributeNode = ContextualNode<XMLDeclarationAttributeNode, 'key' | 'value'>;
419
412
  type ContextualXMLDeclarationNode = ContextualNode<XMLDeclarationNode, 'attributes'> & {
420
413
  attributes: ContextualXMLDeclarationAttributeNode[];
@@ -513,7 +506,7 @@ interface TokenizeHandler {
513
506
  handleContentEnd?: (state: TokenizerState) => void;
514
507
  }
515
508
  declare namespace index_d_exports {
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
+ export { AnyContextualNode, AnyNode, AnyToken, AttributeKeyNode, AttributeNode, AttributeValueNode, BaseNode, CommentNode, ConstructTreeHandler, ConstructTreeState, ContextualAttributeNode, ContextualCommentNode, ContextualDoctypeAttributeNode, ContextualDoctypeNode, ContextualDocumentNode, ContextualElementNode, ContextualNode, ContextualXMLDeclarationAttributeNode, ContextualXMLDeclarationNode, DoctypeAttributeNode, DoctypeAttributeValueNode, DoctypeNode, DocumentChildNode, DocumentNode, ESLintComment, ElementChildNode, ElementNode, ErrorNode, Locations, Options, ParseForESLintResult, ParseResult, PartialBy, Position, Program, Range, SimpleNode, SourceLocation, TextNode, Token, TokenizeHandler, TokenizerState, XMLDeclarationAttributeKeyNode, XMLDeclarationAttributeNode, XMLDeclarationAttributeValueNode, XMLDeclarationNode };
517
510
  }
518
511
  //#endregion
519
512
  //#region src/parser/parseForESLint.d.ts
@@ -630,7 +623,7 @@ declare function findFirstNodeByType<T extends NodeTypes>(node: AnyNode, type: T
630
623
  //#endregion
631
624
  //#region src/index.d.ts
632
625
  declare const name: string;
633
- declare const VisitorKeys: _$eslint.SourceCode.VisitorKeys;
626
+ declare const VisitorKeys: import("eslint").SourceCode.VisitorKeys;
634
627
  declare function parse(code: string, options?: Options): DocumentNode;
635
628
  //#endregion
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 };
629
+ 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, 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, 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 };
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { t as __exportAll } from "./chunk-pbuEa-1d.js";
1
+ import { t as __exportAll } from "./chunk-D7D4PA-g.js";
2
2
  import { unionWith } from "eslint-visitor-keys";
3
3
  //#endregion
4
4
  //#region src/meta.ts
5
5
  const meta = {
6
6
  name: "svg-eslint-parser",
7
- version: "0.1.0"
7
+ version: "0.2.0"
8
8
  };
9
9
  //#endregion
10
10
  //#region src/parser/error.ts
@@ -50,12 +50,12 @@ const RE_OPEN_TAG_START = /^<\w/u;
50
50
  * regexp for open tag name
51
51
  * @regex101 https://regex101.com/?regex=%5E%3C%28%5CS%2B%29&flavor=javascript
52
52
  */
53
- const RE_OPEN_TAG_NAME = /^<(\S+)/u;
53
+ const RE_OPEN_TAG_NAME = /^<(?<tagName>\S+)/u;
54
54
  /**
55
55
  * regexp for close tag name
56
56
  * @regex101 https://regex101.com/?regex=%5E%3C%5C%2F%28%28%3F%3A.%7C%5Cr%3F%5Cn%29*%29%3E%24&flavor=javascript
57
57
  */
58
- const RE_CLOSE_TAG_NAME = /^<\/((?:.|\r?\n)*)>$/u;
58
+ const RE_CLOSE_TAG_NAME = /^<\/(?<tagName>(?:.|\r?\n)*)>$/u;
59
59
  /**
60
60
  * regexp for incomplete closing tag
61
61
  * @regex101 https://regex101.com/?regex=%3C%5C%2F%5B%5E%3E%5D%2B%24&flavor=javascript
@@ -75,8 +75,6 @@ let NodeTypes = /* @__PURE__ */ function(NodeTypes) {
75
75
  NodeTypes["Element"] = "Element";
76
76
  NodeTypes["Error"] = "Error";
77
77
  NodeTypes["Program"] = "Program";
78
- /** @deprecated Use Element instead. */
79
- NodeTypes["Tag"] = "Element";
80
78
  NodeTypes["Text"] = "Text";
81
79
  NodeTypes["XMLDeclaration"] = "XMLDeclaration";
82
80
  NodeTypes["XMLDeclarationAttribute"] = "XMLDeclarationAttribute";
@@ -616,7 +614,6 @@ function validateNode(node) {
616
614
  if (!Array.isArray(node.range) || node.range.length !== 2 || typeof node.range[0] !== "number" || typeof node.range[1] !== "number") return false;
617
615
  if (!node.loc || !node.loc.start || !node.loc.end || typeof node.loc.start.line !== "number" || typeof node.loc.start.column !== "number" || typeof node.loc.end.line !== "number" || typeof node.loc.end.column !== "number") return false;
618
616
  switch (node.type) {
619
- case "Element":
620
617
  case "Element": return validateElementNode(node);
621
618
  case "Attribute": return validateAttributeNode(node);
622
619
  case "Text": return validateTextNode(node);
@@ -737,7 +734,9 @@ function getLastAttribute(state) {
737
734
  function parseOpenTagName(openTagStartTokenContent) {
738
735
  const match = openTagStartTokenContent.match(RE_OPEN_TAG_NAME);
739
736
  if (match === null) throw new Error(`Unable to parse open tag name.\n${openTagStartTokenContent} does not match pattern of opening tag.`);
740
- return match[1].toLowerCase();
737
+ const tagName = match.groups?.tagName;
738
+ if (tagName === void 0) throw new Error(`Unable to parse open tag name. Named capture group "tagName" is missing.`);
739
+ return tagName.toLowerCase();
741
740
  }
742
741
  //#endregion
743
742
  //#region src/utils/parseCloseTagName.ts
@@ -750,7 +749,9 @@ function parseOpenTagName(openTagStartTokenContent) {
750
749
  function parseCloseTagName(closeTagTokenContent) {
751
750
  const match = closeTagTokenContent.match(RE_CLOSE_TAG_NAME);
752
751
  if (match === null) throw new Error(`Unable to parse close tag name.\n${closeTagTokenContent} does not match pattern of closing tag.`);
753
- return match[1].trim().toLowerCase();
752
+ const tagName = match.groups?.tagName;
753
+ if (tagName === void 0) throw new Error(`Unable to parse close tag name. Named capture group "tagName" is missing.`);
754
+ return tagName.trim().toLowerCase();
754
755
  }
755
756
  //#endregion
756
757
  //#region src/utils/calculateTokenLocation.ts
@@ -1054,7 +1055,7 @@ const dispatch$7 = createTokenDispatcher([
1054
1055
  tokenType: "OpenTagStart",
1055
1056
  handler(token, state) {
1056
1057
  initChildrenIfNone(state.currentNode);
1057
- const tagNode = {
1058
+ const elementNode = {
1058
1059
  type: "Element",
1059
1060
  parentRef: state.currentNode,
1060
1061
  range: cloneRange(token.range),
@@ -1062,8 +1063,8 @@ const dispatch$7 = createTokenDispatcher([
1062
1063
  attributes: [],
1063
1064
  children: []
1064
1065
  };
1065
- state.currentNode.children.push(tagNode);
1066
- state.currentNode = tagNode;
1066
+ state.currentNode.children.push(elementNode);
1067
+ state.currentNode = elementNode;
1067
1068
  state.currentContext = {
1068
1069
  parentRef: state.currentContext,
1069
1070
  type: "Tag"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svg-eslint-parser",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "An SVG parser that produces output compatible with ESLint.",
5
5
  "keywords": [
6
6
  "eslint-parser",
@@ -16,7 +16,10 @@
16
16
  "name": "ntnyq",
17
17
  "email": "ntnyq13@gmail.com"
18
18
  },
19
- "repository": "ntnyq/svg-eslint-parser",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "ntnyq/svg-eslint-parser"
22
+ },
20
23
  "files": [
21
24
  "dist"
22
25
  ],
@@ -32,22 +35,23 @@
32
35
  }
33
36
  },
34
37
  "dependencies": {
35
- "@ntnyq/utils": "^0.13.2",
38
+ "@ntnyq/utils": "^0.15.0",
36
39
  "eslint-visitor-keys": "^5.0.1"
37
40
  },
38
41
  "devDependencies": {
39
- "@types/node": "^25.6.2",
40
- "@typescript/native-preview": "^7.0.0-dev.20260508.1",
42
+ "@types/node": "^25.9.2",
43
+ "@typescript/native-preview": "^7.0.0-dev.20260606.1",
44
+ "@vitest/coverage-v8": "^4.1.8",
41
45
  "bumpp": "^11.1.0",
42
- "eslint": "^10.3.0",
46
+ "eslint": "^10.4.1",
43
47
  "husky": "^9.1.7",
44
48
  "nano-staged": "^1.0.2",
45
- "npm-run-all2": "^8.0.4",
46
- "oxfmt": "^0.48.0",
47
- "oxlint": "^1.63.0",
48
- "tsdown": "^0.22.0",
49
+ "npm-run-all2": "^9.0.1",
50
+ "oxfmt": "^0.53.0",
51
+ "oxlint": "^1.68.0",
52
+ "tsdown": "^0.22.2",
49
53
  "typescript": "^6.0.3",
50
- "vitest": "^4.1.5"
54
+ "vitest": "^4.1.8"
51
55
  },
52
56
  "nano-staged": {
53
57
  "*.{js,ts,mjs,tsx,vue}": "oxlint --fix",
@@ -66,6 +70,7 @@
66
70
  "release:check": "run-s format:check lint typecheck test",
67
71
  "release:version": "bumpp",
68
72
  "test": "vitest",
73
+ "test:coverage": "vitest run --coverage",
69
74
  "typecheck": "tsgo --noEmit"
70
75
  }
71
76
  }
File without changes