svg-eslint-parser 0.0.1 → 0.0.2
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 +7 -1
- package/dist/index.cjs +213 -1
- package/dist/index.d.cts +65 -1
- package/dist/index.d.ts +65 -1
- package/dist/index.js +198 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
> [!IMPORTANT]
|
|
12
12
|
> Status: Work In Progress, not ready for production.
|
|
13
13
|
>
|
|
14
|
-
>
|
|
14
|
+
> API is not stale now, Use at your own risk.
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
@@ -27,6 +27,12 @@ yarn add svg-eslint-parser -D
|
|
|
27
27
|
pnpm add svg-eslint-parser -D
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Playground
|
|
31
|
+
|
|
32
|
+
You can try the parser in [playground](https://svg-eslint-parser.ntnyq.com/play).
|
|
33
|
+
|
|
34
|
+
Feel free to open an issue if you have any suggestions or find any bugs.
|
|
35
|
+
|
|
30
36
|
## Links
|
|
31
37
|
|
|
32
38
|
- [Scalable Vector Graphics (SVG) 2](https://www.w3.org/TR/SVG2/)
|
package/dist/index.cjs
CHANGED
|
@@ -20,10 +20,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
COMMENT_END: () => COMMENT_END,
|
|
24
|
+
COMMENT_START: () => COMMENT_START,
|
|
25
|
+
ConstructTreeContextTypes: () => ConstructTreeContextTypes,
|
|
26
|
+
DEPRECATED_SVG_ELEMENTS: () => DEPRECATED_SVG_ELEMENTS,
|
|
27
|
+
NodeTypes: () => NodeTypes,
|
|
23
28
|
ParseError: () => ParseError,
|
|
29
|
+
RE_CLOSE_TAG_NAME: () => RE_CLOSE_TAG_NAME,
|
|
30
|
+
RE_INCOMPLETE_CLOSING_TAG: () => RE_INCOMPLETE_CLOSING_TAG,
|
|
31
|
+
RE_OPEN_TAG_NAME: () => RE_OPEN_TAG_NAME,
|
|
32
|
+
RE_OPEN_TAG_START: () => RE_OPEN_TAG_START,
|
|
33
|
+
SELF_CLOSING_ELEMENTS: () => SELF_CLOSING_ELEMENTS,
|
|
34
|
+
SPECIAL_CHAR: () => SPECIAL_CHAR,
|
|
35
|
+
SVG_ELEMENTS: () => SVG_ELEMENTS,
|
|
36
|
+
TokenTypes: () => TokenTypes,
|
|
37
|
+
TokenizerContextTypes: () => TokenizerContextTypes,
|
|
24
38
|
VisitorKeys: () => VisitorKeys,
|
|
25
39
|
meta: () => meta,
|
|
26
40
|
name: () => name2,
|
|
41
|
+
parse: () => parse17,
|
|
27
42
|
parseForESLint: () => parseForESLint,
|
|
28
43
|
parseSVG: () => parseSVG
|
|
29
44
|
});
|
|
@@ -31,7 +46,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
31
46
|
|
|
32
47
|
// package.json
|
|
33
48
|
var name = "svg-eslint-parser";
|
|
34
|
-
var version = "0.0.
|
|
49
|
+
var version = "0.0.2";
|
|
35
50
|
|
|
36
51
|
// src/meta.ts
|
|
37
52
|
var meta = {
|
|
@@ -59,6 +74,64 @@ var COMMENT_END = "-->";
|
|
|
59
74
|
var RE_OPEN_TAG_START = /^<\w/;
|
|
60
75
|
var RE_OPEN_TAG_NAME = /^<(\S+)/;
|
|
61
76
|
var RE_CLOSE_TAG_NAME = /^<\/((?:.|\n)*)>$/;
|
|
77
|
+
var RE_INCOMPLETE_CLOSING_TAG = /<\/[^>]+$/;
|
|
78
|
+
|
|
79
|
+
// src/constants/nodeTypes.ts
|
|
80
|
+
var NodeTypes = /* @__PURE__ */ ((NodeTypes2) => {
|
|
81
|
+
NodeTypes2["Program"] = "Program";
|
|
82
|
+
NodeTypes2["Document"] = "Document";
|
|
83
|
+
NodeTypes2["Text"] = "Text";
|
|
84
|
+
NodeTypes2["XMLDeclaration"] = "XMLDeclaration";
|
|
85
|
+
NodeTypes2["Doctype"] = "Doctype";
|
|
86
|
+
NodeTypes2["DoctypeOpen"] = "DoctypeOpen";
|
|
87
|
+
NodeTypes2["DoctypeClose"] = "DoctypeClose";
|
|
88
|
+
NodeTypes2["DoctypeAttribute"] = "DoctypeAttribute";
|
|
89
|
+
NodeTypes2["DoctypeAttributeValue"] = "DoctypeAttributeValue";
|
|
90
|
+
NodeTypes2["DoctypeAttributeWrapperEnd"] = "DoctypeAttributeWrapperEnd";
|
|
91
|
+
NodeTypes2["DoctypeAttributeWrapperStart"] = "DoctypeAttributeWrapperStart";
|
|
92
|
+
NodeTypes2["Tag"] = "Tag";
|
|
93
|
+
NodeTypes2["OpenTagStart"] = "OpenTagStart";
|
|
94
|
+
NodeTypes2["OpenTagEnd"] = "OpenTagEnd";
|
|
95
|
+
NodeTypes2["CloseTag"] = "CloseTag";
|
|
96
|
+
NodeTypes2["Comment"] = "Comment";
|
|
97
|
+
NodeTypes2["CommentOpen"] = "CommentOpen";
|
|
98
|
+
NodeTypes2["CommentClose"] = "CommentClose";
|
|
99
|
+
NodeTypes2["CommentContent"] = "CommentContent";
|
|
100
|
+
NodeTypes2["Attribute"] = "Attribute";
|
|
101
|
+
NodeTypes2["AttributeKey"] = "AttributeKey";
|
|
102
|
+
NodeTypes2["AttributeValue"] = "AttributeValue";
|
|
103
|
+
NodeTypes2["AttributeValueWrapperStart"] = "AttributeValueWrapperStart";
|
|
104
|
+
NodeTypes2["AttributeValueWrapperEnd"] = "AttributeValueWrapperEnd";
|
|
105
|
+
return NodeTypes2;
|
|
106
|
+
})(NodeTypes || {});
|
|
107
|
+
|
|
108
|
+
// src/constants/tokenTypes.ts
|
|
109
|
+
var TokenTypes = /* @__PURE__ */ ((TokenTypes2) => {
|
|
110
|
+
TokenTypes2["Program"] = "Program";
|
|
111
|
+
TokenTypes2["Document"] = "Document";
|
|
112
|
+
TokenTypes2["Text"] = "Text";
|
|
113
|
+
TokenTypes2["Doctype"] = "Doctype";
|
|
114
|
+
TokenTypes2["DoctypeOpen"] = "DoctypeOpen";
|
|
115
|
+
TokenTypes2["DoctypeClose"] = "DoctypeClose";
|
|
116
|
+
TokenTypes2["DoctypeAttributeValue"] = "DoctypeAttributeValue";
|
|
117
|
+
TokenTypes2["DoctypeAttributeWrapperStart"] = "DoctypeAttributeWrapperStart";
|
|
118
|
+
TokenTypes2["DoctypeAttributeWrapperEnd"] = "DoctypeAttributeWrapperEnd";
|
|
119
|
+
TokenTypes2["Tag"] = "Tag";
|
|
120
|
+
TokenTypes2["OpenTagStart"] = "OpenTagStart";
|
|
121
|
+
TokenTypes2["OpenTagEnd"] = "OpenTagEnd";
|
|
122
|
+
TokenTypes2["CloseTag"] = "CloseTag";
|
|
123
|
+
TokenTypes2["Comment"] = "Comment";
|
|
124
|
+
TokenTypes2["CommentOpen"] = "CommentOpen";
|
|
125
|
+
TokenTypes2["CommentClose"] = "CommentClose";
|
|
126
|
+
TokenTypes2["CommentContent"] = "CommentContent";
|
|
127
|
+
TokenTypes2["Attribute"] = "Attribute";
|
|
128
|
+
TokenTypes2["AttributeKey"] = "AttributeKey";
|
|
129
|
+
TokenTypes2["AttributeValue"] = "AttributeValue";
|
|
130
|
+
TokenTypes2["AttributeAssignment"] = "AttributeAssignment";
|
|
131
|
+
TokenTypes2["AttributeValueWrapperStart"] = "AttributeValueWrapperStart";
|
|
132
|
+
TokenTypes2["AttributeValueWrapperEnd"] = "AttributeValueWrapperEnd";
|
|
133
|
+
return TokenTypes2;
|
|
134
|
+
})(TokenTypes || {});
|
|
62
135
|
|
|
63
136
|
// src/constants/specialChar.ts
|
|
64
137
|
var SPECIAL_CHAR = {
|
|
@@ -81,6 +154,92 @@ var SPECIAL_CHAR = {
|
|
|
81
154
|
};
|
|
82
155
|
|
|
83
156
|
// src/constants/svgElements.ts
|
|
157
|
+
var SVG_ELEMENTS = /* @__PURE__ */ new Set([
|
|
158
|
+
"a",
|
|
159
|
+
"animate",
|
|
160
|
+
"animateMotion",
|
|
161
|
+
"animateTransform",
|
|
162
|
+
"circle",
|
|
163
|
+
"clipPath",
|
|
164
|
+
// not listed in mdn docs
|
|
165
|
+
"color-profile",
|
|
166
|
+
"defs",
|
|
167
|
+
"desc",
|
|
168
|
+
"ellipse",
|
|
169
|
+
"feBlend",
|
|
170
|
+
"feColorMatrix",
|
|
171
|
+
"feComponentTransfer",
|
|
172
|
+
"feComposite",
|
|
173
|
+
"feConvolveMatrix",
|
|
174
|
+
"feDiffuseLighting",
|
|
175
|
+
"feDisplacementMap",
|
|
176
|
+
"feDistantLight",
|
|
177
|
+
"feDropShadow",
|
|
178
|
+
"feFlood",
|
|
179
|
+
"feFuncA",
|
|
180
|
+
"feFuncB",
|
|
181
|
+
"feFuncG",
|
|
182
|
+
"feFuncR",
|
|
183
|
+
"feGaussianBlur",
|
|
184
|
+
"feImage",
|
|
185
|
+
"feMerge",
|
|
186
|
+
"feMergeNode",
|
|
187
|
+
"feMorphology",
|
|
188
|
+
"feOffset",
|
|
189
|
+
"fePointLight",
|
|
190
|
+
"feSpecularLighting",
|
|
191
|
+
"feSpotLight",
|
|
192
|
+
"feTile",
|
|
193
|
+
"feTurbulence",
|
|
194
|
+
"filter",
|
|
195
|
+
"foreignObject",
|
|
196
|
+
"g",
|
|
197
|
+
"image",
|
|
198
|
+
"line",
|
|
199
|
+
"linearGradient",
|
|
200
|
+
"marker",
|
|
201
|
+
"mask",
|
|
202
|
+
"metadata",
|
|
203
|
+
"mpath",
|
|
204
|
+
"path",
|
|
205
|
+
"pattern",
|
|
206
|
+
"polygon",
|
|
207
|
+
"polyline",
|
|
208
|
+
"radialGradient",
|
|
209
|
+
"rect",
|
|
210
|
+
"script",
|
|
211
|
+
"set",
|
|
212
|
+
"stop",
|
|
213
|
+
"style",
|
|
214
|
+
"svg",
|
|
215
|
+
"switch",
|
|
216
|
+
"symbol",
|
|
217
|
+
"text",
|
|
218
|
+
"textPath",
|
|
219
|
+
"title",
|
|
220
|
+
"tspan",
|
|
221
|
+
"use",
|
|
222
|
+
"view"
|
|
223
|
+
]);
|
|
224
|
+
var DEPRECATED_SVG_ELEMENTS = /* @__PURE__ */ new Set([
|
|
225
|
+
"altGlyph",
|
|
226
|
+
"altGlyphDef",
|
|
227
|
+
"altGlyphItem",
|
|
228
|
+
"animateColor",
|
|
229
|
+
"cursor",
|
|
230
|
+
"font",
|
|
231
|
+
"font-face",
|
|
232
|
+
"font-face-format",
|
|
233
|
+
"font-face-name",
|
|
234
|
+
"font-face-src",
|
|
235
|
+
"font-face-uri",
|
|
236
|
+
"glyph",
|
|
237
|
+
"glyphRef",
|
|
238
|
+
"hkern",
|
|
239
|
+
"missing-glyph",
|
|
240
|
+
"tref",
|
|
241
|
+
"vkern"
|
|
242
|
+
]);
|
|
84
243
|
var SELF_CLOSING_ELEMENTS = /* @__PURE__ */ new Set([
|
|
85
244
|
"animate",
|
|
86
245
|
"animateMotion",
|
|
@@ -116,6 +275,43 @@ var SELF_CLOSING_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
116
275
|
"view"
|
|
117
276
|
]);
|
|
118
277
|
|
|
278
|
+
// src/constants/tokenizerContextTypes.ts
|
|
279
|
+
var TokenizerContextTypes = /* @__PURE__ */ ((TokenizerContextTypes2) => {
|
|
280
|
+
TokenizerContextTypes2["Data"] = "Data";
|
|
281
|
+
TokenizerContextTypes2["OpenTagStart"] = "OpenTagStart";
|
|
282
|
+
TokenizerContextTypes2["OpenTagEnd"] = "OpenTagEnd";
|
|
283
|
+
TokenizerContextTypes2["CloseTag"] = "CloseTag";
|
|
284
|
+
TokenizerContextTypes2["Attributes"] = "Attributes";
|
|
285
|
+
TokenizerContextTypes2["AttributeKey"] = "AttributeKey";
|
|
286
|
+
TokenizerContextTypes2["AttributeValue"] = "AttributeValue";
|
|
287
|
+
TokenizerContextTypes2["AttributeValueBare"] = "AttributeValueBare";
|
|
288
|
+
TokenizerContextTypes2["AttributeValueWrapped"] = "AttributeValueWrapped";
|
|
289
|
+
TokenizerContextTypes2["CommentContent"] = "CommentContent";
|
|
290
|
+
TokenizerContextTypes2["CommentOpen"] = "CommentOpen";
|
|
291
|
+
TokenizerContextTypes2["CommentClose"] = "CommentClose";
|
|
292
|
+
TokenizerContextTypes2["DoctypeOpen"] = "DoctypeOpen";
|
|
293
|
+
TokenizerContextTypes2["DoctypeClose"] = "DoctypeClose";
|
|
294
|
+
TokenizerContextTypes2["DoctypeAttributes"] = "DoctypeAttributes";
|
|
295
|
+
TokenizerContextTypes2["DoctypeAttributeBare"] = "DoctypeAttributeBare";
|
|
296
|
+
TokenizerContextTypes2["DoctypeAttributeWrapped"] = "DoctypeAttributeWrapped";
|
|
297
|
+
return TokenizerContextTypes2;
|
|
298
|
+
})(TokenizerContextTypes || {});
|
|
299
|
+
|
|
300
|
+
// src/constants/constructTreeContextTypes.ts
|
|
301
|
+
var ConstructTreeContextTypes = /* @__PURE__ */ ((ConstructTreeContextTypes2) => {
|
|
302
|
+
ConstructTreeContextTypes2["Tag"] = "Tag";
|
|
303
|
+
ConstructTreeContextTypes2["TagName"] = "TagName";
|
|
304
|
+
ConstructTreeContextTypes2["TagContent"] = "TagContent";
|
|
305
|
+
ConstructTreeContextTypes2["Attribute"] = "Attribute";
|
|
306
|
+
ConstructTreeContextTypes2["Attributes"] = "Attributes";
|
|
307
|
+
ConstructTreeContextTypes2["AttributeValue"] = "AttributeValue";
|
|
308
|
+
ConstructTreeContextTypes2["Doctype"] = "Doctype";
|
|
309
|
+
ConstructTreeContextTypes2["DoctypeAttribute"] = "DoctypeAttribute";
|
|
310
|
+
ConstructTreeContextTypes2["DoctypeAttributes"] = "DoctypeAttributes";
|
|
311
|
+
ConstructTreeContextTypes2["Comment"] = "Comment";
|
|
312
|
+
return ConstructTreeContextTypes2;
|
|
313
|
+
})(ConstructTreeContextTypes || {});
|
|
314
|
+
|
|
119
315
|
// src/utils/firstLast.ts
|
|
120
316
|
function first(items) {
|
|
121
317
|
return items[0];
|
|
@@ -1703,12 +1899,28 @@ function parseSVG(code, options = {}) {
|
|
|
1703
1899
|
}
|
|
1704
1900
|
var name2 = meta.name;
|
|
1705
1901
|
var VisitorKeys = visitorKeys;
|
|
1902
|
+
var parse17 = parseSVG;
|
|
1706
1903
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1707
1904
|
0 && (module.exports = {
|
|
1905
|
+
COMMENT_END,
|
|
1906
|
+
COMMENT_START,
|
|
1907
|
+
ConstructTreeContextTypes,
|
|
1908
|
+
DEPRECATED_SVG_ELEMENTS,
|
|
1909
|
+
NodeTypes,
|
|
1708
1910
|
ParseError,
|
|
1911
|
+
RE_CLOSE_TAG_NAME,
|
|
1912
|
+
RE_INCOMPLETE_CLOSING_TAG,
|
|
1913
|
+
RE_OPEN_TAG_NAME,
|
|
1914
|
+
RE_OPEN_TAG_START,
|
|
1915
|
+
SELF_CLOSING_ELEMENTS,
|
|
1916
|
+
SPECIAL_CHAR,
|
|
1917
|
+
SVG_ELEMENTS,
|
|
1918
|
+
TokenTypes,
|
|
1919
|
+
TokenizerContextTypes,
|
|
1709
1920
|
VisitorKeys,
|
|
1710
1921
|
meta,
|
|
1711
1922
|
name,
|
|
1923
|
+
parse,
|
|
1712
1924
|
parseForESLint,
|
|
1713
1925
|
parseSVG
|
|
1714
1926
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,35 @@ declare class ParseError extends SyntaxError {
|
|
|
16
16
|
constructor(message: string, offset: number, line: number, column: number);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* svg comment start
|
|
21
|
+
*/
|
|
22
|
+
declare const COMMENT_START = "<!--";
|
|
23
|
+
/**
|
|
24
|
+
* svg comment end
|
|
25
|
+
*/
|
|
26
|
+
declare const COMMENT_END = "-->";
|
|
27
|
+
/**
|
|
28
|
+
* regexp for open tag start
|
|
29
|
+
* @regex101 https://regex101.com/?regex=%5E%3C%5Cw&flavor=javascript
|
|
30
|
+
*/
|
|
31
|
+
declare const RE_OPEN_TAG_START: RegExp;
|
|
32
|
+
/**
|
|
33
|
+
* regexp for open tag name
|
|
34
|
+
* @regex101 https://regex101.com/?regex=%5E%3C%28%5CS%2B%29&flavor=javascript
|
|
35
|
+
*/
|
|
36
|
+
declare const RE_OPEN_TAG_NAME: RegExp;
|
|
37
|
+
/**
|
|
38
|
+
* regexp for close tag name
|
|
39
|
+
* @regex101 https://regex101.com/?regex=%5E%3C%5C%2F%28%28%3F%3A.%7C%5Cn%29*%29%3E%24&flavor=javascript
|
|
40
|
+
*/
|
|
41
|
+
declare const RE_CLOSE_TAG_NAME: RegExp;
|
|
42
|
+
/**
|
|
43
|
+
* regexp for incomplete closing tag
|
|
44
|
+
* @regex101 https://regex101.com/?regex=%3C%5C%2F%5B%5E%3E%5D%2B%24&flavor=javascript
|
|
45
|
+
*/
|
|
46
|
+
declare const RE_INCOMPLETE_CLOSING_TAG: RegExp;
|
|
47
|
+
|
|
19
48
|
declare enum NodeTypes {
|
|
20
49
|
Program = "Program",
|
|
21
50
|
Document = "Document",
|
|
@@ -69,6 +98,40 @@ declare enum TokenTypes {
|
|
|
69
98
|
AttributeValueWrapperEnd = "AttributeValueWrapperEnd"
|
|
70
99
|
}
|
|
71
100
|
|
|
101
|
+
declare const SPECIAL_CHAR: {
|
|
102
|
+
closingCorner: string;
|
|
103
|
+
colon: string;
|
|
104
|
+
comma: string;
|
|
105
|
+
doubleQuote: string;
|
|
106
|
+
equal: string;
|
|
107
|
+
exclamation: string;
|
|
108
|
+
hyphen: string;
|
|
109
|
+
newline: string;
|
|
110
|
+
openingCorner: string;
|
|
111
|
+
question: string;
|
|
112
|
+
return: string;
|
|
113
|
+
singleQuote: string;
|
|
114
|
+
slash: string;
|
|
115
|
+
space: string;
|
|
116
|
+
tab: string;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @copyright {@link https://github.com/davidohlin/svg-elements}
|
|
121
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element}
|
|
122
|
+
*/
|
|
123
|
+
declare const SVG_ELEMENTS: Set<string>;
|
|
124
|
+
/**
|
|
125
|
+
* obsolete and deprecated elements
|
|
126
|
+
*
|
|
127
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element#obsolete_and_deprecated_elements}
|
|
128
|
+
*/
|
|
129
|
+
declare const DEPRECATED_SVG_ELEMENTS: Set<string>;
|
|
130
|
+
/**
|
|
131
|
+
* self closing svg elements
|
|
132
|
+
*/
|
|
133
|
+
declare const SELF_CLOSING_ELEMENTS: Set<string>;
|
|
134
|
+
|
|
72
135
|
declare enum TokenizerContextTypes {
|
|
73
136
|
Data = "Data",
|
|
74
137
|
OpenTagStart = "OpenTagStart",
|
|
@@ -419,5 +482,6 @@ declare function parseForESLint(source: string, options?: Options): ParseForESLi
|
|
|
419
482
|
declare function parseSVG(code: string, options?: Options): Program;
|
|
420
483
|
declare const name: string;
|
|
421
484
|
declare const VisitorKeys: eslint.SourceCode.VisitorKeys;
|
|
485
|
+
declare const parse: typeof parseSVG;
|
|
422
486
|
|
|
423
|
-
export { index as AST, ParseError, VisitorKeys, meta, name, parseForESLint, parseSVG };
|
|
487
|
+
export { index as AST, type AnyContextualNode, type AnyNode, type AnyToken, type AttributeKeyNode, type AttributeNode, type AttributeValueNode, type AttributeValueWrapperEndNode, type AttributeValueWrapperStartNode, type BaseNode, COMMENT_END, COMMENT_START, type CloseTagNode, type CommentCloseNode, type CommentContentNode, type CommentNode, type CommentOpenNode, ConstructTreeContextTypes, type ConstructTreeHandler, type ConstructTreeState, type ContextualAttributeNode, type ContextualCommentNode, type ContextualDoctypeAttributeNode, type ContextualDoctypeNode, type ContextualDocumentNode, type ContextualNode, type ContextualTagNode, DEPRECATED_SVG_ELEMENTS, type DoctypeAttributeNode, type DoctypeAttributeValueNode, type DoctypeAttributeWrapperEndNode, type DoctypeAttributeWrapperStartNode, type DoctypeCloseNode, type DoctypeNode, type DoctypeOpenNode, type DocumentNode, type Locations, type NestableNode, NodeTypes, type OpenTagEndNode, type OpenTagStartNode, type Options, ParseError, type ParseForESLintResult, type ParseResult, type PartialBy, type Position, type Program, RE_CLOSE_TAG_NAME, RE_INCOMPLETE_CLOSING_TAG, RE_OPEN_TAG_NAME, RE_OPEN_TAG_START, type Range, SELF_CLOSING_ELEMENTS, SPECIAL_CHAR, SVG_ELEMENTS, type SimpleNode, type SourceLocation, type TagNode, type TextNode, type Token, TokenTypes, type TokenizeHandler, TokenizerContextTypes, type TokenizerState, VisitorKeys, type XMLDeclarationNode, meta, name, parse, parseForESLint, parseSVG };
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,35 @@ declare class ParseError extends SyntaxError {
|
|
|
16
16
|
constructor(message: string, offset: number, line: number, column: number);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* svg comment start
|
|
21
|
+
*/
|
|
22
|
+
declare const COMMENT_START = "<!--";
|
|
23
|
+
/**
|
|
24
|
+
* svg comment end
|
|
25
|
+
*/
|
|
26
|
+
declare const COMMENT_END = "-->";
|
|
27
|
+
/**
|
|
28
|
+
* regexp for open tag start
|
|
29
|
+
* @regex101 https://regex101.com/?regex=%5E%3C%5Cw&flavor=javascript
|
|
30
|
+
*/
|
|
31
|
+
declare const RE_OPEN_TAG_START: RegExp;
|
|
32
|
+
/**
|
|
33
|
+
* regexp for open tag name
|
|
34
|
+
* @regex101 https://regex101.com/?regex=%5E%3C%28%5CS%2B%29&flavor=javascript
|
|
35
|
+
*/
|
|
36
|
+
declare const RE_OPEN_TAG_NAME: RegExp;
|
|
37
|
+
/**
|
|
38
|
+
* regexp for close tag name
|
|
39
|
+
* @regex101 https://regex101.com/?regex=%5E%3C%5C%2F%28%28%3F%3A.%7C%5Cn%29*%29%3E%24&flavor=javascript
|
|
40
|
+
*/
|
|
41
|
+
declare const RE_CLOSE_TAG_NAME: RegExp;
|
|
42
|
+
/**
|
|
43
|
+
* regexp for incomplete closing tag
|
|
44
|
+
* @regex101 https://regex101.com/?regex=%3C%5C%2F%5B%5E%3E%5D%2B%24&flavor=javascript
|
|
45
|
+
*/
|
|
46
|
+
declare const RE_INCOMPLETE_CLOSING_TAG: RegExp;
|
|
47
|
+
|
|
19
48
|
declare enum NodeTypes {
|
|
20
49
|
Program = "Program",
|
|
21
50
|
Document = "Document",
|
|
@@ -69,6 +98,40 @@ declare enum TokenTypes {
|
|
|
69
98
|
AttributeValueWrapperEnd = "AttributeValueWrapperEnd"
|
|
70
99
|
}
|
|
71
100
|
|
|
101
|
+
declare const SPECIAL_CHAR: {
|
|
102
|
+
closingCorner: string;
|
|
103
|
+
colon: string;
|
|
104
|
+
comma: string;
|
|
105
|
+
doubleQuote: string;
|
|
106
|
+
equal: string;
|
|
107
|
+
exclamation: string;
|
|
108
|
+
hyphen: string;
|
|
109
|
+
newline: string;
|
|
110
|
+
openingCorner: string;
|
|
111
|
+
question: string;
|
|
112
|
+
return: string;
|
|
113
|
+
singleQuote: string;
|
|
114
|
+
slash: string;
|
|
115
|
+
space: string;
|
|
116
|
+
tab: string;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @copyright {@link https://github.com/davidohlin/svg-elements}
|
|
121
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element}
|
|
122
|
+
*/
|
|
123
|
+
declare const SVG_ELEMENTS: Set<string>;
|
|
124
|
+
/**
|
|
125
|
+
* obsolete and deprecated elements
|
|
126
|
+
*
|
|
127
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Element#obsolete_and_deprecated_elements}
|
|
128
|
+
*/
|
|
129
|
+
declare const DEPRECATED_SVG_ELEMENTS: Set<string>;
|
|
130
|
+
/**
|
|
131
|
+
* self closing svg elements
|
|
132
|
+
*/
|
|
133
|
+
declare const SELF_CLOSING_ELEMENTS: Set<string>;
|
|
134
|
+
|
|
72
135
|
declare enum TokenizerContextTypes {
|
|
73
136
|
Data = "Data",
|
|
74
137
|
OpenTagStart = "OpenTagStart",
|
|
@@ -419,5 +482,6 @@ declare function parseForESLint(source: string, options?: Options): ParseForESLi
|
|
|
419
482
|
declare function parseSVG(code: string, options?: Options): Program;
|
|
420
483
|
declare const name: string;
|
|
421
484
|
declare const VisitorKeys: eslint.SourceCode.VisitorKeys;
|
|
485
|
+
declare const parse: typeof parseSVG;
|
|
422
486
|
|
|
423
|
-
export { index as AST, ParseError, VisitorKeys, meta, name, parseForESLint, parseSVG };
|
|
487
|
+
export { index as AST, type AnyContextualNode, type AnyNode, type AnyToken, type AttributeKeyNode, type AttributeNode, type AttributeValueNode, type AttributeValueWrapperEndNode, type AttributeValueWrapperStartNode, type BaseNode, COMMENT_END, COMMENT_START, type CloseTagNode, type CommentCloseNode, type CommentContentNode, type CommentNode, type CommentOpenNode, ConstructTreeContextTypes, type ConstructTreeHandler, type ConstructTreeState, type ContextualAttributeNode, type ContextualCommentNode, type ContextualDoctypeAttributeNode, type ContextualDoctypeNode, type ContextualDocumentNode, type ContextualNode, type ContextualTagNode, DEPRECATED_SVG_ELEMENTS, type DoctypeAttributeNode, type DoctypeAttributeValueNode, type DoctypeAttributeWrapperEndNode, type DoctypeAttributeWrapperStartNode, type DoctypeCloseNode, type DoctypeNode, type DoctypeOpenNode, type DocumentNode, type Locations, type NestableNode, NodeTypes, type OpenTagEndNode, type OpenTagStartNode, type Options, ParseError, type ParseForESLintResult, type ParseResult, type PartialBy, type Position, type Program, RE_CLOSE_TAG_NAME, RE_INCOMPLETE_CLOSING_TAG, RE_OPEN_TAG_NAME, RE_OPEN_TAG_START, type Range, SELF_CLOSING_ELEMENTS, SPECIAL_CHAR, SVG_ELEMENTS, type SimpleNode, type SourceLocation, type TagNode, type TextNode, type Token, TokenTypes, type TokenizeHandler, TokenizerContextTypes, type TokenizerState, VisitorKeys, type XMLDeclarationNode, meta, name, parse, parseForESLint, parseSVG };
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// package.json
|
|
8
8
|
var name = "svg-eslint-parser";
|
|
9
|
-
var version = "0.0.
|
|
9
|
+
var version = "0.0.2";
|
|
10
10
|
|
|
11
11
|
// src/meta.ts
|
|
12
12
|
var meta = {
|
|
@@ -34,6 +34,64 @@ var COMMENT_END = "-->";
|
|
|
34
34
|
var RE_OPEN_TAG_START = /^<\w/;
|
|
35
35
|
var RE_OPEN_TAG_NAME = /^<(\S+)/;
|
|
36
36
|
var RE_CLOSE_TAG_NAME = /^<\/((?:.|\n)*)>$/;
|
|
37
|
+
var RE_INCOMPLETE_CLOSING_TAG = /<\/[^>]+$/;
|
|
38
|
+
|
|
39
|
+
// src/constants/nodeTypes.ts
|
|
40
|
+
var NodeTypes = /* @__PURE__ */ ((NodeTypes2) => {
|
|
41
|
+
NodeTypes2["Program"] = "Program";
|
|
42
|
+
NodeTypes2["Document"] = "Document";
|
|
43
|
+
NodeTypes2["Text"] = "Text";
|
|
44
|
+
NodeTypes2["XMLDeclaration"] = "XMLDeclaration";
|
|
45
|
+
NodeTypes2["Doctype"] = "Doctype";
|
|
46
|
+
NodeTypes2["DoctypeOpen"] = "DoctypeOpen";
|
|
47
|
+
NodeTypes2["DoctypeClose"] = "DoctypeClose";
|
|
48
|
+
NodeTypes2["DoctypeAttribute"] = "DoctypeAttribute";
|
|
49
|
+
NodeTypes2["DoctypeAttributeValue"] = "DoctypeAttributeValue";
|
|
50
|
+
NodeTypes2["DoctypeAttributeWrapperEnd"] = "DoctypeAttributeWrapperEnd";
|
|
51
|
+
NodeTypes2["DoctypeAttributeWrapperStart"] = "DoctypeAttributeWrapperStart";
|
|
52
|
+
NodeTypes2["Tag"] = "Tag";
|
|
53
|
+
NodeTypes2["OpenTagStart"] = "OpenTagStart";
|
|
54
|
+
NodeTypes2["OpenTagEnd"] = "OpenTagEnd";
|
|
55
|
+
NodeTypes2["CloseTag"] = "CloseTag";
|
|
56
|
+
NodeTypes2["Comment"] = "Comment";
|
|
57
|
+
NodeTypes2["CommentOpen"] = "CommentOpen";
|
|
58
|
+
NodeTypes2["CommentClose"] = "CommentClose";
|
|
59
|
+
NodeTypes2["CommentContent"] = "CommentContent";
|
|
60
|
+
NodeTypes2["Attribute"] = "Attribute";
|
|
61
|
+
NodeTypes2["AttributeKey"] = "AttributeKey";
|
|
62
|
+
NodeTypes2["AttributeValue"] = "AttributeValue";
|
|
63
|
+
NodeTypes2["AttributeValueWrapperStart"] = "AttributeValueWrapperStart";
|
|
64
|
+
NodeTypes2["AttributeValueWrapperEnd"] = "AttributeValueWrapperEnd";
|
|
65
|
+
return NodeTypes2;
|
|
66
|
+
})(NodeTypes || {});
|
|
67
|
+
|
|
68
|
+
// src/constants/tokenTypes.ts
|
|
69
|
+
var TokenTypes = /* @__PURE__ */ ((TokenTypes2) => {
|
|
70
|
+
TokenTypes2["Program"] = "Program";
|
|
71
|
+
TokenTypes2["Document"] = "Document";
|
|
72
|
+
TokenTypes2["Text"] = "Text";
|
|
73
|
+
TokenTypes2["Doctype"] = "Doctype";
|
|
74
|
+
TokenTypes2["DoctypeOpen"] = "DoctypeOpen";
|
|
75
|
+
TokenTypes2["DoctypeClose"] = "DoctypeClose";
|
|
76
|
+
TokenTypes2["DoctypeAttributeValue"] = "DoctypeAttributeValue";
|
|
77
|
+
TokenTypes2["DoctypeAttributeWrapperStart"] = "DoctypeAttributeWrapperStart";
|
|
78
|
+
TokenTypes2["DoctypeAttributeWrapperEnd"] = "DoctypeAttributeWrapperEnd";
|
|
79
|
+
TokenTypes2["Tag"] = "Tag";
|
|
80
|
+
TokenTypes2["OpenTagStart"] = "OpenTagStart";
|
|
81
|
+
TokenTypes2["OpenTagEnd"] = "OpenTagEnd";
|
|
82
|
+
TokenTypes2["CloseTag"] = "CloseTag";
|
|
83
|
+
TokenTypes2["Comment"] = "Comment";
|
|
84
|
+
TokenTypes2["CommentOpen"] = "CommentOpen";
|
|
85
|
+
TokenTypes2["CommentClose"] = "CommentClose";
|
|
86
|
+
TokenTypes2["CommentContent"] = "CommentContent";
|
|
87
|
+
TokenTypes2["Attribute"] = "Attribute";
|
|
88
|
+
TokenTypes2["AttributeKey"] = "AttributeKey";
|
|
89
|
+
TokenTypes2["AttributeValue"] = "AttributeValue";
|
|
90
|
+
TokenTypes2["AttributeAssignment"] = "AttributeAssignment";
|
|
91
|
+
TokenTypes2["AttributeValueWrapperStart"] = "AttributeValueWrapperStart";
|
|
92
|
+
TokenTypes2["AttributeValueWrapperEnd"] = "AttributeValueWrapperEnd";
|
|
93
|
+
return TokenTypes2;
|
|
94
|
+
})(TokenTypes || {});
|
|
37
95
|
|
|
38
96
|
// src/constants/specialChar.ts
|
|
39
97
|
var SPECIAL_CHAR = {
|
|
@@ -56,6 +114,92 @@ var SPECIAL_CHAR = {
|
|
|
56
114
|
};
|
|
57
115
|
|
|
58
116
|
// src/constants/svgElements.ts
|
|
117
|
+
var SVG_ELEMENTS = /* @__PURE__ */ new Set([
|
|
118
|
+
"a",
|
|
119
|
+
"animate",
|
|
120
|
+
"animateMotion",
|
|
121
|
+
"animateTransform",
|
|
122
|
+
"circle",
|
|
123
|
+
"clipPath",
|
|
124
|
+
// not listed in mdn docs
|
|
125
|
+
"color-profile",
|
|
126
|
+
"defs",
|
|
127
|
+
"desc",
|
|
128
|
+
"ellipse",
|
|
129
|
+
"feBlend",
|
|
130
|
+
"feColorMatrix",
|
|
131
|
+
"feComponentTransfer",
|
|
132
|
+
"feComposite",
|
|
133
|
+
"feConvolveMatrix",
|
|
134
|
+
"feDiffuseLighting",
|
|
135
|
+
"feDisplacementMap",
|
|
136
|
+
"feDistantLight",
|
|
137
|
+
"feDropShadow",
|
|
138
|
+
"feFlood",
|
|
139
|
+
"feFuncA",
|
|
140
|
+
"feFuncB",
|
|
141
|
+
"feFuncG",
|
|
142
|
+
"feFuncR",
|
|
143
|
+
"feGaussianBlur",
|
|
144
|
+
"feImage",
|
|
145
|
+
"feMerge",
|
|
146
|
+
"feMergeNode",
|
|
147
|
+
"feMorphology",
|
|
148
|
+
"feOffset",
|
|
149
|
+
"fePointLight",
|
|
150
|
+
"feSpecularLighting",
|
|
151
|
+
"feSpotLight",
|
|
152
|
+
"feTile",
|
|
153
|
+
"feTurbulence",
|
|
154
|
+
"filter",
|
|
155
|
+
"foreignObject",
|
|
156
|
+
"g",
|
|
157
|
+
"image",
|
|
158
|
+
"line",
|
|
159
|
+
"linearGradient",
|
|
160
|
+
"marker",
|
|
161
|
+
"mask",
|
|
162
|
+
"metadata",
|
|
163
|
+
"mpath",
|
|
164
|
+
"path",
|
|
165
|
+
"pattern",
|
|
166
|
+
"polygon",
|
|
167
|
+
"polyline",
|
|
168
|
+
"radialGradient",
|
|
169
|
+
"rect",
|
|
170
|
+
"script",
|
|
171
|
+
"set",
|
|
172
|
+
"stop",
|
|
173
|
+
"style",
|
|
174
|
+
"svg",
|
|
175
|
+
"switch",
|
|
176
|
+
"symbol",
|
|
177
|
+
"text",
|
|
178
|
+
"textPath",
|
|
179
|
+
"title",
|
|
180
|
+
"tspan",
|
|
181
|
+
"use",
|
|
182
|
+
"view"
|
|
183
|
+
]);
|
|
184
|
+
var DEPRECATED_SVG_ELEMENTS = /* @__PURE__ */ new Set([
|
|
185
|
+
"altGlyph",
|
|
186
|
+
"altGlyphDef",
|
|
187
|
+
"altGlyphItem",
|
|
188
|
+
"animateColor",
|
|
189
|
+
"cursor",
|
|
190
|
+
"font",
|
|
191
|
+
"font-face",
|
|
192
|
+
"font-face-format",
|
|
193
|
+
"font-face-name",
|
|
194
|
+
"font-face-src",
|
|
195
|
+
"font-face-uri",
|
|
196
|
+
"glyph",
|
|
197
|
+
"glyphRef",
|
|
198
|
+
"hkern",
|
|
199
|
+
"missing-glyph",
|
|
200
|
+
"tref",
|
|
201
|
+
"vkern"
|
|
202
|
+
]);
|
|
59
203
|
var SELF_CLOSING_ELEMENTS = /* @__PURE__ */ new Set([
|
|
60
204
|
"animate",
|
|
61
205
|
"animateMotion",
|
|
@@ -91,6 +235,43 @@ var SELF_CLOSING_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
91
235
|
"view"
|
|
92
236
|
]);
|
|
93
237
|
|
|
238
|
+
// src/constants/tokenizerContextTypes.ts
|
|
239
|
+
var TokenizerContextTypes = /* @__PURE__ */ ((TokenizerContextTypes2) => {
|
|
240
|
+
TokenizerContextTypes2["Data"] = "Data";
|
|
241
|
+
TokenizerContextTypes2["OpenTagStart"] = "OpenTagStart";
|
|
242
|
+
TokenizerContextTypes2["OpenTagEnd"] = "OpenTagEnd";
|
|
243
|
+
TokenizerContextTypes2["CloseTag"] = "CloseTag";
|
|
244
|
+
TokenizerContextTypes2["Attributes"] = "Attributes";
|
|
245
|
+
TokenizerContextTypes2["AttributeKey"] = "AttributeKey";
|
|
246
|
+
TokenizerContextTypes2["AttributeValue"] = "AttributeValue";
|
|
247
|
+
TokenizerContextTypes2["AttributeValueBare"] = "AttributeValueBare";
|
|
248
|
+
TokenizerContextTypes2["AttributeValueWrapped"] = "AttributeValueWrapped";
|
|
249
|
+
TokenizerContextTypes2["CommentContent"] = "CommentContent";
|
|
250
|
+
TokenizerContextTypes2["CommentOpen"] = "CommentOpen";
|
|
251
|
+
TokenizerContextTypes2["CommentClose"] = "CommentClose";
|
|
252
|
+
TokenizerContextTypes2["DoctypeOpen"] = "DoctypeOpen";
|
|
253
|
+
TokenizerContextTypes2["DoctypeClose"] = "DoctypeClose";
|
|
254
|
+
TokenizerContextTypes2["DoctypeAttributes"] = "DoctypeAttributes";
|
|
255
|
+
TokenizerContextTypes2["DoctypeAttributeBare"] = "DoctypeAttributeBare";
|
|
256
|
+
TokenizerContextTypes2["DoctypeAttributeWrapped"] = "DoctypeAttributeWrapped";
|
|
257
|
+
return TokenizerContextTypes2;
|
|
258
|
+
})(TokenizerContextTypes || {});
|
|
259
|
+
|
|
260
|
+
// src/constants/constructTreeContextTypes.ts
|
|
261
|
+
var ConstructTreeContextTypes = /* @__PURE__ */ ((ConstructTreeContextTypes2) => {
|
|
262
|
+
ConstructTreeContextTypes2["Tag"] = "Tag";
|
|
263
|
+
ConstructTreeContextTypes2["TagName"] = "TagName";
|
|
264
|
+
ConstructTreeContextTypes2["TagContent"] = "TagContent";
|
|
265
|
+
ConstructTreeContextTypes2["Attribute"] = "Attribute";
|
|
266
|
+
ConstructTreeContextTypes2["Attributes"] = "Attributes";
|
|
267
|
+
ConstructTreeContextTypes2["AttributeValue"] = "AttributeValue";
|
|
268
|
+
ConstructTreeContextTypes2["Doctype"] = "Doctype";
|
|
269
|
+
ConstructTreeContextTypes2["DoctypeAttribute"] = "DoctypeAttribute";
|
|
270
|
+
ConstructTreeContextTypes2["DoctypeAttributes"] = "DoctypeAttributes";
|
|
271
|
+
ConstructTreeContextTypes2["Comment"] = "Comment";
|
|
272
|
+
return ConstructTreeContextTypes2;
|
|
273
|
+
})(ConstructTreeContextTypes || {});
|
|
274
|
+
|
|
94
275
|
// src/utils/firstLast.ts
|
|
95
276
|
function first(items) {
|
|
96
277
|
return items[0];
|
|
@@ -1678,11 +1859,27 @@ function parseSVG(code, options = {}) {
|
|
|
1678
1859
|
}
|
|
1679
1860
|
var name2 = meta.name;
|
|
1680
1861
|
var VisitorKeys = visitorKeys;
|
|
1862
|
+
var parse17 = parseSVG;
|
|
1681
1863
|
export {
|
|
1864
|
+
COMMENT_END,
|
|
1865
|
+
COMMENT_START,
|
|
1866
|
+
ConstructTreeContextTypes,
|
|
1867
|
+
DEPRECATED_SVG_ELEMENTS,
|
|
1868
|
+
NodeTypes,
|
|
1682
1869
|
ParseError,
|
|
1870
|
+
RE_CLOSE_TAG_NAME,
|
|
1871
|
+
RE_INCOMPLETE_CLOSING_TAG,
|
|
1872
|
+
RE_OPEN_TAG_NAME,
|
|
1873
|
+
RE_OPEN_TAG_START,
|
|
1874
|
+
SELF_CLOSING_ELEMENTS,
|
|
1875
|
+
SPECIAL_CHAR,
|
|
1876
|
+
SVG_ELEMENTS,
|
|
1877
|
+
TokenTypes,
|
|
1878
|
+
TokenizerContextTypes,
|
|
1683
1879
|
VisitorKeys,
|
|
1684
1880
|
meta,
|
|
1685
1881
|
name2 as name,
|
|
1882
|
+
parse17 as parse,
|
|
1686
1883
|
parseForESLint,
|
|
1687
1884
|
parseSVG
|
|
1688
1885
|
};
|