@herb-tools/core 0.8.10 → 0.9.1
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/dist/herb-core.browser.js +22728 -320
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +22815 -321
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +22728 -320
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +22815 -321
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/ast-utils.d.ts +185 -4
- package/dist/types/backend.d.ts +6 -6
- package/dist/types/diagnostic.d.ts +6 -0
- package/dist/types/errors.d.ts +390 -25
- package/dist/types/extract-ruby-options.d.ts +6 -0
- package/dist/types/herb-backend.d.ts +15 -7
- package/dist/types/index.d.ts +2 -0
- package/dist/types/node-type-guards.d.ts +113 -32
- package/dist/types/nodes.d.ts +465 -49
- package/dist/types/parse-result.d.ts +7 -1
- package/dist/types/parser-options.d.ts +33 -2
- package/dist/types/prism/index.d.ts +28 -0
- package/dist/types/prism/inspect.d.ts +3 -0
- package/dist/types/util.d.ts +0 -1
- package/dist/types/visitor.d.ts +19 -1
- package/package.json +4 -1
- package/src/ast-utils.ts +564 -8
- package/src/backend.ts +7 -7
- package/src/diagnostic.ts +7 -0
- package/src/errors.ts +1221 -76
- package/src/extract-ruby-options.ts +11 -0
- package/src/herb-backend.ts +30 -15
- package/src/index.ts +2 -0
- package/src/node-type-guards.ts +281 -33
- package/src/nodes.ts +1309 -100
- package/src/parse-result.ts +11 -0
- package/src/parser-options.ts +62 -2
- package/src/prism/index.ts +44 -0
- package/src/prism/inspect.ts +118 -0
- package/src/util.ts +0 -12
- package/src/visitor.ts +66 -1
package/src/node-type-guards.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
2
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.
|
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.1/templates/javascript/packages/core/src/node-type-guards.ts.erb
|
|
3
3
|
|
|
4
4
|
import type { Node, NodeType, ERBNode } from "./nodes.js"
|
|
5
5
|
|
|
@@ -10,11 +10,18 @@ import {
|
|
|
10
10
|
DocumentNode,
|
|
11
11
|
LiteralNode,
|
|
12
12
|
HTMLOpenTagNode,
|
|
13
|
+
HTMLConditionalOpenTagNode,
|
|
13
14
|
HTMLCloseTagNode,
|
|
15
|
+
HTMLOmittedCloseTagNode,
|
|
16
|
+
HTMLVirtualCloseTagNode,
|
|
14
17
|
HTMLElementNode,
|
|
18
|
+
HTMLConditionalElementNode,
|
|
15
19
|
HTMLAttributeValueNode,
|
|
16
20
|
HTMLAttributeNameNode,
|
|
17
21
|
HTMLAttributeNode,
|
|
22
|
+
RubyLiteralNode,
|
|
23
|
+
RubyHTMLAttributesSplatNode,
|
|
24
|
+
ERBOpenTagNode,
|
|
18
25
|
HTMLTextNode,
|
|
19
26
|
HTMLCommentNode,
|
|
20
27
|
HTMLDoctypeNode,
|
|
@@ -36,6 +43,8 @@ import {
|
|
|
36
43
|
ERBEnsureNode,
|
|
37
44
|
ERBBeginNode,
|
|
38
45
|
ERBUnlessNode,
|
|
46
|
+
RubyRenderLocalNode,
|
|
47
|
+
ERBRenderNode,
|
|
39
48
|
ERBYieldNode,
|
|
40
49
|
ERBInNode,
|
|
41
50
|
} from "./nodes.js"
|
|
@@ -50,217 +59,360 @@ import {
|
|
|
50
59
|
/**
|
|
51
60
|
* Checks if a node is a DocumentNode
|
|
52
61
|
*/
|
|
53
|
-
export function isDocumentNode(node: Node): node is DocumentNode {
|
|
62
|
+
export function isDocumentNode(node: Node | null | undefined): node is DocumentNode {
|
|
63
|
+
if (!node) return false
|
|
64
|
+
|
|
54
65
|
return node instanceof DocumentNode || node.type === "AST_DOCUMENT_NODE" || (node.constructor as any).type === "AST_DOCUMENT_NODE"
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
/**
|
|
58
69
|
* Checks if a node is a LiteralNode
|
|
59
70
|
*/
|
|
60
|
-
export function isLiteralNode(node: Node): node is LiteralNode {
|
|
71
|
+
export function isLiteralNode(node: Node | null | undefined): node is LiteralNode {
|
|
72
|
+
if (!node) return false
|
|
73
|
+
|
|
61
74
|
return node instanceof LiteralNode || node.type === "AST_LITERAL_NODE" || (node.constructor as any).type === "AST_LITERAL_NODE"
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
/**
|
|
65
78
|
* Checks if a node is a HTMLOpenTagNode
|
|
66
79
|
*/
|
|
67
|
-
export function isHTMLOpenTagNode(node: Node): node is HTMLOpenTagNode {
|
|
80
|
+
export function isHTMLOpenTagNode(node: Node | null | undefined): node is HTMLOpenTagNode {
|
|
81
|
+
if (!node) return false
|
|
82
|
+
|
|
68
83
|
return node instanceof HTMLOpenTagNode || node.type === "AST_HTML_OPEN_TAG_NODE" || (node.constructor as any).type === "AST_HTML_OPEN_TAG_NODE"
|
|
69
84
|
}
|
|
70
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Checks if a node is a HTMLConditionalOpenTagNode
|
|
88
|
+
*/
|
|
89
|
+
export function isHTMLConditionalOpenTagNode(node: Node | null | undefined): node is HTMLConditionalOpenTagNode {
|
|
90
|
+
if (!node) return false
|
|
91
|
+
|
|
92
|
+
return node instanceof HTMLConditionalOpenTagNode || node.type === "AST_HTML_CONDITIONAL_OPEN_TAG_NODE" || (node.constructor as any).type === "AST_HTML_CONDITIONAL_OPEN_TAG_NODE"
|
|
93
|
+
}
|
|
94
|
+
|
|
71
95
|
/**
|
|
72
96
|
* Checks if a node is a HTMLCloseTagNode
|
|
73
97
|
*/
|
|
74
|
-
export function isHTMLCloseTagNode(node: Node): node is HTMLCloseTagNode {
|
|
98
|
+
export function isHTMLCloseTagNode(node: Node | null | undefined): node is HTMLCloseTagNode {
|
|
99
|
+
if (!node) return false
|
|
100
|
+
|
|
75
101
|
return node instanceof HTMLCloseTagNode || node.type === "AST_HTML_CLOSE_TAG_NODE" || (node.constructor as any).type === "AST_HTML_CLOSE_TAG_NODE"
|
|
76
102
|
}
|
|
77
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Checks if a node is a HTMLOmittedCloseTagNode
|
|
106
|
+
*/
|
|
107
|
+
export function isHTMLOmittedCloseTagNode(node: Node | null | undefined): node is HTMLOmittedCloseTagNode {
|
|
108
|
+
if (!node) return false
|
|
109
|
+
|
|
110
|
+
return node instanceof HTMLOmittedCloseTagNode || node.type === "AST_HTML_OMITTED_CLOSE_TAG_NODE" || (node.constructor as any).type === "AST_HTML_OMITTED_CLOSE_TAG_NODE"
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Checks if a node is a HTMLVirtualCloseTagNode
|
|
115
|
+
*/
|
|
116
|
+
export function isHTMLVirtualCloseTagNode(node: Node | null | undefined): node is HTMLVirtualCloseTagNode {
|
|
117
|
+
if (!node) return false
|
|
118
|
+
|
|
119
|
+
return node instanceof HTMLVirtualCloseTagNode || node.type === "AST_HTML_VIRTUAL_CLOSE_TAG_NODE" || (node.constructor as any).type === "AST_HTML_VIRTUAL_CLOSE_TAG_NODE"
|
|
120
|
+
}
|
|
121
|
+
|
|
78
122
|
/**
|
|
79
123
|
* Checks if a node is a HTMLElementNode
|
|
80
124
|
*/
|
|
81
|
-
export function isHTMLElementNode(node: Node): node is HTMLElementNode {
|
|
125
|
+
export function isHTMLElementNode(node: Node | null | undefined): node is HTMLElementNode {
|
|
126
|
+
if (!node) return false
|
|
127
|
+
|
|
82
128
|
return node instanceof HTMLElementNode || node.type === "AST_HTML_ELEMENT_NODE" || (node.constructor as any).type === "AST_HTML_ELEMENT_NODE"
|
|
83
129
|
}
|
|
84
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Checks if a node is a HTMLConditionalElementNode
|
|
133
|
+
*/
|
|
134
|
+
export function isHTMLConditionalElementNode(node: Node | null | undefined): node is HTMLConditionalElementNode {
|
|
135
|
+
if (!node) return false
|
|
136
|
+
|
|
137
|
+
return node instanceof HTMLConditionalElementNode || node.type === "AST_HTML_CONDITIONAL_ELEMENT_NODE" || (node.constructor as any).type === "AST_HTML_CONDITIONAL_ELEMENT_NODE"
|
|
138
|
+
}
|
|
139
|
+
|
|
85
140
|
/**
|
|
86
141
|
* Checks if a node is a HTMLAttributeValueNode
|
|
87
142
|
*/
|
|
88
|
-
export function isHTMLAttributeValueNode(node: Node): node is HTMLAttributeValueNode {
|
|
143
|
+
export function isHTMLAttributeValueNode(node: Node | null | undefined): node is HTMLAttributeValueNode {
|
|
144
|
+
if (!node) return false
|
|
145
|
+
|
|
89
146
|
return node instanceof HTMLAttributeValueNode || node.type === "AST_HTML_ATTRIBUTE_VALUE_NODE" || (node.constructor as any).type === "AST_HTML_ATTRIBUTE_VALUE_NODE"
|
|
90
147
|
}
|
|
91
148
|
|
|
92
149
|
/**
|
|
93
150
|
* Checks if a node is a HTMLAttributeNameNode
|
|
94
151
|
*/
|
|
95
|
-
export function isHTMLAttributeNameNode(node: Node): node is HTMLAttributeNameNode {
|
|
152
|
+
export function isHTMLAttributeNameNode(node: Node | null | undefined): node is HTMLAttributeNameNode {
|
|
153
|
+
if (!node) return false
|
|
154
|
+
|
|
96
155
|
return node instanceof HTMLAttributeNameNode || node.type === "AST_HTML_ATTRIBUTE_NAME_NODE" || (node.constructor as any).type === "AST_HTML_ATTRIBUTE_NAME_NODE"
|
|
97
156
|
}
|
|
98
157
|
|
|
99
158
|
/**
|
|
100
159
|
* Checks if a node is a HTMLAttributeNode
|
|
101
160
|
*/
|
|
102
|
-
export function isHTMLAttributeNode(node: Node): node is HTMLAttributeNode {
|
|
161
|
+
export function isHTMLAttributeNode(node: Node | null | undefined): node is HTMLAttributeNode {
|
|
162
|
+
if (!node) return false
|
|
163
|
+
|
|
103
164
|
return node instanceof HTMLAttributeNode || node.type === "AST_HTML_ATTRIBUTE_NODE" || (node.constructor as any).type === "AST_HTML_ATTRIBUTE_NODE"
|
|
104
165
|
}
|
|
105
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Checks if a node is a RubyLiteralNode
|
|
169
|
+
*/
|
|
170
|
+
export function isRubyLiteralNode(node: Node | null | undefined): node is RubyLiteralNode {
|
|
171
|
+
if (!node) return false
|
|
172
|
+
|
|
173
|
+
return node instanceof RubyLiteralNode || node.type === "AST_RUBY_LITERAL_NODE" || (node.constructor as any).type === "AST_RUBY_LITERAL_NODE"
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Checks if a node is a RubyHTMLAttributesSplatNode
|
|
178
|
+
*/
|
|
179
|
+
export function isRubyHTMLAttributesSplatNode(node: Node | null | undefined): node is RubyHTMLAttributesSplatNode {
|
|
180
|
+
if (!node) return false
|
|
181
|
+
|
|
182
|
+
return node instanceof RubyHTMLAttributesSplatNode || node.type === "AST_RUBY_HTML_ATTRIBUTES_SPLAT_NODE" || (node.constructor as any).type === "AST_RUBY_HTML_ATTRIBUTES_SPLAT_NODE"
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Checks if a node is a ERBOpenTagNode
|
|
187
|
+
*/
|
|
188
|
+
export function isERBOpenTagNode(node: Node | null | undefined): node is ERBOpenTagNode {
|
|
189
|
+
if (!node) return false
|
|
190
|
+
|
|
191
|
+
return node instanceof ERBOpenTagNode || node.type === "AST_ERB_OPEN_TAG_NODE" || (node.constructor as any).type === "AST_ERB_OPEN_TAG_NODE"
|
|
192
|
+
}
|
|
193
|
+
|
|
106
194
|
/**
|
|
107
195
|
* Checks if a node is a HTMLTextNode
|
|
108
196
|
*/
|
|
109
|
-
export function isHTMLTextNode(node: Node): node is HTMLTextNode {
|
|
197
|
+
export function isHTMLTextNode(node: Node | null | undefined): node is HTMLTextNode {
|
|
198
|
+
if (!node) return false
|
|
199
|
+
|
|
110
200
|
return node instanceof HTMLTextNode || node.type === "AST_HTML_TEXT_NODE" || (node.constructor as any).type === "AST_HTML_TEXT_NODE"
|
|
111
201
|
}
|
|
112
202
|
|
|
113
203
|
/**
|
|
114
204
|
* Checks if a node is a HTMLCommentNode
|
|
115
205
|
*/
|
|
116
|
-
export function isHTMLCommentNode(node: Node): node is HTMLCommentNode {
|
|
206
|
+
export function isHTMLCommentNode(node: Node | null | undefined): node is HTMLCommentNode {
|
|
207
|
+
if (!node) return false
|
|
208
|
+
|
|
117
209
|
return node instanceof HTMLCommentNode || node.type === "AST_HTML_COMMENT_NODE" || (node.constructor as any).type === "AST_HTML_COMMENT_NODE"
|
|
118
210
|
}
|
|
119
211
|
|
|
120
212
|
/**
|
|
121
213
|
* Checks if a node is a HTMLDoctypeNode
|
|
122
214
|
*/
|
|
123
|
-
export function isHTMLDoctypeNode(node: Node): node is HTMLDoctypeNode {
|
|
215
|
+
export function isHTMLDoctypeNode(node: Node | null | undefined): node is HTMLDoctypeNode {
|
|
216
|
+
if (!node) return false
|
|
217
|
+
|
|
124
218
|
return node instanceof HTMLDoctypeNode || node.type === "AST_HTML_DOCTYPE_NODE" || (node.constructor as any).type === "AST_HTML_DOCTYPE_NODE"
|
|
125
219
|
}
|
|
126
220
|
|
|
127
221
|
/**
|
|
128
222
|
* Checks if a node is a XMLDeclarationNode
|
|
129
223
|
*/
|
|
130
|
-
export function isXMLDeclarationNode(node: Node): node is XMLDeclarationNode {
|
|
224
|
+
export function isXMLDeclarationNode(node: Node | null | undefined): node is XMLDeclarationNode {
|
|
225
|
+
if (!node) return false
|
|
226
|
+
|
|
131
227
|
return node instanceof XMLDeclarationNode || node.type === "AST_XML_DECLARATION_NODE" || (node.constructor as any).type === "AST_XML_DECLARATION_NODE"
|
|
132
228
|
}
|
|
133
229
|
|
|
134
230
|
/**
|
|
135
231
|
* Checks if a node is a CDATANode
|
|
136
232
|
*/
|
|
137
|
-
export function isCDATANode(node: Node): node is CDATANode {
|
|
233
|
+
export function isCDATANode(node: Node | null | undefined): node is CDATANode {
|
|
234
|
+
if (!node) return false
|
|
235
|
+
|
|
138
236
|
return node instanceof CDATANode || node.type === "AST_CDATA_NODE" || (node.constructor as any).type === "AST_CDATA_NODE"
|
|
139
237
|
}
|
|
140
238
|
|
|
141
239
|
/**
|
|
142
240
|
* Checks if a node is a WhitespaceNode
|
|
143
241
|
*/
|
|
144
|
-
export function isWhitespaceNode(node: Node): node is WhitespaceNode {
|
|
242
|
+
export function isWhitespaceNode(node: Node | null | undefined): node is WhitespaceNode {
|
|
243
|
+
if (!node) return false
|
|
244
|
+
|
|
145
245
|
return node instanceof WhitespaceNode || node.type === "AST_WHITESPACE_NODE" || (node.constructor as any).type === "AST_WHITESPACE_NODE"
|
|
146
246
|
}
|
|
147
247
|
|
|
148
248
|
/**
|
|
149
249
|
* Checks if a node is a ERBContentNode
|
|
150
250
|
*/
|
|
151
|
-
export function isERBContentNode(node: Node): node is ERBContentNode {
|
|
251
|
+
export function isERBContentNode(node: Node | null | undefined): node is ERBContentNode {
|
|
252
|
+
if (!node) return false
|
|
253
|
+
|
|
152
254
|
return node instanceof ERBContentNode || node.type === "AST_ERB_CONTENT_NODE" || (node.constructor as any).type === "AST_ERB_CONTENT_NODE"
|
|
153
255
|
}
|
|
154
256
|
|
|
155
257
|
/**
|
|
156
258
|
* Checks if a node is a ERBEndNode
|
|
157
259
|
*/
|
|
158
|
-
export function isERBEndNode(node: Node): node is ERBEndNode {
|
|
260
|
+
export function isERBEndNode(node: Node | null | undefined): node is ERBEndNode {
|
|
261
|
+
if (!node) return false
|
|
262
|
+
|
|
159
263
|
return node instanceof ERBEndNode || node.type === "AST_ERB_END_NODE" || (node.constructor as any).type === "AST_ERB_END_NODE"
|
|
160
264
|
}
|
|
161
265
|
|
|
162
266
|
/**
|
|
163
267
|
* Checks if a node is a ERBElseNode
|
|
164
268
|
*/
|
|
165
|
-
export function isERBElseNode(node: Node): node is ERBElseNode {
|
|
269
|
+
export function isERBElseNode(node: Node | null | undefined): node is ERBElseNode {
|
|
270
|
+
if (!node) return false
|
|
271
|
+
|
|
166
272
|
return node instanceof ERBElseNode || node.type === "AST_ERB_ELSE_NODE" || (node.constructor as any).type === "AST_ERB_ELSE_NODE"
|
|
167
273
|
}
|
|
168
274
|
|
|
169
275
|
/**
|
|
170
276
|
* Checks if a node is a ERBIfNode
|
|
171
277
|
*/
|
|
172
|
-
export function isERBIfNode(node: Node): node is ERBIfNode {
|
|
278
|
+
export function isERBIfNode(node: Node | null | undefined): node is ERBIfNode {
|
|
279
|
+
if (!node) return false
|
|
280
|
+
|
|
173
281
|
return node instanceof ERBIfNode || node.type === "AST_ERB_IF_NODE" || (node.constructor as any).type === "AST_ERB_IF_NODE"
|
|
174
282
|
}
|
|
175
283
|
|
|
176
284
|
/**
|
|
177
285
|
* Checks if a node is a ERBBlockNode
|
|
178
286
|
*/
|
|
179
|
-
export function isERBBlockNode(node: Node): node is ERBBlockNode {
|
|
287
|
+
export function isERBBlockNode(node: Node | null | undefined): node is ERBBlockNode {
|
|
288
|
+
if (!node) return false
|
|
289
|
+
|
|
180
290
|
return node instanceof ERBBlockNode || node.type === "AST_ERB_BLOCK_NODE" || (node.constructor as any).type === "AST_ERB_BLOCK_NODE"
|
|
181
291
|
}
|
|
182
292
|
|
|
183
293
|
/**
|
|
184
294
|
* Checks if a node is a ERBWhenNode
|
|
185
295
|
*/
|
|
186
|
-
export function isERBWhenNode(node: Node): node is ERBWhenNode {
|
|
296
|
+
export function isERBWhenNode(node: Node | null | undefined): node is ERBWhenNode {
|
|
297
|
+
if (!node) return false
|
|
298
|
+
|
|
187
299
|
return node instanceof ERBWhenNode || node.type === "AST_ERB_WHEN_NODE" || (node.constructor as any).type === "AST_ERB_WHEN_NODE"
|
|
188
300
|
}
|
|
189
301
|
|
|
190
302
|
/**
|
|
191
303
|
* Checks if a node is a ERBCaseNode
|
|
192
304
|
*/
|
|
193
|
-
export function isERBCaseNode(node: Node): node is ERBCaseNode {
|
|
305
|
+
export function isERBCaseNode(node: Node | null | undefined): node is ERBCaseNode {
|
|
306
|
+
if (!node) return false
|
|
307
|
+
|
|
194
308
|
return node instanceof ERBCaseNode || node.type === "AST_ERB_CASE_NODE" || (node.constructor as any).type === "AST_ERB_CASE_NODE"
|
|
195
309
|
}
|
|
196
310
|
|
|
197
311
|
/**
|
|
198
312
|
* Checks if a node is a ERBCaseMatchNode
|
|
199
313
|
*/
|
|
200
|
-
export function isERBCaseMatchNode(node: Node): node is ERBCaseMatchNode {
|
|
314
|
+
export function isERBCaseMatchNode(node: Node | null | undefined): node is ERBCaseMatchNode {
|
|
315
|
+
if (!node) return false
|
|
316
|
+
|
|
201
317
|
return node instanceof ERBCaseMatchNode || node.type === "AST_ERB_CASE_MATCH_NODE" || (node.constructor as any).type === "AST_ERB_CASE_MATCH_NODE"
|
|
202
318
|
}
|
|
203
319
|
|
|
204
320
|
/**
|
|
205
321
|
* Checks if a node is a ERBWhileNode
|
|
206
322
|
*/
|
|
207
|
-
export function isERBWhileNode(node: Node): node is ERBWhileNode {
|
|
323
|
+
export function isERBWhileNode(node: Node | null | undefined): node is ERBWhileNode {
|
|
324
|
+
if (!node) return false
|
|
325
|
+
|
|
208
326
|
return node instanceof ERBWhileNode || node.type === "AST_ERB_WHILE_NODE" || (node.constructor as any).type === "AST_ERB_WHILE_NODE"
|
|
209
327
|
}
|
|
210
328
|
|
|
211
329
|
/**
|
|
212
330
|
* Checks if a node is a ERBUntilNode
|
|
213
331
|
*/
|
|
214
|
-
export function isERBUntilNode(node: Node): node is ERBUntilNode {
|
|
332
|
+
export function isERBUntilNode(node: Node | null | undefined): node is ERBUntilNode {
|
|
333
|
+
if (!node) return false
|
|
334
|
+
|
|
215
335
|
return node instanceof ERBUntilNode || node.type === "AST_ERB_UNTIL_NODE" || (node.constructor as any).type === "AST_ERB_UNTIL_NODE"
|
|
216
336
|
}
|
|
217
337
|
|
|
218
338
|
/**
|
|
219
339
|
* Checks if a node is a ERBForNode
|
|
220
340
|
*/
|
|
221
|
-
export function isERBForNode(node: Node): node is ERBForNode {
|
|
341
|
+
export function isERBForNode(node: Node | null | undefined): node is ERBForNode {
|
|
342
|
+
if (!node) return false
|
|
343
|
+
|
|
222
344
|
return node instanceof ERBForNode || node.type === "AST_ERB_FOR_NODE" || (node.constructor as any).type === "AST_ERB_FOR_NODE"
|
|
223
345
|
}
|
|
224
346
|
|
|
225
347
|
/**
|
|
226
348
|
* Checks if a node is a ERBRescueNode
|
|
227
349
|
*/
|
|
228
|
-
export function isERBRescueNode(node: Node): node is ERBRescueNode {
|
|
350
|
+
export function isERBRescueNode(node: Node | null | undefined): node is ERBRescueNode {
|
|
351
|
+
if (!node) return false
|
|
352
|
+
|
|
229
353
|
return node instanceof ERBRescueNode || node.type === "AST_ERB_RESCUE_NODE" || (node.constructor as any).type === "AST_ERB_RESCUE_NODE"
|
|
230
354
|
}
|
|
231
355
|
|
|
232
356
|
/**
|
|
233
357
|
* Checks if a node is a ERBEnsureNode
|
|
234
358
|
*/
|
|
235
|
-
export function isERBEnsureNode(node: Node): node is ERBEnsureNode {
|
|
359
|
+
export function isERBEnsureNode(node: Node | null | undefined): node is ERBEnsureNode {
|
|
360
|
+
if (!node) return false
|
|
361
|
+
|
|
236
362
|
return node instanceof ERBEnsureNode || node.type === "AST_ERB_ENSURE_NODE" || (node.constructor as any).type === "AST_ERB_ENSURE_NODE"
|
|
237
363
|
}
|
|
238
364
|
|
|
239
365
|
/**
|
|
240
366
|
* Checks if a node is a ERBBeginNode
|
|
241
367
|
*/
|
|
242
|
-
export function isERBBeginNode(node: Node): node is ERBBeginNode {
|
|
368
|
+
export function isERBBeginNode(node: Node | null | undefined): node is ERBBeginNode {
|
|
369
|
+
if (!node) return false
|
|
370
|
+
|
|
243
371
|
return node instanceof ERBBeginNode || node.type === "AST_ERB_BEGIN_NODE" || (node.constructor as any).type === "AST_ERB_BEGIN_NODE"
|
|
244
372
|
}
|
|
245
373
|
|
|
246
374
|
/**
|
|
247
375
|
* Checks if a node is a ERBUnlessNode
|
|
248
376
|
*/
|
|
249
|
-
export function isERBUnlessNode(node: Node): node is ERBUnlessNode {
|
|
377
|
+
export function isERBUnlessNode(node: Node | null | undefined): node is ERBUnlessNode {
|
|
378
|
+
if (!node) return false
|
|
379
|
+
|
|
250
380
|
return node instanceof ERBUnlessNode || node.type === "AST_ERB_UNLESS_NODE" || (node.constructor as any).type === "AST_ERB_UNLESS_NODE"
|
|
251
381
|
}
|
|
252
382
|
|
|
383
|
+
/**
|
|
384
|
+
* Checks if a node is a RubyRenderLocalNode
|
|
385
|
+
*/
|
|
386
|
+
export function isRubyRenderLocalNode(node: Node | null | undefined): node is RubyRenderLocalNode {
|
|
387
|
+
if (!node) return false
|
|
388
|
+
|
|
389
|
+
return node instanceof RubyRenderLocalNode || node.type === "AST_RUBY_RENDER_LOCAL_NODE" || (node.constructor as any).type === "AST_RUBY_RENDER_LOCAL_NODE"
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Checks if a node is a ERBRenderNode
|
|
394
|
+
*/
|
|
395
|
+
export function isERBRenderNode(node: Node | null | undefined): node is ERBRenderNode {
|
|
396
|
+
if (!node) return false
|
|
397
|
+
|
|
398
|
+
return node instanceof ERBRenderNode || node.type === "AST_ERB_RENDER_NODE" || (node.constructor as any).type === "AST_ERB_RENDER_NODE"
|
|
399
|
+
}
|
|
400
|
+
|
|
253
401
|
/**
|
|
254
402
|
* Checks if a node is a ERBYieldNode
|
|
255
403
|
*/
|
|
256
|
-
export function isERBYieldNode(node: Node): node is ERBYieldNode {
|
|
404
|
+
export function isERBYieldNode(node: Node | null | undefined): node is ERBYieldNode {
|
|
405
|
+
if (!node) return false
|
|
406
|
+
|
|
257
407
|
return node instanceof ERBYieldNode || node.type === "AST_ERB_YIELD_NODE" || (node.constructor as any).type === "AST_ERB_YIELD_NODE"
|
|
258
408
|
}
|
|
259
409
|
|
|
260
410
|
/**
|
|
261
411
|
* Checks if a node is a ERBInNode
|
|
262
412
|
*/
|
|
263
|
-
export function isERBInNode(node: Node): node is ERBInNode {
|
|
413
|
+
export function isERBInNode(node: Node | null | undefined): node is ERBInNode {
|
|
414
|
+
if (!node) return false
|
|
415
|
+
|
|
264
416
|
return node instanceof ERBInNode || node.type === "AST_ERB_IN_NODE" || (node.constructor as any).type === "AST_ERB_IN_NODE"
|
|
265
417
|
}
|
|
266
418
|
|
|
@@ -273,8 +425,12 @@ export function isERBInNode(node: Node): node is ERBInNode {
|
|
|
273
425
|
*/
|
|
274
426
|
export function isHTMLNode(node: Node): boolean {
|
|
275
427
|
return isHTMLOpenTagNode(node) ||
|
|
428
|
+
isHTMLConditionalOpenTagNode(node) ||
|
|
276
429
|
isHTMLCloseTagNode(node) ||
|
|
430
|
+
isHTMLOmittedCloseTagNode(node) ||
|
|
431
|
+
isHTMLVirtualCloseTagNode(node) ||
|
|
277
432
|
isHTMLElementNode(node) ||
|
|
433
|
+
isHTMLConditionalElementNode(node) ||
|
|
278
434
|
isHTMLAttributeValueNode(node) ||
|
|
279
435
|
isHTMLAttributeNameNode(node) ||
|
|
280
436
|
isHTMLAttributeNode(node) ||
|
|
@@ -287,7 +443,8 @@ export function isHTMLNode(node: Node): boolean {
|
|
|
287
443
|
* Checks if a node is any ERB node type
|
|
288
444
|
*/
|
|
289
445
|
export function isERBNode(node: Node): node is ERBNode {
|
|
290
|
-
return
|
|
446
|
+
return isERBOpenTagNode(node) ||
|
|
447
|
+
isERBContentNode(node) ||
|
|
291
448
|
isERBEndNode(node) ||
|
|
292
449
|
isERBElseNode(node) ||
|
|
293
450
|
isERBIfNode(node) ||
|
|
@@ -302,6 +459,7 @@ export function isERBNode(node: Node): node is ERBNode {
|
|
|
302
459
|
isERBEnsureNode(node) ||
|
|
303
460
|
isERBBeginNode(node) ||
|
|
304
461
|
isERBUnlessNode(node) ||
|
|
462
|
+
isERBRenderNode(node) ||
|
|
305
463
|
isERBYieldNode(node) ||
|
|
306
464
|
isERBInNode(node)
|
|
307
465
|
}
|
|
@@ -320,11 +478,18 @@ export const NODE_TYPE_GUARDS = new Map<new (...args: any[]) => Node, (node: Nod
|
|
|
320
478
|
[DocumentNode, isDocumentNode],
|
|
321
479
|
[LiteralNode, isLiteralNode],
|
|
322
480
|
[HTMLOpenTagNode, isHTMLOpenTagNode],
|
|
481
|
+
[HTMLConditionalOpenTagNode, isHTMLConditionalOpenTagNode],
|
|
323
482
|
[HTMLCloseTagNode, isHTMLCloseTagNode],
|
|
483
|
+
[HTMLOmittedCloseTagNode, isHTMLOmittedCloseTagNode],
|
|
484
|
+
[HTMLVirtualCloseTagNode, isHTMLVirtualCloseTagNode],
|
|
324
485
|
[HTMLElementNode, isHTMLElementNode],
|
|
486
|
+
[HTMLConditionalElementNode, isHTMLConditionalElementNode],
|
|
325
487
|
[HTMLAttributeValueNode, isHTMLAttributeValueNode],
|
|
326
488
|
[HTMLAttributeNameNode, isHTMLAttributeNameNode],
|
|
327
489
|
[HTMLAttributeNode, isHTMLAttributeNode],
|
|
490
|
+
[RubyLiteralNode, isRubyLiteralNode],
|
|
491
|
+
[RubyHTMLAttributesSplatNode, isRubyHTMLAttributesSplatNode],
|
|
492
|
+
[ERBOpenTagNode, isERBOpenTagNode],
|
|
328
493
|
[HTMLTextNode, isHTMLTextNode],
|
|
329
494
|
[HTMLCommentNode, isHTMLCommentNode],
|
|
330
495
|
[HTMLDoctypeNode, isHTMLDoctypeNode],
|
|
@@ -346,6 +511,8 @@ export const NODE_TYPE_GUARDS = new Map<new (...args: any[]) => Node, (node: Nod
|
|
|
346
511
|
[ERBEnsureNode, isERBEnsureNode],
|
|
347
512
|
[ERBBeginNode, isERBBeginNode],
|
|
348
513
|
[ERBUnlessNode, isERBUnlessNode],
|
|
514
|
+
[RubyRenderLocalNode, isRubyRenderLocalNode],
|
|
515
|
+
[ERBRenderNode, isERBRenderNode],
|
|
349
516
|
[ERBYieldNode, isERBYieldNode],
|
|
350
517
|
[ERBInNode, isERBInNode],
|
|
351
518
|
])
|
|
@@ -364,11 +531,18 @@ export const AST_TYPE_GUARDS = new Map<NodeType, (node: Node) => boolean>([
|
|
|
364
531
|
["AST_DOCUMENT_NODE", isDocumentNode],
|
|
365
532
|
["AST_LITERAL_NODE", isLiteralNode],
|
|
366
533
|
["AST_HTML_OPEN_TAG_NODE", isHTMLOpenTagNode],
|
|
534
|
+
["AST_HTML_CONDITIONAL_OPEN_TAG_NODE", isHTMLConditionalOpenTagNode],
|
|
367
535
|
["AST_HTML_CLOSE_TAG_NODE", isHTMLCloseTagNode],
|
|
536
|
+
["AST_HTML_OMITTED_CLOSE_TAG_NODE", isHTMLOmittedCloseTagNode],
|
|
537
|
+
["AST_HTML_VIRTUAL_CLOSE_TAG_NODE", isHTMLVirtualCloseTagNode],
|
|
368
538
|
["AST_HTML_ELEMENT_NODE", isHTMLElementNode],
|
|
539
|
+
["AST_HTML_CONDITIONAL_ELEMENT_NODE", isHTMLConditionalElementNode],
|
|
369
540
|
["AST_HTML_ATTRIBUTE_VALUE_NODE", isHTMLAttributeValueNode],
|
|
370
541
|
["AST_HTML_ATTRIBUTE_NAME_NODE", isHTMLAttributeNameNode],
|
|
371
542
|
["AST_HTML_ATTRIBUTE_NODE", isHTMLAttributeNode],
|
|
543
|
+
["AST_RUBY_LITERAL_NODE", isRubyLiteralNode],
|
|
544
|
+
["AST_RUBY_HTML_ATTRIBUTES_SPLAT_NODE", isRubyHTMLAttributesSplatNode],
|
|
545
|
+
["AST_ERB_OPEN_TAG_NODE", isERBOpenTagNode],
|
|
372
546
|
["AST_HTML_TEXT_NODE", isHTMLTextNode],
|
|
373
547
|
["AST_HTML_COMMENT_NODE", isHTMLCommentNode],
|
|
374
548
|
["AST_HTML_DOCTYPE_NODE", isHTMLDoctypeNode],
|
|
@@ -390,6 +564,8 @@ export const AST_TYPE_GUARDS = new Map<NodeType, (node: Node) => boolean>([
|
|
|
390
564
|
["AST_ERB_ENSURE_NODE", isERBEnsureNode],
|
|
391
565
|
["AST_ERB_BEGIN_NODE", isERBBeginNode],
|
|
392
566
|
["AST_ERB_UNLESS_NODE", isERBUnlessNode],
|
|
567
|
+
["AST_RUBY_RENDER_LOCAL_NODE", isRubyRenderLocalNode],
|
|
568
|
+
["AST_ERB_RENDER_NODE", isERBRenderNode],
|
|
393
569
|
["AST_ERB_YIELD_NODE", isERBYieldNode],
|
|
394
570
|
["AST_ERB_IN_NODE", isERBInNode],
|
|
395
571
|
])
|
|
@@ -398,11 +574,18 @@ type NodeTypeToClass = {
|
|
|
398
574
|
"AST_DOCUMENT_NODE": DocumentNode;
|
|
399
575
|
"AST_LITERAL_NODE": LiteralNode;
|
|
400
576
|
"AST_HTML_OPEN_TAG_NODE": HTMLOpenTagNode;
|
|
577
|
+
"AST_HTML_CONDITIONAL_OPEN_TAG_NODE": HTMLConditionalOpenTagNode;
|
|
401
578
|
"AST_HTML_CLOSE_TAG_NODE": HTMLCloseTagNode;
|
|
579
|
+
"AST_HTML_OMITTED_CLOSE_TAG_NODE": HTMLOmittedCloseTagNode;
|
|
580
|
+
"AST_HTML_VIRTUAL_CLOSE_TAG_NODE": HTMLVirtualCloseTagNode;
|
|
402
581
|
"AST_HTML_ELEMENT_NODE": HTMLElementNode;
|
|
582
|
+
"AST_HTML_CONDITIONAL_ELEMENT_NODE": HTMLConditionalElementNode;
|
|
403
583
|
"AST_HTML_ATTRIBUTE_VALUE_NODE": HTMLAttributeValueNode;
|
|
404
584
|
"AST_HTML_ATTRIBUTE_NAME_NODE": HTMLAttributeNameNode;
|
|
405
585
|
"AST_HTML_ATTRIBUTE_NODE": HTMLAttributeNode;
|
|
586
|
+
"AST_RUBY_LITERAL_NODE": RubyLiteralNode;
|
|
587
|
+
"AST_RUBY_HTML_ATTRIBUTES_SPLAT_NODE": RubyHTMLAttributesSplatNode;
|
|
588
|
+
"AST_ERB_OPEN_TAG_NODE": ERBOpenTagNode;
|
|
406
589
|
"AST_HTML_TEXT_NODE": HTMLTextNode;
|
|
407
590
|
"AST_HTML_COMMENT_NODE": HTMLCommentNode;
|
|
408
591
|
"AST_HTML_DOCTYPE_NODE": HTMLDoctypeNode;
|
|
@@ -424,6 +607,8 @@ type NodeTypeToClass = {
|
|
|
424
607
|
"AST_ERB_ENSURE_NODE": ERBEnsureNode;
|
|
425
608
|
"AST_ERB_BEGIN_NODE": ERBBeginNode;
|
|
426
609
|
"AST_ERB_UNLESS_NODE": ERBUnlessNode;
|
|
610
|
+
"AST_RUBY_RENDER_LOCAL_NODE": RubyRenderLocalNode;
|
|
611
|
+
"AST_ERB_RENDER_NODE": ERBRenderNode;
|
|
427
612
|
"AST_ERB_YIELD_NODE": ERBYieldNode;
|
|
428
613
|
"AST_ERB_IN_NODE": ERBInNode;
|
|
429
614
|
}
|
|
@@ -680,6 +865,13 @@ export function filterHTMLOpenTagNodes(nodes: Node[]): HTMLOpenTagNode[] {
|
|
|
680
865
|
return nodes.filter(isHTMLOpenTagNode) as HTMLOpenTagNode[]
|
|
681
866
|
}
|
|
682
867
|
|
|
868
|
+
/**
|
|
869
|
+
* Filters an array of nodes to only include HTMLConditionalOpenTagNode nodes
|
|
870
|
+
*/
|
|
871
|
+
export function filterHTMLConditionalOpenTagNodes(nodes: Node[]): HTMLConditionalOpenTagNode[] {
|
|
872
|
+
return nodes.filter(isHTMLConditionalOpenTagNode) as HTMLConditionalOpenTagNode[]
|
|
873
|
+
}
|
|
874
|
+
|
|
683
875
|
/**
|
|
684
876
|
* Filters an array of nodes to only include HTMLCloseTagNode nodes
|
|
685
877
|
*/
|
|
@@ -687,6 +879,20 @@ export function filterHTMLCloseTagNodes(nodes: Node[]): HTMLCloseTagNode[] {
|
|
|
687
879
|
return nodes.filter(isHTMLCloseTagNode) as HTMLCloseTagNode[]
|
|
688
880
|
}
|
|
689
881
|
|
|
882
|
+
/**
|
|
883
|
+
* Filters an array of nodes to only include HTMLOmittedCloseTagNode nodes
|
|
884
|
+
*/
|
|
885
|
+
export function filterHTMLOmittedCloseTagNodes(nodes: Node[]): HTMLOmittedCloseTagNode[] {
|
|
886
|
+
return nodes.filter(isHTMLOmittedCloseTagNode) as HTMLOmittedCloseTagNode[]
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Filters an array of nodes to only include HTMLVirtualCloseTagNode nodes
|
|
891
|
+
*/
|
|
892
|
+
export function filterHTMLVirtualCloseTagNodes(nodes: Node[]): HTMLVirtualCloseTagNode[] {
|
|
893
|
+
return nodes.filter(isHTMLVirtualCloseTagNode) as HTMLVirtualCloseTagNode[]
|
|
894
|
+
}
|
|
895
|
+
|
|
690
896
|
/**
|
|
691
897
|
* Filters an array of nodes to only include HTMLElementNode nodes
|
|
692
898
|
*/
|
|
@@ -694,6 +900,13 @@ export function filterHTMLElementNodes(nodes: Node[]): HTMLElementNode[] {
|
|
|
694
900
|
return nodes.filter(isHTMLElementNode) as HTMLElementNode[]
|
|
695
901
|
}
|
|
696
902
|
|
|
903
|
+
/**
|
|
904
|
+
* Filters an array of nodes to only include HTMLConditionalElementNode nodes
|
|
905
|
+
*/
|
|
906
|
+
export function filterHTMLConditionalElementNodes(nodes: Node[]): HTMLConditionalElementNode[] {
|
|
907
|
+
return nodes.filter(isHTMLConditionalElementNode) as HTMLConditionalElementNode[]
|
|
908
|
+
}
|
|
909
|
+
|
|
697
910
|
/**
|
|
698
911
|
* Filters an array of nodes to only include HTMLAttributeValueNode nodes
|
|
699
912
|
*/
|
|
@@ -715,6 +928,27 @@ export function filterHTMLAttributeNodes(nodes: Node[]): HTMLAttributeNode[] {
|
|
|
715
928
|
return nodes.filter(isHTMLAttributeNode) as HTMLAttributeNode[]
|
|
716
929
|
}
|
|
717
930
|
|
|
931
|
+
/**
|
|
932
|
+
* Filters an array of nodes to only include RubyLiteralNode nodes
|
|
933
|
+
*/
|
|
934
|
+
export function filterRubyLiteralNodes(nodes: Node[]): RubyLiteralNode[] {
|
|
935
|
+
return nodes.filter(isRubyLiteralNode) as RubyLiteralNode[]
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Filters an array of nodes to only include RubyHTMLAttributesSplatNode nodes
|
|
940
|
+
*/
|
|
941
|
+
export function filterRubyHTMLAttributesSplatNodes(nodes: Node[]): RubyHTMLAttributesSplatNode[] {
|
|
942
|
+
return nodes.filter(isRubyHTMLAttributesSplatNode) as RubyHTMLAttributesSplatNode[]
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Filters an array of nodes to only include ERBOpenTagNode nodes
|
|
947
|
+
*/
|
|
948
|
+
export function filterERBOpenTagNodes(nodes: Node[]): ERBOpenTagNode[] {
|
|
949
|
+
return nodes.filter(isERBOpenTagNode) as ERBOpenTagNode[]
|
|
950
|
+
}
|
|
951
|
+
|
|
718
952
|
/**
|
|
719
953
|
* Filters an array of nodes to only include HTMLTextNode nodes
|
|
720
954
|
*/
|
|
@@ -862,6 +1096,20 @@ export function filterERBUnlessNodes(nodes: Node[]): ERBUnlessNode[] {
|
|
|
862
1096
|
return nodes.filter(isERBUnlessNode) as ERBUnlessNode[]
|
|
863
1097
|
}
|
|
864
1098
|
|
|
1099
|
+
/**
|
|
1100
|
+
* Filters an array of nodes to only include RubyRenderLocalNode nodes
|
|
1101
|
+
*/
|
|
1102
|
+
export function filterRubyRenderLocalNodes(nodes: Node[]): RubyRenderLocalNode[] {
|
|
1103
|
+
return nodes.filter(isRubyRenderLocalNode) as RubyRenderLocalNode[]
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* Filters an array of nodes to only include ERBRenderNode nodes
|
|
1108
|
+
*/
|
|
1109
|
+
export function filterERBRenderNodes(nodes: Node[]): ERBRenderNode[] {
|
|
1110
|
+
return nodes.filter(isERBRenderNode) as ERBRenderNode[]
|
|
1111
|
+
}
|
|
1112
|
+
|
|
865
1113
|
/**
|
|
866
1114
|
* Filters an array of nodes to only include ERBYieldNode nodes
|
|
867
1115
|
*/
|