-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.ts
169 lines (158 loc) · 3.79 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import "@total-typescript/ts-reset/recommended";
import type { IterableElement } from "type-fest";
import type {
Attribute,
AwaitBlock,
Block,
ClassDirective,
Comment,
Component,
ConstTag,
Css,
Directive,
EachBlock,
ElementLike,
ExpressionTag,
Fragment,
IfBlock,
KeyBlock,
Root,
Script,
SnippetBlock,
SpreadAttribute,
StyleDirective,
SvelteNode,
Tag,
TemplateNode,
Text,
} from "svelte/compiler";
export type {
Attribute,
AwaitBlock,
Block,
ClassDirective,
Comment,
Component,
ConstTag,
Css,
Directive,
EachBlock,
ElementLike,
ExpressionTag,
Fragment,
IfBlock,
KeyBlock,
Root,
Script,
SnippetBlock,
SpreadAttribute,
StyleDirective,
SvelteNode,
Tag,
TemplateNode,
Text,
};
export type SupportedSvelteNode = TemplateNode | Script | Css.Node | Fragment;
export type AttributeLike = Attribute | SpreadAttribute | Directive;
export const ATTRIBUTE_LIKE_NODE_NAMES = new Set([
"AnimateDirective",
"Attribute",
"BindDirective",
"ClassDirective",
"LetDirective",
"OnDirective",
"SpreadAttribute",
"StyleDirective",
"TransitionDirective",
"UseDirective",
] as const);
export type AttributeLikeNodeName = IterableElement<typeof ATTRIBUTE_LIKE_NODE_NAMES>;
export const is_attribute_like_node = (node: SvelteNode): node is AttributeLike =>
ATTRIBUTE_LIKE_NODE_NAMES.has(node.type);
export const BLOCK_NODE_NAMES = new Set([
"AwaitBlock",
"Block",
"EachBlock",
"IfBlock",
"KeyBlock",
"SnippetBlock",
] as const);
export type BlockNodeName = IterableElement<typeof BLOCK_NODE_NAMES>;
export const is_block_node = (node: SvelteNode): node is Block => BLOCK_NODE_NAMES.has(node.type);
export const CSS_AST_NODE_NAMES = new Set([
"Atrule",
"AttributeSelector",
"Block",
"ClassSelector",
"Combinator",
"ComplexSelector",
"Declaration",
"IdSelector",
"NestingSelector",
"Nth",
"Percentage",
"PseudoClassSelector",
"PseudoElementSelector",
"RelativeSelector",
"Rule",
"SelectorList",
"StyleSheet",
"TypeSelector",
] as const);
export type CssASTNodeName = IterableElement<typeof CSS_AST_NODE_NAMES>;
export const is_css_node = (node: SvelteNode): node is Css.Node => CSS_AST_NODE_NAMES.has(node.type);
export const ELEMENT_LIKE_NODE_NAMES = new Set([
"Component",
"TitleElement",
"SlotElement",
"RegularElement",
"SvelteBody",
"SvelteComponent",
"SvelteDocument",
"SvelteElement",
"SvelteFragment",
"SvelteHead",
"SvelteOptionsRaw",
"SvelteSelf",
"SvelteWindow",
] as const);
export type ElementLikeNodeName = IterableElement<typeof ELEMENT_LIKE_NODE_NAMES>;
export const is_element_like_node = (node: SvelteNode): node is ElementLike => ELEMENT_LIKE_NODE_NAMES.has(node.type);
export type StandardNode = Comment | Text;
export const STANDARD_NODE_NAMES = new Set([
//
"Comment",
"Text",
] as const);
export type StandardNodeName = IterableElement<typeof STANDARD_NODE_NAMES>;
export const is_standard_node = (node: SvelteNode): node is StandardNode => STANDARD_NODE_NAMES.has(node.type);
export const TAG_NODE_NAMES = new Set([
//
"ExpressionTag",
"HtmlTag",
"ConstTag",
"DebugTag",
"RenderTag",
] as const);
export type TagNodeName = IterableElement<typeof TAG_NODE_NAMES>;
export const is_tag_node = (node: SvelteNode): node is Tag => TAG_NODE_NAMES.has(node.type);
export const is_template_node = (node: SvelteNode): node is TemplateNode =>
node.type === "Root" ||
node.type === "Fragment" ||
is_attribute_like_node(node) ||
is_block_node(node) ||
is_css_node(node) ||
is_element_like_node(node) ||
is_standard_node(node) ||
is_tag_node(node);
export type SupportedSvelteNodeName =
| "Root"
| "Script"
| AttributeLikeNodeName
| BlockNodeName
| CssASTNodeName
| ElementLikeNodeName
| StandardNodeName
| TagNodeName;
export const is_supported_svelte_node = (node: SvelteNode | Script): node is SupportedSvelteNode =>
node.type === "Script" || is_template_node(node);