@herb-tools/core 0.5.0 → 0.6.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/dist/herb-core.browser.js +1223 -432
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +1314 -432
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +1223 -432
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +1314 -432
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/ast-utils.d.ts +74 -0
- package/dist/types/backend.d.ts +2 -1
- package/dist/types/herb-backend.d.ts +3 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/node-type-guards.d.ts +434 -0
- package/dist/types/nodes.d.ts +149 -97
- package/dist/types/parser-options.d.ts +4 -0
- package/dist/types/visitor.d.ts +3 -2
- package/package.json +1 -1
- package/src/ast-utils.ts +191 -0
- package/src/backend.ts +2 -1
- package/src/errors.ts +1 -1
- package/src/herb-backend.ts +7 -2
- package/src/index.ts +3 -0
- package/src/node-type-guards.ts +876 -0
- package/src/nodes.ts +300 -251
- package/src/parser-options.ts +7 -0
- package/src/visitor.ts +11 -6
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { HTMLElementNode, HTMLOpenTagNode, HTMLCloseTagNode } from "./nodes.js";
|
|
2
|
+
import { Node, ERBContentNode, HTMLAttributeNameNode } from "./nodes.js";
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a node is an ERB output node (generates content: <%= %> or <%== %>)
|
|
5
|
+
*/
|
|
6
|
+
export declare function isERBOutputNode(node: Node): node is ERBContentNode;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if a node is a non-output ERB node (control flow: <% %>)
|
|
9
|
+
*/
|
|
10
|
+
export declare function isERBControlFlowNode(node: Node): node is ERBContentNode;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if an array of nodes contains any ERB content nodes
|
|
13
|
+
*/
|
|
14
|
+
export declare function hasERBContent(nodes: Node[]): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if an array of nodes contains any ERB output nodes (dynamic content)
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasERBOutput(nodes: Node[]): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts a static string from an array of literal nodes
|
|
21
|
+
* Returns null if any node is not a literal node
|
|
22
|
+
*/
|
|
23
|
+
export declare function getStaticStringFromNodes(nodes: Node[]): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Extracts static content from nodes, including mixed literal/ERB content
|
|
26
|
+
* Returns the concatenated literal content, or null if no literal nodes exist
|
|
27
|
+
*/
|
|
28
|
+
export declare function getStaticContentFromNodes(nodes: Node[]): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if nodes contain any literal content (for static validation)
|
|
31
|
+
*/
|
|
32
|
+
export declare function hasStaticContent(nodes: Node[]): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if nodes are effectively static (only literals and non-output ERB)
|
|
35
|
+
* Non-output ERB like <% if %> doesn't affect static validation
|
|
36
|
+
*/
|
|
37
|
+
export declare function isEffectivelyStatic(nodes: Node[]): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Gets static-validatable content from nodes (ignores control ERB, includes literals)
|
|
40
|
+
* Returns concatenated literal content for validation, or null if contains output ERB
|
|
41
|
+
*/
|
|
42
|
+
export declare function getValidatableStaticContent(nodes: Node[]): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Extracts a combined string from nodes, including ERB content
|
|
45
|
+
* For ERB nodes, includes the full tag syntax (e.g., "<%= foo %>")
|
|
46
|
+
* This is useful for debugging or displaying the full attribute name
|
|
47
|
+
*/
|
|
48
|
+
export declare function getCombinedStringFromNodes(nodes: Node[]): string;
|
|
49
|
+
/**
|
|
50
|
+
* Checks if an HTML attribute name node has a static (literal-only) name
|
|
51
|
+
*/
|
|
52
|
+
export declare function hasStaticAttributeName(attributeNameNode: HTMLAttributeNameNode): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if an HTML attribute name node has dynamic content (contains ERB)
|
|
55
|
+
*/
|
|
56
|
+
export declare function hasDynamicAttributeName(attributeNameNode: HTMLAttributeNameNode): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the static string value of an HTML attribute name node
|
|
59
|
+
* Returns null if the attribute name contains dynamic content (ERB)
|
|
60
|
+
*/
|
|
61
|
+
export declare function getStaticAttributeName(attributeNameNode: HTMLAttributeNameNode): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the combined string representation of an HTML attribute name node
|
|
64
|
+
* This includes both static and dynamic content, useful for debugging
|
|
65
|
+
*/
|
|
66
|
+
export declare function getCombinedAttributeName(attributeNameNode: HTMLAttributeNameNode): string;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the tag name of an HTML element node
|
|
69
|
+
*/
|
|
70
|
+
export declare function getTagName(node: HTMLElementNode | HTMLOpenTagNode | HTMLCloseTagNode): string;
|
|
71
|
+
/**
|
|
72
|
+
* Check if a node is a comment (HTML comment or ERB comment)
|
|
73
|
+
*/
|
|
74
|
+
export declare function isCommentNode(node: Node): boolean;
|
package/dist/types/backend.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { SerializedParseResult } from "./parse-result.js";
|
|
2
2
|
import type { SerializedLexResult } from "./lex-result.js";
|
|
3
|
+
import type { ParserOptions } from "./parser-options.js";
|
|
3
4
|
interface LibHerbBackendFunctions {
|
|
4
5
|
lex: (source: string) => SerializedLexResult;
|
|
5
6
|
lexFile: (path: string) => SerializedLexResult;
|
|
6
|
-
parse: (source: string) => SerializedParseResult;
|
|
7
|
+
parse: (source: string, options?: ParserOptions) => SerializedParseResult;
|
|
7
8
|
parseFile: (path: string) => SerializedParseResult;
|
|
8
9
|
extractRuby: (source: string) => string;
|
|
9
10
|
extractHTML: (source: string) => string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LexResult } from "./lex-result.js";
|
|
2
2
|
import { ParseResult } from "./parse-result.js";
|
|
3
3
|
import type { LibHerbBackend, BackendPromise } from "./backend.js";
|
|
4
|
+
import type { ParserOptions } from "./parser-options.js";
|
|
4
5
|
/**
|
|
5
6
|
* The main Herb parser interface, providing methods to lex and parse input.
|
|
6
7
|
*/
|
|
@@ -36,10 +37,11 @@ export declare abstract class HerbBackend {
|
|
|
36
37
|
/**
|
|
37
38
|
* Parses the given source string into a `ParseResult`.
|
|
38
39
|
* @param source - The source code to parse.
|
|
40
|
+
* @param options - Optional parsing options.
|
|
39
41
|
* @returns A `ParseResult` instance.
|
|
40
42
|
* @throws Error if the backend is not loaded.
|
|
41
43
|
*/
|
|
42
|
-
parse(source: string): ParseResult;
|
|
44
|
+
parse(source: string, options?: ParserOptions): ParseResult;
|
|
43
45
|
/**
|
|
44
46
|
* Parses a file.
|
|
45
47
|
* @param path - The file path to parse.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./ast-utils.js";
|
|
1
2
|
export * from "./backend.js";
|
|
2
3
|
export * from "./diagnostic.js";
|
|
3
4
|
export * from "./errors.js";
|
|
@@ -5,7 +6,9 @@ export * from "./herb-backend.js";
|
|
|
5
6
|
export * from "./lex-result.js";
|
|
6
7
|
export * from "./location.js";
|
|
7
8
|
export * from "./nodes.js";
|
|
9
|
+
export * from "./node-type-guards.js";
|
|
8
10
|
export * from "./parse-result.js";
|
|
11
|
+
export * from "./parser-options.js";
|
|
9
12
|
export * from "./position.js";
|
|
10
13
|
export * from "./range.js";
|
|
11
14
|
export * from "./result.js";
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import type { Node, NodeType, ERBNode } from "./nodes.js";
|
|
2
|
+
import { Token } from "./token.js";
|
|
3
|
+
import { ParseResult } from "./parse-result.js";
|
|
4
|
+
import { DocumentNode, LiteralNode, HTMLOpenTagNode, HTMLCloseTagNode, HTMLElementNode, HTMLAttributeValueNode, HTMLAttributeNameNode, HTMLAttributeNode, HTMLTextNode, HTMLCommentNode, HTMLDoctypeNode, XMLDeclarationNode, CDATANode, WhitespaceNode, ERBContentNode, ERBEndNode, ERBElseNode, ERBIfNode, ERBBlockNode, ERBWhenNode, ERBCaseNode, ERBCaseMatchNode, ERBWhileNode, ERBUntilNode, ERBForNode, ERBRescueNode, ERBEnsureNode, ERBBeginNode, ERBUnlessNode, ERBYieldNode, ERBInNode } from "./nodes.js";
|
|
5
|
+
/**
|
|
6
|
+
* Type guard functions for AST nodes.
|
|
7
|
+
* These functions provide type checking by combining both instanceof
|
|
8
|
+
* checks and type string comparisons for maximum reliability across different
|
|
9
|
+
* runtime scenarios (e.g., serialized/deserialized nodes).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a node is a DocumentNode
|
|
13
|
+
*/
|
|
14
|
+
export declare function isDocumentNode(node: Node): node is DocumentNode;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if a node is a LiteralNode
|
|
17
|
+
*/
|
|
18
|
+
export declare function isLiteralNode(node: Node): node is LiteralNode;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a node is a HTMLOpenTagNode
|
|
21
|
+
*/
|
|
22
|
+
export declare function isHTMLOpenTagNode(node: Node): node is HTMLOpenTagNode;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a node is a HTMLCloseTagNode
|
|
25
|
+
*/
|
|
26
|
+
export declare function isHTMLCloseTagNode(node: Node): node is HTMLCloseTagNode;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a node is a HTMLElementNode
|
|
29
|
+
*/
|
|
30
|
+
export declare function isHTMLElementNode(node: Node): node is HTMLElementNode;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if a node is a HTMLAttributeValueNode
|
|
33
|
+
*/
|
|
34
|
+
export declare function isHTMLAttributeValueNode(node: Node): node is HTMLAttributeValueNode;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a node is a HTMLAttributeNameNode
|
|
37
|
+
*/
|
|
38
|
+
export declare function isHTMLAttributeNameNode(node: Node): node is HTMLAttributeNameNode;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a node is a HTMLAttributeNode
|
|
41
|
+
*/
|
|
42
|
+
export declare function isHTMLAttributeNode(node: Node): node is HTMLAttributeNode;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a node is a HTMLTextNode
|
|
45
|
+
*/
|
|
46
|
+
export declare function isHTMLTextNode(node: Node): node is HTMLTextNode;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a node is a HTMLCommentNode
|
|
49
|
+
*/
|
|
50
|
+
export declare function isHTMLCommentNode(node: Node): node is HTMLCommentNode;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a node is a HTMLDoctypeNode
|
|
53
|
+
*/
|
|
54
|
+
export declare function isHTMLDoctypeNode(node: Node): node is HTMLDoctypeNode;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a node is a XMLDeclarationNode
|
|
57
|
+
*/
|
|
58
|
+
export declare function isXMLDeclarationNode(node: Node): node is XMLDeclarationNode;
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a node is a CDATANode
|
|
61
|
+
*/
|
|
62
|
+
export declare function isCDATANode(node: Node): node is CDATANode;
|
|
63
|
+
/**
|
|
64
|
+
* Checks if a node is a WhitespaceNode
|
|
65
|
+
*/
|
|
66
|
+
export declare function isWhitespaceNode(node: Node): node is WhitespaceNode;
|
|
67
|
+
/**
|
|
68
|
+
* Checks if a node is a ERBContentNode
|
|
69
|
+
*/
|
|
70
|
+
export declare function isERBContentNode(node: Node): node is ERBContentNode;
|
|
71
|
+
/**
|
|
72
|
+
* Checks if a node is a ERBEndNode
|
|
73
|
+
*/
|
|
74
|
+
export declare function isERBEndNode(node: Node): node is ERBEndNode;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if a node is a ERBElseNode
|
|
77
|
+
*/
|
|
78
|
+
export declare function isERBElseNode(node: Node): node is ERBElseNode;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if a node is a ERBIfNode
|
|
81
|
+
*/
|
|
82
|
+
export declare function isERBIfNode(node: Node): node is ERBIfNode;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if a node is a ERBBlockNode
|
|
85
|
+
*/
|
|
86
|
+
export declare function isERBBlockNode(node: Node): node is ERBBlockNode;
|
|
87
|
+
/**
|
|
88
|
+
* Checks if a node is a ERBWhenNode
|
|
89
|
+
*/
|
|
90
|
+
export declare function isERBWhenNode(node: Node): node is ERBWhenNode;
|
|
91
|
+
/**
|
|
92
|
+
* Checks if a node is a ERBCaseNode
|
|
93
|
+
*/
|
|
94
|
+
export declare function isERBCaseNode(node: Node): node is ERBCaseNode;
|
|
95
|
+
/**
|
|
96
|
+
* Checks if a node is a ERBCaseMatchNode
|
|
97
|
+
*/
|
|
98
|
+
export declare function isERBCaseMatchNode(node: Node): node is ERBCaseMatchNode;
|
|
99
|
+
/**
|
|
100
|
+
* Checks if a node is a ERBWhileNode
|
|
101
|
+
*/
|
|
102
|
+
export declare function isERBWhileNode(node: Node): node is ERBWhileNode;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if a node is a ERBUntilNode
|
|
105
|
+
*/
|
|
106
|
+
export declare function isERBUntilNode(node: Node): node is ERBUntilNode;
|
|
107
|
+
/**
|
|
108
|
+
* Checks if a node is a ERBForNode
|
|
109
|
+
*/
|
|
110
|
+
export declare function isERBForNode(node: Node): node is ERBForNode;
|
|
111
|
+
/**
|
|
112
|
+
* Checks if a node is a ERBRescueNode
|
|
113
|
+
*/
|
|
114
|
+
export declare function isERBRescueNode(node: Node): node is ERBRescueNode;
|
|
115
|
+
/**
|
|
116
|
+
* Checks if a node is a ERBEnsureNode
|
|
117
|
+
*/
|
|
118
|
+
export declare function isERBEnsureNode(node: Node): node is ERBEnsureNode;
|
|
119
|
+
/**
|
|
120
|
+
* Checks if a node is a ERBBeginNode
|
|
121
|
+
*/
|
|
122
|
+
export declare function isERBBeginNode(node: Node): node is ERBBeginNode;
|
|
123
|
+
/**
|
|
124
|
+
* Checks if a node is a ERBUnlessNode
|
|
125
|
+
*/
|
|
126
|
+
export declare function isERBUnlessNode(node: Node): node is ERBUnlessNode;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if a node is a ERBYieldNode
|
|
129
|
+
*/
|
|
130
|
+
export declare function isERBYieldNode(node: Node): node is ERBYieldNode;
|
|
131
|
+
/**
|
|
132
|
+
* Checks if a node is a ERBInNode
|
|
133
|
+
*/
|
|
134
|
+
export declare function isERBInNode(node: Node): node is ERBInNode;
|
|
135
|
+
/**
|
|
136
|
+
* Convenience type guards for common node categories
|
|
137
|
+
*/
|
|
138
|
+
/**
|
|
139
|
+
* Checks if a node is any HTML node type
|
|
140
|
+
*/
|
|
141
|
+
export declare function isHTMLNode(node: Node): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Checks if a node is any ERB node type
|
|
144
|
+
*/
|
|
145
|
+
export declare function isERBNode(node: Node): node is ERBNode;
|
|
146
|
+
/**
|
|
147
|
+
* Map of node classes to their corresponding type guard functions
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* const guard = NODE_TYPE_GUARDS[HTMLTextNode]
|
|
151
|
+
*
|
|
152
|
+
* if (guard(node)) {
|
|
153
|
+
* // node is HTMLTextNode
|
|
154
|
+
* }
|
|
155
|
+
*/
|
|
156
|
+
export declare const NODE_TYPE_GUARDS: Map<new (...args: any[]) => Node, (node: Node) => boolean>;
|
|
157
|
+
/**
|
|
158
|
+
* Map of AST node type strings to their corresponding type guard functions
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* const guard = AST_TYPE_GUARDS["AST_HTML_TEXT_NODE"]
|
|
162
|
+
*
|
|
163
|
+
* if (guard(node)) {
|
|
164
|
+
* // node is HTMLTextNode
|
|
165
|
+
* }
|
|
166
|
+
*/
|
|
167
|
+
export declare const AST_TYPE_GUARDS: Map<string, (node: Node) => boolean>;
|
|
168
|
+
type NodeTypeToClass = {
|
|
169
|
+
"AST_DOCUMENT_NODE": DocumentNode;
|
|
170
|
+
"AST_LITERAL_NODE": LiteralNode;
|
|
171
|
+
"AST_HTML_OPEN_TAG_NODE": HTMLOpenTagNode;
|
|
172
|
+
"AST_HTML_CLOSE_TAG_NODE": HTMLCloseTagNode;
|
|
173
|
+
"AST_HTML_ELEMENT_NODE": HTMLElementNode;
|
|
174
|
+
"AST_HTML_ATTRIBUTE_VALUE_NODE": HTMLAttributeValueNode;
|
|
175
|
+
"AST_HTML_ATTRIBUTE_NAME_NODE": HTMLAttributeNameNode;
|
|
176
|
+
"AST_HTML_ATTRIBUTE_NODE": HTMLAttributeNode;
|
|
177
|
+
"AST_HTML_TEXT_NODE": HTMLTextNode;
|
|
178
|
+
"AST_HTML_COMMENT_NODE": HTMLCommentNode;
|
|
179
|
+
"AST_HTML_DOCTYPE_NODE": HTMLDoctypeNode;
|
|
180
|
+
"AST_XML_DECLARATION_NODE": XMLDeclarationNode;
|
|
181
|
+
"AST_CDATA_NODE": CDATANode;
|
|
182
|
+
"AST_WHITESPACE_NODE": WhitespaceNode;
|
|
183
|
+
"AST_ERB_CONTENT_NODE": ERBContentNode;
|
|
184
|
+
"AST_ERB_END_NODE": ERBEndNode;
|
|
185
|
+
"AST_ERB_ELSE_NODE": ERBElseNode;
|
|
186
|
+
"AST_ERB_IF_NODE": ERBIfNode;
|
|
187
|
+
"AST_ERB_BLOCK_NODE": ERBBlockNode;
|
|
188
|
+
"AST_ERB_WHEN_NODE": ERBWhenNode;
|
|
189
|
+
"AST_ERB_CASE_NODE": ERBCaseNode;
|
|
190
|
+
"AST_ERB_CASE_MATCH_NODE": ERBCaseMatchNode;
|
|
191
|
+
"AST_ERB_WHILE_NODE": ERBWhileNode;
|
|
192
|
+
"AST_ERB_UNTIL_NODE": ERBUntilNode;
|
|
193
|
+
"AST_ERB_FOR_NODE": ERBForNode;
|
|
194
|
+
"AST_ERB_RESCUE_NODE": ERBRescueNode;
|
|
195
|
+
"AST_ERB_ENSURE_NODE": ERBEnsureNode;
|
|
196
|
+
"AST_ERB_BEGIN_NODE": ERBBeginNode;
|
|
197
|
+
"AST_ERB_UNLESS_NODE": ERBUnlessNode;
|
|
198
|
+
"AST_ERB_YIELD_NODE": ERBYieldNode;
|
|
199
|
+
"AST_ERB_IN_NODE": ERBInNode;
|
|
200
|
+
};
|
|
201
|
+
type ClassToInstance<T> = T extends new (...args: any[]) => infer R ? R : never;
|
|
202
|
+
/**
|
|
203
|
+
* Checks if a node matches any of the provided type identifiers with proper type narrowing
|
|
204
|
+
* Supports AST type strings, node classes, or type guard functions
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* if (isAnyOf(node, "AST_HTML_TEXT_NODE", "AST_LITERAL_NODE")) {
|
|
208
|
+
* // node is narrowed to HTMLTextNode | LiteralNode
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* if (isAnyOf(node, HTMLTextNode, LiteralNode)) {
|
|
213
|
+
* // node is narrowed to HTMLTextNode | LiteralNode
|
|
214
|
+
* }
|
|
215
|
+
*/
|
|
216
|
+
export declare function isAnyOf(node: Node, ...types: Array<NodeType | (new (...args: any[]) => Node) | ((node: Node) => boolean)>): boolean;
|
|
217
|
+
/**
|
|
218
|
+
* Checks if a node does NOT match any of the provided type identifiers
|
|
219
|
+
* Supports AST type strings, node classes, or type guard functions
|
|
220
|
+
* This is the logical inverse of isAnyOf
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* if (isNoneOf(node, "AST_HTML_TEXT_NODE", "AST_LITERAL_NODE")) {
|
|
224
|
+
* // node is neither HTMLTextNode nor LiteralNode
|
|
225
|
+
* }
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* if (isNoneOf(node, HTMLTextNode, LiteralNode)) {
|
|
229
|
+
* // node is neither HTMLTextNode nor LiteralNode
|
|
230
|
+
* }
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* if (isNoneOf(node, isHTMLTextNode, isLiteralNode)) {
|
|
234
|
+
* // node is neither HTMLTextNode nor LiteralNode
|
|
235
|
+
* }
|
|
236
|
+
*/
|
|
237
|
+
export declare function isNoneOf(node: Node, ...types: Array<NodeType | (new (...args: any[]) => Node) | ((node: Node) => boolean)>): boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Checks if ALL nodes in an array match any of the provided type identifiers
|
|
240
|
+
* Supports AST type strings, node classes, or type guard functions
|
|
241
|
+
* Provides type narrowing for the array when true
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* if (areAllOfType(nodes, "AST_HTML_TEXT_NODE", "AST_LITERAL_NODE")) {
|
|
245
|
+
* // nodes is narrowed to (HTMLTextNode | LiteralNode)[]
|
|
246
|
+
* }
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* if (areAllOfType(nodes, HTMLTextNode, LiteralNode)) {
|
|
250
|
+
* // nodes is narrowed to (HTMLTextNode | LiteralNode)[]
|
|
251
|
+
* }
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* if (areAllOfType(nodes, isHTMLTextNode, isLiteralNode)) {
|
|
255
|
+
* // all nodes are either HTMLTextNode or LiteralNode
|
|
256
|
+
* }
|
|
257
|
+
*/
|
|
258
|
+
export declare function areAllOfType<T extends NodeType[]>(nodes: Node[], ...types: T): nodes is NodeTypeToClass[T[number]][];
|
|
259
|
+
export declare function areAllOfType<T extends (new (...args: any[]) => Node)[]>(nodes: Node[], ...types: T): nodes is ClassToInstance<T[number]>[];
|
|
260
|
+
export declare function areAllOfType(nodes: Node[], ...types: Array<(node: Node) => boolean>): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Filters an array of nodes to only include nodes matching any of the provided type identifiers
|
|
263
|
+
* Supports AST type strings, node classes, or type guard functions
|
|
264
|
+
* Returns a properly typed array of the filtered nodes
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* const filtered = filterNodes(nodes, "AST_HTML_TEXT_NODE", "AST_LITERAL_NODE")
|
|
268
|
+
* // filtered is typed as (HTMLTextNode | LiteralNode)[]
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* const filtered = filterNodes(nodes, HTMLTextNode, LiteralNode)
|
|
272
|
+
* // filtered is typed as (HTMLTextNode | LiteralNode)[]
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* const filtered = filterNodes(nodes, isHTMLTextNode, isLiteralNode)
|
|
276
|
+
* // filtered contains only HTMLTextNode or LiteralNode instances
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* const filtered = filterNodes(nodes, "AST_LITERAL_NODE", HTMLTextNode, isERBContentNode)
|
|
280
|
+
* // filtered contains only LiteralNode, HTMLTextNode, or ERBContentNode instances
|
|
281
|
+
*/
|
|
282
|
+
export declare function filterNodes<T extends NodeType[]>(nodes: Node[] | undefined | null, ...types: T): NodeTypeToClass[T[number]][];
|
|
283
|
+
export declare function filterNodes<T extends (new (...args: any[]) => Node)[]>(nodes: Node[] | undefined | null, ...types: T): ClassToInstance<T[number]>[];
|
|
284
|
+
export declare function filterNodes(nodes: Node[] | undefined | null, ...types: Array<(node: Node) => boolean>): Node[];
|
|
285
|
+
/**
|
|
286
|
+
* Checks if a node matches a specific type identifier with proper type narrowing
|
|
287
|
+
* Supports AST type strings or node classes
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* if (isNode(node, "AST_HTML_TEXT_NODE")) {
|
|
291
|
+
* // node is narrowed to HTMLTextNode
|
|
292
|
+
* }
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* if (isNode(node, HTMLTextNode)) {
|
|
296
|
+
* // node is narrowed to HTMLTextNode
|
|
297
|
+
* }
|
|
298
|
+
*/
|
|
299
|
+
export declare function isNode<T extends NodeType>(node: Node, type: T): node is NodeTypeToClass[T];
|
|
300
|
+
export declare function isNode<T extends new (...args: any[]) => Node>(node: Node, type: T): node is ClassToInstance<T>;
|
|
301
|
+
export declare function isToken(object: any): object is Token;
|
|
302
|
+
export declare function isParseResult(object: any): object is ParseResult;
|
|
303
|
+
/**
|
|
304
|
+
* Checks if a node has children (contains other nodes)
|
|
305
|
+
*/
|
|
306
|
+
export declare function hasChildren(node: Node): boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Filter functions for extracting specific node types from arrays
|
|
309
|
+
*/
|
|
310
|
+
/**
|
|
311
|
+
* Filters an array of nodes to only include DocumentNode nodes
|
|
312
|
+
*/
|
|
313
|
+
export declare function filterDocumentNodes(nodes: Node[]): DocumentNode[];
|
|
314
|
+
/**
|
|
315
|
+
* Filters an array of nodes to only include LiteralNode nodes
|
|
316
|
+
*/
|
|
317
|
+
export declare function filterLiteralNodes(nodes: Node[]): LiteralNode[];
|
|
318
|
+
/**
|
|
319
|
+
* Filters an array of nodes to only include HTMLOpenTagNode nodes
|
|
320
|
+
*/
|
|
321
|
+
export declare function filterHTMLOpenTagNodes(nodes: Node[]): HTMLOpenTagNode[];
|
|
322
|
+
/**
|
|
323
|
+
* Filters an array of nodes to only include HTMLCloseTagNode nodes
|
|
324
|
+
*/
|
|
325
|
+
export declare function filterHTMLCloseTagNodes(nodes: Node[]): HTMLCloseTagNode[];
|
|
326
|
+
/**
|
|
327
|
+
* Filters an array of nodes to only include HTMLElementNode nodes
|
|
328
|
+
*/
|
|
329
|
+
export declare function filterHTMLElementNodes(nodes: Node[]): HTMLElementNode[];
|
|
330
|
+
/**
|
|
331
|
+
* Filters an array of nodes to only include HTMLAttributeValueNode nodes
|
|
332
|
+
*/
|
|
333
|
+
export declare function filterHTMLAttributeValueNodes(nodes: Node[]): HTMLAttributeValueNode[];
|
|
334
|
+
/**
|
|
335
|
+
* Filters an array of nodes to only include HTMLAttributeNameNode nodes
|
|
336
|
+
*/
|
|
337
|
+
export declare function filterHTMLAttributeNameNodes(nodes: Node[]): HTMLAttributeNameNode[];
|
|
338
|
+
/**
|
|
339
|
+
* Filters an array of nodes to only include HTMLAttributeNode nodes
|
|
340
|
+
*/
|
|
341
|
+
export declare function filterHTMLAttributeNodes(nodes: Node[]): HTMLAttributeNode[];
|
|
342
|
+
/**
|
|
343
|
+
* Filters an array of nodes to only include HTMLTextNode nodes
|
|
344
|
+
*/
|
|
345
|
+
export declare function filterHTMLTextNodes(nodes: Node[]): HTMLTextNode[];
|
|
346
|
+
/**
|
|
347
|
+
* Filters an array of nodes to only include HTMLCommentNode nodes
|
|
348
|
+
*/
|
|
349
|
+
export declare function filterHTMLCommentNodes(nodes: Node[]): HTMLCommentNode[];
|
|
350
|
+
/**
|
|
351
|
+
* Filters an array of nodes to only include HTMLDoctypeNode nodes
|
|
352
|
+
*/
|
|
353
|
+
export declare function filterHTMLDoctypeNodes(nodes: Node[]): HTMLDoctypeNode[];
|
|
354
|
+
/**
|
|
355
|
+
* Filters an array of nodes to only include XMLDeclarationNode nodes
|
|
356
|
+
*/
|
|
357
|
+
export declare function filterXMLDeclarationNodes(nodes: Node[]): XMLDeclarationNode[];
|
|
358
|
+
/**
|
|
359
|
+
* Filters an array of nodes to only include CDATANode nodes
|
|
360
|
+
*/
|
|
361
|
+
export declare function filterCDATANodes(nodes: Node[]): CDATANode[];
|
|
362
|
+
/**
|
|
363
|
+
* Filters an array of nodes to only include WhitespaceNode nodes
|
|
364
|
+
*/
|
|
365
|
+
export declare function filterWhitespaceNodes(nodes: Node[]): WhitespaceNode[];
|
|
366
|
+
/**
|
|
367
|
+
* Filters an array of nodes to only include ERBContentNode nodes
|
|
368
|
+
*/
|
|
369
|
+
export declare function filterERBContentNodes(nodes: Node[]): ERBContentNode[];
|
|
370
|
+
/**
|
|
371
|
+
* Filters an array of nodes to only include ERBEndNode nodes
|
|
372
|
+
*/
|
|
373
|
+
export declare function filterERBEndNodes(nodes: Node[]): ERBEndNode[];
|
|
374
|
+
/**
|
|
375
|
+
* Filters an array of nodes to only include ERBElseNode nodes
|
|
376
|
+
*/
|
|
377
|
+
export declare function filterERBElseNodes(nodes: Node[]): ERBElseNode[];
|
|
378
|
+
/**
|
|
379
|
+
* Filters an array of nodes to only include ERBIfNode nodes
|
|
380
|
+
*/
|
|
381
|
+
export declare function filterERBIfNodes(nodes: Node[]): ERBIfNode[];
|
|
382
|
+
/**
|
|
383
|
+
* Filters an array of nodes to only include ERBBlockNode nodes
|
|
384
|
+
*/
|
|
385
|
+
export declare function filterERBBlockNodes(nodes: Node[]): ERBBlockNode[];
|
|
386
|
+
/**
|
|
387
|
+
* Filters an array of nodes to only include ERBWhenNode nodes
|
|
388
|
+
*/
|
|
389
|
+
export declare function filterERBWhenNodes(nodes: Node[]): ERBWhenNode[];
|
|
390
|
+
/**
|
|
391
|
+
* Filters an array of nodes to only include ERBCaseNode nodes
|
|
392
|
+
*/
|
|
393
|
+
export declare function filterERBCaseNodes(nodes: Node[]): ERBCaseNode[];
|
|
394
|
+
/**
|
|
395
|
+
* Filters an array of nodes to only include ERBCaseMatchNode nodes
|
|
396
|
+
*/
|
|
397
|
+
export declare function filterERBCaseMatchNodes(nodes: Node[]): ERBCaseMatchNode[];
|
|
398
|
+
/**
|
|
399
|
+
* Filters an array of nodes to only include ERBWhileNode nodes
|
|
400
|
+
*/
|
|
401
|
+
export declare function filterERBWhileNodes(nodes: Node[]): ERBWhileNode[];
|
|
402
|
+
/**
|
|
403
|
+
* Filters an array of nodes to only include ERBUntilNode nodes
|
|
404
|
+
*/
|
|
405
|
+
export declare function filterERBUntilNodes(nodes: Node[]): ERBUntilNode[];
|
|
406
|
+
/**
|
|
407
|
+
* Filters an array of nodes to only include ERBForNode nodes
|
|
408
|
+
*/
|
|
409
|
+
export declare function filterERBForNodes(nodes: Node[]): ERBForNode[];
|
|
410
|
+
/**
|
|
411
|
+
* Filters an array of nodes to only include ERBRescueNode nodes
|
|
412
|
+
*/
|
|
413
|
+
export declare function filterERBRescueNodes(nodes: Node[]): ERBRescueNode[];
|
|
414
|
+
/**
|
|
415
|
+
* Filters an array of nodes to only include ERBEnsureNode nodes
|
|
416
|
+
*/
|
|
417
|
+
export declare function filterERBEnsureNodes(nodes: Node[]): ERBEnsureNode[];
|
|
418
|
+
/**
|
|
419
|
+
* Filters an array of nodes to only include ERBBeginNode nodes
|
|
420
|
+
*/
|
|
421
|
+
export declare function filterERBBeginNodes(nodes: Node[]): ERBBeginNode[];
|
|
422
|
+
/**
|
|
423
|
+
* Filters an array of nodes to only include ERBUnlessNode nodes
|
|
424
|
+
*/
|
|
425
|
+
export declare function filterERBUnlessNodes(nodes: Node[]): ERBUnlessNode[];
|
|
426
|
+
/**
|
|
427
|
+
* Filters an array of nodes to only include ERBYieldNode nodes
|
|
428
|
+
*/
|
|
429
|
+
export declare function filterERBYieldNodes(nodes: Node[]): ERBYieldNode[];
|
|
430
|
+
/**
|
|
431
|
+
* Filters an array of nodes to only include ERBInNode nodes
|
|
432
|
+
*/
|
|
433
|
+
export declare function filterERBInNodes(nodes: Node[]): ERBInNode[];
|
|
434
|
+
export {};
|