Skip to content

Commit 2298fe3

Browse files
committed
feat: add LiteralNode
1 parent a82f76b commit 2298fe3

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"devDependencies": {
2626
"@iconify-json/carbon": "^1.2.5",
27-
"@iconify-json/lucide": "^1.2.20",
27+
"@iconify-json/lucide": "^1.2.21",
2828
"@shikijs/transformers": "^1.26.1",
2929
"@shikijs/vitepress-twoslash": "^1.26.1",
3030
"twoslash": "^0.2.12",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svg-eslint-parser",
33
"type": "module",
44
"version": "0.0.2",
5-
"packageManager": "[email protected].2",
5+
"packageManager": "[email protected].3",
66
"description": "An SVG parser that produces output compatible with ESLint.",
77
"keywords": [
88
"eslint-parser",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants/nodeTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ export enum NodeTypes {
22
Program = 'Program',
33
Document = 'Document',
44
Text = 'Text',
5+
Literal = 'Literal',
56

67
XMLDeclaration = 'XMLDeclaration',
8+
XMLDeclarationAttribute = 'XMLDeclarationAttribute',
79

810
Doctype = 'Doctype',
911
DoctypeOpen = 'DoctypeOpen',

src/types/ast/node.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,38 @@ export interface SimpleNode<T extends NodeTypes> extends BaseNode {
1111
value: string
1212
}
1313

14+
/**
15+
* literal node
16+
*/
17+
export type LiteralNode = SimpleNode<NodeTypes.Literal> & {
18+
raw: string
19+
}
20+
21+
/**
22+
* XML declaration
23+
*/
24+
export interface XMLDeclarationAttributeNode extends BaseNode {
25+
key: LiteralNode
26+
type: NodeTypes.XMLDeclarationAttribute
27+
value: LiteralNode
28+
}
29+
export interface XMLDeclarationNode extends BaseNode {
30+
attributes: XMLDeclarationAttributeNode[]
31+
close: LiteralNode
32+
open: LiteralNode
33+
type: NodeTypes.XMLDeclaration
34+
}
35+
1436
/**
1537
* attribute
1638
*/
1739
export type AttributeKeyNode = SimpleNode<NodeTypes.AttributeKey>
1840
export interface AttributeNode extends BaseNode {
1941
key: AttributeKeyNode
2042
type: NodeTypes.Attribute
43+
value: AttributeValueNode
2144
endWrapper?: AttributeValueWrapperEndNode
2245
startWrapper?: AttributeValueWrapperStartNode
23-
value?: AttributeValueNode
2446
}
2547
export type AttributeValueNode = SimpleNode<NodeTypes.AttributeValue>
2648
export type AttributeValueWrapperEndNode = SimpleNode<NodeTypes.AttributeValueWrapperEnd>
@@ -66,14 +88,6 @@ export interface DocumentNode extends BaseNode {
6688
}
6789
export type TextNode = SimpleNode<NodeTypes.Text>
6890

69-
export interface XMLDeclarationNode extends BaseNode {
70-
/**
71-
* TODO: create XMLDeclarationAttributeNode
72-
*/
73-
attributes: AttributeNode[]
74-
type: NodeTypes.XMLDeclaration
75-
}
76-
7791
/**
7892
* tag
7993
*/
@@ -128,9 +142,11 @@ export type AnyNode =
128142
| DoctypeNode
129143
| DoctypeOpenNode
130144
| DocumentNode
145+
| LiteralNode
131146
| OpenTagEndNode
132147
| OpenTagStartNode
133148
| Program
134149
| TagNode
135150
| TextNode
151+
| XMLDeclarationAttributeNode
136152
| XMLDeclarationNode

src/visitorKeys.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ const keys: {
99
Document: ['children'],
1010

1111
XMLDeclaration: [],
12+
XMLDeclarationAttribute: ['key', 'value'],
1213

1314
Doctype: ['open', 'close', 'attributes'],
1415
DoctypeOpen: [],
1516
DoctypeClose: [],
16-
DoctypeAttribute: ['key'],
17-
DoctypeAttributeValue: [],
17+
DoctypeAttribute: ['key', 'value'],
18+
DoctypeAttributeValue: ['value'],
1819
DoctypeAttributeWrapperEnd: [],
1920
DoctypeAttributeWrapperStart: [],
2021

2122
Attribute: ['key', 'value'],
22-
AttributeKey: [],
23-
AttributeValue: [],
23+
AttributeKey: ['value'],
24+
AttributeValue: ['value'],
2425
AttributeValueWrapperEnd: [],
2526
AttributeValueWrapperStart: [],
2627

@@ -34,6 +35,7 @@ const keys: {
3435
CommentClose: [],
3536
CommentContent: [],
3637

38+
Literal: [],
3739
Text: [],
3840
}
3941

0 commit comments

Comments
 (0)