@eslint-react/jsx 5.30.0-beta.2 → 5.30.0-beta.20
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/index.d.ts +421 -274
- package/dist/index.js +154 -184
- package/package.json +7 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,78 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TSESTreeJSXElementLike } from "@eslint-react/ast";
|
|
2
2
|
import { TSESTree } from "@typescript-eslint/types";
|
|
3
3
|
import { RuleContext } from "@eslint-react/eslint";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* A test used to select a `JSXAttribute`.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* that resolves to an object expression, the object's properties are searched for a
|
|
10
|
-
* matching key (see {@link findSpreadProperty}).
|
|
11
|
-
* @param context The ESLint rule context (needed for variable resolution in spread attributes).
|
|
12
|
-
* @param element The `JSXElement` node to search.
|
|
13
|
-
* @param name The attribute name to look for (ex: "className").
|
|
14
|
-
* @returns The matching `JSXAttribute` or `JSXSpreadAttribute`, or `undefined` when not found.
|
|
15
|
-
*/
|
|
16
|
-
export declare function findAttribute(context: RuleContext, element: TSESTree.JSXElement, name: string): TSESTreeJSXAttributeLike | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* Walk up the AST from `node` to find the nearest `JSXAttribute` ancestor, optionally matching a predicate.
|
|
19
|
-
* @param node The starting node for the upward search.
|
|
20
|
-
* @param test Optional predicate to filter candidate `JSXAttribute` nodes.
|
|
21
|
-
* @returns The first matching `JSXAttribute` ancestor, or `undefined` when none is found.
|
|
22
|
-
*/
|
|
23
|
-
export declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Find the `Property` node that provides a given key inside a spread argument.
|
|
26
|
-
*
|
|
27
|
-
* This is the single resolution routine shared by {@link findAttribute} (existence
|
|
28
|
-
* checks) and the `spreadProps` variant of `resolveAttributeValue` (value extraction):
|
|
29
|
-
*
|
|
30
|
-
* - An `Identifier` argument is resolved to its initializer via variable
|
|
31
|
-
* resolution, following alias chains (`const b = a`) like `getStaticValue`
|
|
32
|
-
* does; an `ObjectExpression` argument is searched directly.
|
|
33
|
-
* - Properties are walked **in reverse** so that later entries win, matching
|
|
34
|
-
* JavaScript object semantics (`{ ...a, k: 1 }` -> the literal `k`).
|
|
35
|
-
* - Nested `SpreadElement`s (identifiers or inline object expressions) are
|
|
36
|
-
* searched recursively; a `seen` set guards against circular references.
|
|
37
|
-
* - Plain identifier keys and string literal keys are matched directly;
|
|
38
|
-
* computed keys are matched when they are statically evaluable
|
|
39
|
-
* (ex: `{ ["class" + "Name"]: 1 }`).
|
|
40
|
-
* @param context The ESLint rule context (needed for variable resolution).
|
|
41
|
-
* @param argument The spread argument expression to search.
|
|
42
|
-
* @param name The property name to look for.
|
|
43
|
-
* @param seen Internal set of already-visited nodes (cycle guard).
|
|
44
|
-
* @returns The matching `Property` node, or `undefined` when the key is not found.
|
|
45
|
-
*/
|
|
46
|
-
export declare function findSpreadProperty(context: RuleContext, argument: TSESTree.Expression, name: string, seen?: Set<TSESTree.Node>): TSESTree.Property | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* Check if the element has an attribute with the given name.
|
|
49
|
-
*
|
|
50
|
-
* Spread attributes are taken into account: `<Comp {...{ disabled: true }} />`
|
|
51
|
-
* reports `true` for `"disabled"` (see {@link findAttribute}).
|
|
52
|
-
* @param context The ESLint rule context (needed for variable resolution in spread attributes).
|
|
53
|
-
* @param element The `JSXElement` node to check.
|
|
54
|
-
* @param name The attribute name to look for (ex: "className").
|
|
55
|
-
* @returns `true` if the attribute is present on the element.
|
|
56
|
-
*/
|
|
57
|
-
export declare function hasAttribute(context: RuleContext, element: TSESTree.JSXElement, name: string): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Check if the element has at least one of the given attributes.
|
|
60
|
-
* @param context The ESLint rule context (needed for variable resolution in spread attributes).
|
|
61
|
-
* @param element The `JSXElement` node to check.
|
|
62
|
-
* @param names The attribute names to look for.
|
|
63
|
-
* @returns `true` if at least one of the attributes is present.
|
|
7
|
+
* A string is matched against the full attribute name (including a namespace);
|
|
8
|
+
* a function receives the attribute node.
|
|
64
9
|
*/
|
|
65
|
-
|
|
10
|
+
type AttributeTest = string | ((attribute: TSESTree.JSXAttribute) => boolean);
|
|
66
11
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
12
|
+
* The structural value of a direct JSX attribute.
|
|
13
|
+
*
|
|
14
|
+
* - `boolean`: the attribute has no value (ex: `<input disabled />`).
|
|
15
|
+
* - `literal`: the value is a literal.
|
|
16
|
+
* - `unknown`: a non-empty expression, normally in an expression container; the expression is not evaluated.
|
|
17
|
+
* - `element`: the value is a JSX element or fragment.
|
|
18
|
+
* - `missing`: no expression, normally an empty expression container
|
|
19
|
+
* (`{}` or `{/* comment *\/}`).
|
|
20
|
+
*
|
|
21
|
+
* Every variant carries the source `attribute`; `node` is `null` only for the
|
|
22
|
+
* `boolean` kind. This is plain data; use {@link getAttributeStaticValue} to
|
|
23
|
+
* collapse values to a plain JavaScript value.
|
|
24
|
+
* @remarks
|
|
25
|
+
* The `spreadChild` variant is omitted because it is not valid in attribute
|
|
26
|
+
* value position and is not produced by current parsers. The `spreadProps`
|
|
27
|
+
* variant is omitted because spread props are not resolved and direct attribute
|
|
28
|
+
* lookup never produces a spread descriptor.
|
|
72
29
|
*/
|
|
73
|
-
|
|
30
|
+
type AttributeValue = {
|
|
31
|
+
readonly kind: "boolean";
|
|
32
|
+
readonly attribute: TSESTree.JSXAttribute;
|
|
33
|
+
readonly node: null;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: "literal";
|
|
36
|
+
readonly attribute: TSESTree.JSXAttribute;
|
|
37
|
+
readonly node: TSESTree.Literal;
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: "unknown";
|
|
40
|
+
readonly attribute: TSESTree.JSXAttribute;
|
|
41
|
+
readonly node: TSESTree.Expression;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: "element";
|
|
44
|
+
readonly attribute: TSESTree.JSXAttribute;
|
|
45
|
+
readonly node: TSESTreeJSXElementLike;
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: "missing";
|
|
48
|
+
readonly attribute: TSESTree.JSXAttribute;
|
|
49
|
+
readonly node: TSESTree.JSXEmptyExpression;
|
|
50
|
+
};
|
|
74
51
|
/**
|
|
75
|
-
* Get the
|
|
52
|
+
* Get the full name of a `JSXAttribute` node.
|
|
76
53
|
*
|
|
77
54
|
* - `className` -> `"className"`
|
|
78
55
|
* - `aria-label` -> `"aria-label"`
|
|
@@ -82,232 +59,374 @@ export declare function hasEveryAttribute(context: RuleContext, element: TSESTre
|
|
|
82
59
|
*/
|
|
83
60
|
export declare function getAttributeName(node: TSESTree.JSXAttribute): string;
|
|
84
61
|
/**
|
|
85
|
-
* Check if the node is a `JSXAttribute` with the given name.
|
|
62
|
+
* Check if the node is a `JSXAttribute` with the given plain identifier name.
|
|
86
63
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
64
|
+
* Namespaced attributes (ex: `xml:space`) never match; use
|
|
65
|
+
* {@link isAttributeNamed} for full-name matching.
|
|
89
66
|
*
|
|
90
67
|
* Supports both data-first and data-last (curried) call styles:
|
|
91
|
-
* - `
|
|
92
|
-
* - `
|
|
68
|
+
* - `isPlainAttribute(node, "className")`
|
|
69
|
+
* - `isPlainAttribute("className")(node)`.
|
|
93
70
|
* @param node The node to check.
|
|
94
|
-
* @param name The attribute name to match (ex: "className").
|
|
95
|
-
* @returns `true` if the node is a `JSXAttribute`
|
|
71
|
+
* @param name The plain attribute name to match (ex: "className").
|
|
72
|
+
* @returns `true` if the node is a `JSXAttribute` whose identifier name is `name`.
|
|
73
|
+
* @remarks
|
|
74
|
+
* This is a name predicate, not a type guard: a `false` result does not mean
|
|
75
|
+
* the node is not a `JSXAttribute`, only that it does not match `name`.
|
|
96
76
|
*/
|
|
97
|
-
export declare const
|
|
98
|
-
(name: string): (node: TSESTree.Node) =>
|
|
99
|
-
(node: TSESTree.Node, name: string):
|
|
77
|
+
export declare const isPlainAttribute: {
|
|
78
|
+
(name: string): (node: TSESTree.Node | null | undefined) => boolean;
|
|
79
|
+
(node: TSESTree.Node | null | undefined, name: string): boolean;
|
|
100
80
|
};
|
|
101
81
|
/**
|
|
102
|
-
*
|
|
82
|
+
* Check if the node is a `JSXAttribute` with the given full name.
|
|
103
83
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
84
|
+
* The name includes the namespace when present, so `xml:space` can be matched.
|
|
85
|
+
* This is the name semantics used by {@link findAttribute} and the string form
|
|
86
|
+
* of {@link AttributeTest}.
|
|
87
|
+
*
|
|
88
|
+
* Supports both data-first and data-last (curried) call styles.
|
|
89
|
+
* @param node The node to check.
|
|
90
|
+
* @param name The full attribute name to match (ex: "className", "xml:space").
|
|
91
|
+
* @returns `true` if the node is a `JSXAttribute` whose full name is `name`.
|
|
92
|
+
* @remarks
|
|
93
|
+
* This is a name predicate, not a type guard: a `false` result does not mean
|
|
94
|
+
* the node is not a `JSXAttribute`, only that it does not match `name`.
|
|
109
95
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
toStatic(): true;
|
|
114
|
-
} | {
|
|
115
|
-
readonly kind: "literal";
|
|
116
|
-
readonly node: TSESTree.Literal;
|
|
117
|
-
toStatic(): TSESTree.Literal["value"];
|
|
118
|
-
} | {
|
|
119
|
-
readonly kind: "unknown";
|
|
120
|
-
readonly node: TSESTree.Expression;
|
|
121
|
-
toStatic(): unknown;
|
|
122
|
-
} | {
|
|
123
|
-
readonly kind: "element";
|
|
124
|
-
readonly node: TSESTreeJSXElementLike;
|
|
125
|
-
toStatic(): undefined;
|
|
126
|
-
} | {
|
|
127
|
-
readonly kind: "missing";
|
|
128
|
-
readonly node: TSESTree.JSXEmptyExpression;
|
|
129
|
-
toStatic(): undefined;
|
|
130
|
-
} | {
|
|
131
|
-
readonly kind: "spreadChild";
|
|
132
|
-
readonly node: TSESTree.JSXSpreadChild;
|
|
133
|
-
toStatic(): undefined;
|
|
134
|
-
} | {
|
|
135
|
-
readonly kind: "spreadProps";
|
|
136
|
-
getProperty(name: string): unknown;
|
|
137
|
-
readonly node: TSESTree.JSXSpreadAttribute["argument"];
|
|
138
|
-
toStatic(): unknown;
|
|
96
|
+
export declare const isAttributeNamed: {
|
|
97
|
+
(name: string): (node: TSESTree.Node | null | undefined) => boolean;
|
|
98
|
+
(node: TSESTree.Node | null | undefined, name: string): boolean;
|
|
139
99
|
};
|
|
140
100
|
/**
|
|
141
|
-
*
|
|
101
|
+
* Find the last direct JSX attribute with the given full name.
|
|
142
102
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* @param
|
|
147
|
-
* @param attribute
|
|
148
|
-
* @
|
|
103
|
+
* Later direct attributes take precedence, matching the order in which JSX
|
|
104
|
+
* props are written. Spread attributes are opaque: they are ignored by this lookup, and a
|
|
105
|
+
* spread after the returned attribute may still override it at runtime.
|
|
106
|
+
* @param element The `JSXElement` node to search.
|
|
107
|
+
* @param name The full attribute name to look for (ex: "className", "xml:space").
|
|
108
|
+
* @returns The last matching `JSXAttribute`, or `null` when not found.
|
|
109
|
+
*/
|
|
110
|
+
export declare function findAttribute(element: TSESTree.JSXElement, name: string): TSESTree.JSXAttribute | null;
|
|
111
|
+
/**
|
|
112
|
+
* Walk up the AST from `node` to find the nearest `JSXAttribute` ancestor,
|
|
113
|
+
* optionally matching a string name or a predicate.
|
|
114
|
+
*
|
|
115
|
+
* The search starts at `node.parent`; `node` itself is not considered. When
|
|
116
|
+
* `test` is omitted, the nearest `JSXAttribute` ancestor matches.
|
|
117
|
+
* @param node The starting node for the upward search; nullish values return `null`.
|
|
118
|
+
* @param test Optional test to filter candidate `JSXAttribute` nodes. A string
|
|
119
|
+
* matches the full attribute name (see {@link isAttributeNamed}); a function
|
|
120
|
+
* receives the candidate attribute.
|
|
121
|
+
* @returns The first matching `JSXAttribute` ancestor, or `null` when none is found.
|
|
122
|
+
*/
|
|
123
|
+
export declare function findParentAttribute(node: TSESTree.Node | null | undefined, test?: AttributeTest): TSESTree.JSXAttribute | null;
|
|
124
|
+
/**
|
|
125
|
+
* Check if the element has a direct attribute with the given full name.
|
|
126
|
+
*
|
|
127
|
+
* Spread attributes are ignored; only direct `JSXAttribute` nodes are checked.
|
|
128
|
+
* @param element The `JSXElement` node to check.
|
|
129
|
+
* @param name The full attribute name to look for (ex: "className", "xml:space").
|
|
130
|
+
* @returns `true` if the attribute is directly present on the element.
|
|
131
|
+
*/
|
|
132
|
+
export declare function hasAttribute(element: TSESTree.JSXElement, name: string): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Check if the element has at least one of the given direct attributes.
|
|
135
|
+
*
|
|
136
|
+
* Spread attributes are ignored; only direct `JSXAttribute` nodes are checked.
|
|
137
|
+
* @param element The `JSXElement` node to check.
|
|
138
|
+
* @param names The full attribute names to look for (namespaces included).
|
|
139
|
+
* @returns `true` if at least one direct attribute is present; `false` for an empty list.
|
|
140
|
+
*/
|
|
141
|
+
export declare function hasAnyAttribute(element: TSESTree.JSXElement, names: readonly string[]): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Check if the element has all of the given direct attributes.
|
|
144
|
+
*
|
|
145
|
+
* Spread attributes are ignored; only direct `JSXAttribute` nodes are checked.
|
|
146
|
+
* @param element The `JSXElement` node to check.
|
|
147
|
+
* @param names The full attribute names to look for (namespaces included).
|
|
148
|
+
* @returns `true` if every direct attribute is present; an empty list is vacuously `true`.
|
|
149
|
+
*/
|
|
150
|
+
export declare function hasEveryAttribute(element: TSESTree.JSXElement, names: readonly string[]): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Get the structural value of a direct `JSXAttribute`.
|
|
153
|
+
*
|
|
154
|
+
* The attribute's value is classified syntactically; expressions are not
|
|
155
|
+
* evaluated. Only direct `JSXAttribute` nodes are accepted; spread attributes
|
|
156
|
+
* are outside this API.
|
|
157
|
+
* @param attribute The `JSXAttribute` node to get the value from.
|
|
149
158
|
* @returns A discriminated-union descriptor of the attribute's value.
|
|
150
159
|
*/
|
|
151
|
-
export declare function
|
|
160
|
+
export declare function getAttributeValue(attribute: TSESTree.JSXAttribute): AttributeValue;
|
|
152
161
|
/**
|
|
153
|
-
* Find
|
|
162
|
+
* Find the last direct attribute with the given full name and get its value.
|
|
154
163
|
*
|
|
155
|
-
* Convenience composition of {@link findAttribute} and {@link
|
|
156
|
-
*
|
|
164
|
+
* Convenience composition of {@link findAttribute} and {@link getAttributeValue}.
|
|
165
|
+
* Spread attributes are ignored; a spread after the matched attribute may still
|
|
166
|
+
* override it at runtime.
|
|
157
167
|
* @param element The `JSXElement` node to search.
|
|
158
|
-
* @param name The attribute name to look up (ex: "className").
|
|
159
|
-
* @returns An {@link AttributeValue} descriptor, or `
|
|
168
|
+
* @param name The full attribute name to look up (ex: "className", "xml:space").
|
|
169
|
+
* @returns An {@link AttributeValue} descriptor, or `null` when no matching direct attribute is present.
|
|
160
170
|
*/
|
|
161
|
-
export declare function
|
|
171
|
+
export declare function getAttributeValueByName(element: TSESTree.JSXElement, name: string): AttributeValue | null;
|
|
162
172
|
/**
|
|
163
|
-
*
|
|
173
|
+
* Get the statically known value of an attribute value descriptor when possible.
|
|
164
174
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
175
|
+
* Boolean attributes resolve to `true`; literal attributes resolve to their
|
|
176
|
+
* literal value; other expressions are evaluated statically when possible.
|
|
177
|
+
* Returns `undefined` when the descriptor is null, is a JSX element or fragment,
|
|
178
|
+
* is a `missing` descriptor, cannot be statically evaluated, or evaluates to
|
|
179
|
+
* `undefined`. A statically known `undefined` is therefore indistinguishable
|
|
180
|
+
* from an indeterminate value.
|
|
181
|
+
* @param context The ESLint rule context (needed for scope look-ups).
|
|
182
|
+
* @param value The attribute value descriptor, or `null`.
|
|
183
|
+
* @returns The static value, or `undefined` when no statically known plain value is available.
|
|
184
|
+
*/
|
|
185
|
+
export declare function getAttributeStaticValue(context: RuleContext, value: AttributeValue | null): unknown;
|
|
186
|
+
/**
|
|
187
|
+
* Find the last direct attribute with the given full name and get its static value.
|
|
188
|
+
*
|
|
189
|
+
* Returns `undefined` when no matching direct attribute is present, or when its
|
|
190
|
+
* value is a JSX element or fragment, is a `missing` descriptor, cannot be
|
|
191
|
+
* statically evaluated, or evaluates to `undefined`. A statically known
|
|
192
|
+
* `undefined` is likewise indistinguishable from an absent or indeterminate
|
|
193
|
+
* value; use {@link hasAttribute} when presence itself matters. Spread
|
|
194
|
+
* attributes are ignored; a spread after the matched attribute may still
|
|
195
|
+
* override it at runtime.
|
|
167
196
|
* @param context The ESLint rule context.
|
|
168
197
|
* @param element The `JSXElement` node to check.
|
|
169
|
-
* @param name The attribute name to look up (ex: "className").
|
|
198
|
+
* @param name The full attribute name to look up (ex: "className", "xml:space").
|
|
170
199
|
* @returns The static value of the attribute, or `undefined` when absent or indeterminate.
|
|
171
200
|
*/
|
|
172
|
-
export declare function
|
|
201
|
+
export declare function getAttributeStaticValueByName(context: RuleContext, element: TSESTree.JSXElement, name: string): unknown;
|
|
202
|
+
/**
|
|
203
|
+
* Check if the node is whitespace-only `JSXText` by its raw source text.
|
|
204
|
+
*
|
|
205
|
+
* Uses `node.raw`, not the entity-decoded `value`, so ` `/` ` count as
|
|
206
|
+
* content even when their decoded value is whitespace; this is not a model of
|
|
207
|
+
* React's whitespace collapsing. Same-line whitespace matches here, while
|
|
208
|
+
* {@link isPaddingWhitespace} (the decoded-value counterpart) also requires a
|
|
209
|
+
* line break.
|
|
210
|
+
* @param node The node to check.
|
|
211
|
+
* @returns `true` if the node is whitespace-only `JSXText` in its raw form.
|
|
212
|
+
* @remarks
|
|
213
|
+
* A content predicate, not a type guard: `false` does not mean the node is not
|
|
214
|
+
* `JSXText`.
|
|
215
|
+
*/
|
|
216
|
+
export declare function isWhitespaceText(node: TSESTree.Node | null | undefined): boolean;
|
|
217
|
+
/**
|
|
218
|
+
* Check if the node is whitespace-only `JSXText` that this module treats as
|
|
219
|
+
* padding: it cleans to nothing (see {@link collapseMultilineText}) and holds a
|
|
220
|
+
* line break (`\r\n`, `\n`, or `\r`), matching Babel's
|
|
221
|
+
* `cleanJSXElementLiteralChild` line splitting.
|
|
222
|
+
*
|
|
223
|
+
* Uses the entity-decoded `value`, so ` `/` ` match even though the raw
|
|
224
|
+
* text has no line break; {@link isWhitespaceText} is the raw-text counterpart.
|
|
225
|
+
* @param node The node to check.
|
|
226
|
+
* @returns `true` if the node is formatting whitespace by its decoded value.
|
|
227
|
+
* @remarks
|
|
228
|
+
* Entity-decoded line breaks follow Babel's cleaning; `tsc --jsx` may emit them
|
|
229
|
+
* as children instead.
|
|
230
|
+
* A content predicate, not a type guard: `false` does not mean the node is not
|
|
231
|
+
* `JSXText`.
|
|
232
|
+
*/
|
|
233
|
+
export declare function isPaddingWhitespace(node: TSESTree.Node | null | undefined): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Check if the node is an empty expression container (`{}`, `{ }`,
|
|
236
|
+
* `{/* comment *\/}`), including multiline and TypeScript directive comments.
|
|
237
|
+
*
|
|
238
|
+
* It holds a `JSXEmptyExpression`, so it renders nothing, like whitespace
|
|
239
|
+
* padding. A comment attached to a real expression (`{/* comment *\/} null`) is
|
|
240
|
+
* not empty.
|
|
241
|
+
* @param node The node to check.
|
|
242
|
+
* @returns `true` if the node is an empty `JSXExpressionContainer`.
|
|
243
|
+
* @remarks
|
|
244
|
+
* A content predicate, not a type guard: `false` does not mean the node is not
|
|
245
|
+
* a `JSXExpressionContainer`.
|
|
246
|
+
*/
|
|
247
|
+
export declare function isEmptyExpressionContainer(node: TSESTree.Node | null | undefined): boolean;
|
|
173
248
|
/**
|
|
174
|
-
*
|
|
249
|
+
* Check if the node is an empty string literal expression (`{""}`, `{''}`).
|
|
175
250
|
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* `
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
251
|
+
* Node-shape check, not an evaluation: TS wrappers (`{"" as string}`, `{""!}`,
|
|
252
|
+
* `{"" satisfies string}`), template literals (`` {``} ``, `` {`${''}`} ``), and
|
|
253
|
+
* calls (`{String("")}`) do not match even though their runtime value is `""`;
|
|
254
|
+
* only `value === ""` matches, so `{0}`, `{false}`, and `{NaN}` do not. A comment
|
|
255
|
+
* attached to the literal does not affect the result.
|
|
256
|
+
* @param node The node to check.
|
|
257
|
+
* @returns `true` if the node holds a bare empty string literal.
|
|
258
|
+
* @remarks
|
|
259
|
+
* A content predicate, not a type guard: `false` does not mean the node is not
|
|
260
|
+
* a `JSXExpressionContainer`.
|
|
261
|
+
*/
|
|
262
|
+
export declare function isEmptyStringExpression(node: TSESTree.Node | null | undefined): boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Check if the child is syntactically non-empty ("meaningful") content.
|
|
265
|
+
*
|
|
266
|
+
* Excluded: whitespace-only `JSXText` per {@link isWhitespaceText} (raw text, so
|
|
267
|
+
* entity text such as ` `/` ` is kept), empty expression containers, and
|
|
268
|
+
* bare empty string literals.
|
|
269
|
+
*
|
|
270
|
+
* Kept: dynamic values (`{null}`, `{false}`, `{undefined}`, `{0}`, `{NaN}`,
|
|
271
|
+
* `{cond ? <A /> : null}`), TS-wrapped empty strings (`{"" as string}`, `{""!}`),
|
|
272
|
+
* unevaluated template literals, and spread children.
|
|
273
|
+
*
|
|
274
|
+
* A syntactic check, not a rendering oracle: React renders nothing for `null`,
|
|
275
|
+
* `undefined`, booleans, and `""`, but those children are kept.
|
|
276
|
+
* @param node The JSX child to check.
|
|
277
|
+
* @returns `true` if the child is not syntactically empty.
|
|
278
|
+
* @remarks
|
|
279
|
+
* Definitional difference: JSXText `" "` is not meaningful, while `{" "}` and
|
|
280
|
+
* ` ` are, even though all three render a space text node.
|
|
281
|
+
*/
|
|
282
|
+
export declare function isMeaningfulChild(node: TSESTree.JSXChild): boolean;
|
|
283
|
+
/**
|
|
284
|
+
* Get the children of a JSX element or fragment after removing padding
|
|
285
|
+
* whitespace (see {@link isPaddingWhitespace}), empty expression containers,
|
|
286
|
+
* and empty string literals.
|
|
287
|
+
*
|
|
288
|
+
* Same-line whitespace is kept (it can render a text node); this is a syntactic
|
|
289
|
+
* filter, not a rendering guarantee (`{null}`/`{false}` are kept). Compared with
|
|
290
|
+
* {@link getMeaningfulChildren}:
|
|
291
|
+
*
|
|
292
|
+
* | Input | `getChildren` | `getMeaningfulChildren` |
|
|
293
|
+
* | ------------------------ | ------------------------- | ----------------------- |
|
|
294
|
+
* | `" "`, `"\t"` | kept | excluded |
|
|
295
|
+
* | `\r \r` (CR-only) | excluded | excluded |
|
|
296
|
+
* | ` `, ` ` | excluded (Babel cleaning) | kept (raw text) |
|
|
297
|
+
* | ` `, ` ` | kept | kept |
|
|
298
|
+
* | `{null}`, `{false}` | kept | kept |
|
|
299
|
+
* | `{}`, `{/* comment *\/}` | excluded | excluded |
|
|
300
|
+
* | `{""}` | excluded | excluded |
|
|
301
|
+
* | `{"" as string}` | kept | kept |
|
|
186
302
|
* @param element A `JSXElement` or `JSXFragment` node.
|
|
187
|
-
* @returns The children
|
|
303
|
+
* @returns The children that remain after removing padding artifacts.
|
|
188
304
|
*/
|
|
189
305
|
export declare function getChildren(element: TSESTreeJSXElementLike): TSESTree.JSXChild[];
|
|
190
306
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* empty string expression (`{""}`).
|
|
307
|
+
* Get the children of a JSX element or fragment that are not syntactically
|
|
308
|
+
* empty.
|
|
194
309
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
310
|
+
* Stricter than {@link getChildren} for same-line whitespace
|
|
311
|
+
* (`<div> </div>` yields no children here). Dynamic expressions count, and
|
|
312
|
+
* entity line breaks (` `, ` `) are kept because the raw text is not
|
|
313
|
+
* whitespace, whereas `getChildren` excludes them through Babel's decoded-value
|
|
314
|
+
* cleaning. See {@link getChildren} for a comparison table.
|
|
198
315
|
* @param element A `JSXElement` or `JSXFragment` node.
|
|
199
|
-
* @returns
|
|
316
|
+
* @returns The children that are not syntactically empty.
|
|
200
317
|
*/
|
|
201
|
-
export declare function
|
|
318
|
+
export declare function getMeaningfulChildren(element: TSESTreeJSXElementLike): TSESTree.JSXChild[];
|
|
202
319
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* @
|
|
320
|
+
* Check if the element has at least one syntactically non-empty child.
|
|
321
|
+
*
|
|
322
|
+
* A child counts unless it is whitespace-only `JSXText` per
|
|
323
|
+
* {@link isWhitespaceText}, an empty expression container, or a bare empty
|
|
324
|
+
* string literal. Same-line whitespace does not count, unlike in
|
|
325
|
+
* {@link getChildren}; `{null}`, `{false}`, and other dynamic expressions do. A
|
|
326
|
+
* syntactic check, not a rendering oracle.
|
|
327
|
+
* @param element A `JSXElement` or `JSXFragment` node.
|
|
328
|
+
* @returns `true` if the element has at least one syntactically non-empty child.
|
|
207
329
|
*/
|
|
208
|
-
export declare function
|
|
330
|
+
export declare function hasMeaningfulChildren(element: TSESTreeJSXElementLike): boolean;
|
|
209
331
|
/**
|
|
210
|
-
*
|
|
332
|
+
* A parsed `createElement` call.
|
|
211
333
|
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
334
|
+
* The raw positional argument fields (`typeArgument`, `propsArgument`, and
|
|
335
|
+
* `childrenArguments`) may contain `SpreadElement` nodes. `propsObject` is the
|
|
336
|
+
* only derived field: it is the second argument after unwrapping type/chain
|
|
337
|
+
* expressions, and is non-null only when that argument is syntactically an
|
|
338
|
+
* object literal.
|
|
339
|
+
*/
|
|
340
|
+
interface CreateElementCall {
|
|
341
|
+
/** The raw arguments after the props argument. */
|
|
342
|
+
readonly childrenArguments: readonly TSESTree.CallExpressionArgument[];
|
|
343
|
+
/** The call expression node. */
|
|
344
|
+
readonly node: TSESTree.CallExpression;
|
|
345
|
+
/** The raw second positional argument (the props argument), if present. */
|
|
346
|
+
readonly propsArgument: TSESTree.CallExpressionArgument | null;
|
|
347
|
+
/** The second argument unwrapped, when it is an object literal. */
|
|
348
|
+
readonly propsObject: TSESTree.ObjectExpression | null;
|
|
349
|
+
/** The raw first positional argument (the element type), if present. */
|
|
350
|
+
readonly typeArgument: TSESTree.CallExpressionArgument | null;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Check if the node is a call to a `createElement` API.
|
|
215
354
|
*
|
|
355
|
+
* Matching is name-based and namespace-agnostic: the fully qualified callee name
|
|
356
|
+
* must be `createElement` or end with `.createElement`. No import provenance
|
|
357
|
+
* check is performed, matching `isAPICall("createElement")` in `@eslint-react/core`.
|
|
216
358
|
* @param context The ESLint rule context.
|
|
217
|
-
* @param node The node to inspect
|
|
218
|
-
* @returns
|
|
359
|
+
* @param node The node to inspect; nullish or non-call nodes return `false`.
|
|
360
|
+
* @returns `true` if the node is a `createElement` call.
|
|
361
|
+
* @remarks
|
|
362
|
+
* This is a call-name predicate, not a type guard: a `false` result does not
|
|
363
|
+
* mean the node is not a `CallExpression`, only that it is not a
|
|
364
|
+
* `createElement` call.
|
|
219
365
|
*/
|
|
220
|
-
export declare function
|
|
366
|
+
export declare function isCreateElementCall(context: RuleContext, node: TSESTree.Node | null | undefined): boolean;
|
|
221
367
|
/**
|
|
222
|
-
*
|
|
368
|
+
* Parse a `createElement` call into its positional arguments.
|
|
369
|
+
*
|
|
370
|
+
* A nullish or non-`createElement` node yields `null`; a matched call always
|
|
371
|
+
* yields a descriptor, even when it has no arguments. This removes the ambiguity
|
|
372
|
+
* between "not a `createElement` call" and "a call with no props/children".
|
|
223
373
|
* @param context The ESLint rule context.
|
|
224
374
|
* @param node The node to inspect.
|
|
225
|
-
* @returns The
|
|
375
|
+
* @returns The parsed call, or `null` when the node is not a `createElement` call.
|
|
226
376
|
*/
|
|
227
|
-
export declare function
|
|
377
|
+
export declare function parseCreateElementCall(context: RuleContext, node: TSESTree.Node | null | undefined): CreateElementCall | null;
|
|
228
378
|
/**
|
|
229
|
-
* Find a statically named property in the props object of a `createElement` call.
|
|
379
|
+
* Find a statically named direct property in the props object of a `createElement` call.
|
|
380
|
+
*
|
|
381
|
+
* Properties are scanned in reverse so that the last direct property takes precedence.
|
|
382
|
+
* Spread properties are ignored rather than statically resolved; a spread after
|
|
383
|
+
* the returned property may still override it at runtime. Statically evaluable
|
|
384
|
+
* computed keys are matched.
|
|
230
385
|
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
386
|
+
* Returns `null` when the call is `null` or has no statically identifiable props
|
|
387
|
+
* object, that is, when the second argument is absent or is not an object
|
|
388
|
+
* literal after unwrapping type/chain expressions.
|
|
233
389
|
* @param context The ESLint rule context.
|
|
234
|
-
* @param
|
|
390
|
+
* @param call The parsed call, or `null`.
|
|
235
391
|
* @param name The property name to look for (ex: `"children"`, `"key"`).
|
|
236
|
-
* @returns The matching `Property` node, or `null` when
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* ```ts
|
|
240
|
-
* import { getCreateElementProp } from "@eslint-react/jsx";
|
|
241
|
-
*
|
|
242
|
-
* const childrenProp = getCreateElementProp(context, node, "children");
|
|
243
|
-
* ```
|
|
392
|
+
* @returns The last matching `Property` node, or `null` when not found.
|
|
244
393
|
*/
|
|
245
|
-
export declare function
|
|
394
|
+
export declare function findCreateElementProp(context: RuleContext, call: CreateElementCall | null, name: string): TSESTree.Property | null;
|
|
246
395
|
/**
|
|
247
|
-
* Check if the node is passed as a children argument (the third argument
|
|
248
|
-
* later) of a `createElement` call.
|
|
396
|
+
* Check if the node itself is passed as a children argument (the third argument
|
|
397
|
+
* or later) of a `createElement` call. Contiguous TypeScript type-expression
|
|
398
|
+
* and chain-expression ancestors are skipped, and the node is unwrapped before
|
|
399
|
+
* the comparison; expressions nested inside an argument are not considered.
|
|
249
400
|
* @param context The ESLint rule context.
|
|
250
|
-
* @param node The node to check
|
|
401
|
+
* @param node The node to check; nullish values return `false`.
|
|
251
402
|
* @returns `true` if the node is a direct children argument of a `createElement` call.
|
|
252
403
|
*/
|
|
253
|
-
export declare function isCreateElementChildrenArgument(context: RuleContext, node: TSESTree.Node): boolean;
|
|
404
|
+
export declare function isCreateElementChildrenArgument(context: RuleContext, node: TSESTree.Node | null | undefined): boolean;
|
|
254
405
|
/**
|
|
255
|
-
* Check if the node
|
|
256
|
-
*
|
|
257
|
-
*
|
|
406
|
+
* Check if the node's closest `ObjectExpression` ancestor is the props object
|
|
407
|
+
* (the second argument) of its nearest enclosing `createElement` call. The
|
|
408
|
+
* second argument is unwrapped when it is a type or chain expression. Nodes that
|
|
409
|
+
* cross another object literal (ex: a value inside an object nested in the props
|
|
410
|
+
* object) are not considered inside.
|
|
258
411
|
* @param context The ESLint rule context.
|
|
259
|
-
* @param node The node to check
|
|
260
|
-
* @returns `true` if the node
|
|
412
|
+
* @param node The node to check; nullish values return `false`.
|
|
413
|
+
* @returns `true` if the node's closest object literal is `createElement`'s props object.
|
|
261
414
|
*/
|
|
262
|
-
export declare function isInsideCreateElementProps(context: RuleContext, node: TSESTree.Node): boolean;
|
|
415
|
+
export declare function isInsideCreateElementProps(context: RuleContext, node: TSESTree.Node | null | undefined): boolean;
|
|
263
416
|
/**
|
|
264
|
-
* A test that determines whether a JSX element matches.
|
|
417
|
+
* A test that determines whether a JSX element or fragment matches.
|
|
265
418
|
*
|
|
266
|
-
* - `string` matches
|
|
267
|
-
*
|
|
268
|
-
* - `
|
|
269
|
-
|
|
270
|
-
type ElementTest = string | readonly string[] | ((elementType: string, node: TSESTreeJSXElementLike) => boolean);
|
|
271
|
-
/**
|
|
272
|
-
* Check if the node is a `JSXElement` (or `JSXFragment`), optionally matching a given test.
|
|
419
|
+
* - `string` matches the full element type (ex: "div", "React.Fragment"; a
|
|
420
|
+
* fragment has type `""`)
|
|
421
|
+
* - `readonly string[]` matches when the full element type equals any entry
|
|
422
|
+
* - `function` receives the full element type string and the element or fragment node.
|
|
273
423
|
*
|
|
274
|
-
*
|
|
275
|
-
* the
|
|
276
|
-
* the function acts as a simple type guard for `JSXElement | JSXFragment`.
|
|
277
|
-
* @param node The node to check.
|
|
278
|
-
* @param test Optional test to match the element type against.
|
|
279
|
-
* @returns `true` if the node is a matching JSX element.
|
|
424
|
+
* The function form receives `(elementType, node)`; this order is intentional:
|
|
425
|
+
* the element type is the primary subject of the test.
|
|
280
426
|
*/
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Check if the node is a React Fragment element.
|
|
284
|
-
*
|
|
285
|
-
* Recognizes both the shorthand `<>...</>` syntax (`JSXFragment`) and the explicit
|
|
286
|
-
* `<Fragment>` / `<React.Fragment>` form (`JSXElement`). The comparison is performed
|
|
287
|
-
* against the self name (last dot-separated segment) of both the node and the
|
|
288
|
-
* configured factory, so `<React.Fragment>` matches `"React.Fragment"` and
|
|
289
|
-
* `<Fragment>` matches `"Fragment"`.
|
|
290
|
-
*
|
|
291
|
-
* The factory is a required parameter (no implicit `"React.Fragment"` default) so
|
|
292
|
-
* that callers always pass the project-configured pragma — see `getJSXConfig` in
|
|
293
|
-
* `@eslint-react/core` — and cannot silently use the wrong factory under a custom
|
|
294
|
-
* JSX runtime (ex: Preact). Note the self-name comparison is a heuristic: any
|
|
295
|
-
* `<*.Fragment>` member expression matches, regardless of the qualifier.
|
|
296
|
-
* @param node The node to check.
|
|
297
|
-
* @param jsxFragmentFactory The configured fragment factory string (ex: "React.Fragment").
|
|
298
|
-
* @returns `true` if the node represents a React Fragment.
|
|
299
|
-
*/
|
|
300
|
-
export declare function isFragmentElement(node: TSESTree.Node, jsxFragmentFactory: string): node is TSESTreeJSXElementLike;
|
|
301
|
-
/**
|
|
302
|
-
* Check if the node is a host (intrinsic / DOM) element, that is, a `JSXElement`
|
|
303
|
-
* whose tag name starts with a lowercase letter (ex: `<div>` vs `<MyComponent>`).
|
|
304
|
-
* For namespaced names, the local part is checked (ex: `rect` in `<svg:rect>`).
|
|
305
|
-
* @param node The node to check.
|
|
306
|
-
* @returns `true` if the node is a `JSXElement` with a lowercase tag name.
|
|
307
|
-
*/
|
|
308
|
-
export declare function isHostElement(node: TSESTree.Node): node is TSESTree.JSXElement;
|
|
427
|
+
type ElementTest = string | readonly string[] | ((elementType: string, node: TSESTreeJSXElementLike) => boolean);
|
|
309
428
|
/**
|
|
310
|
-
* Get the string representation of a JSX element's type.
|
|
429
|
+
* Get the string representation of a JSX element or fragment's type.
|
|
311
430
|
*
|
|
312
431
|
* - `<div>` -> `"div"`
|
|
313
432
|
* - `<Foo.Bar>` -> `"Foo.Bar"`
|
|
@@ -319,64 +438,92 @@ export declare function isHostElement(node: TSESTree.Node): node is TSESTree.JSX
|
|
|
319
438
|
*/
|
|
320
439
|
export declare function getElementFullType(node: TSESTreeJSXElementLike): string;
|
|
321
440
|
/**
|
|
322
|
-
* Get the self name (last dot-separated segment) of a JSX element type.
|
|
441
|
+
* Get the self name (last dot-separated segment) of a JSX element or fragment type.
|
|
323
442
|
*
|
|
324
443
|
* - `<Foo.Bar.Baz>` -> `"Baz"`
|
|
325
444
|
* - `<div>` -> `"div"`
|
|
445
|
+
* - `<xml:space>` -> `"xml:space"` (only `.` separates segments, not `:`)
|
|
326
446
|
* - `<></>` -> `""`
|
|
327
447
|
* @param node The `JSXElement` or `JSXFragment` node.
|
|
328
|
-
* @returns The last segment of the element type, or `""` for fragments.
|
|
448
|
+
* @returns The last dot-separated segment of the element type, or `""` for fragments.
|
|
329
449
|
*/
|
|
330
450
|
export declare function getElementSelfType(node: TSESTreeJSXElementLike): string;
|
|
331
451
|
/**
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
* 1. Split the raw text into lines.
|
|
336
|
-
* 2. Find the last non-empty line.
|
|
337
|
-
* 3. Collapse tabs into spaces.
|
|
338
|
-
* 4. Trim leading spaces on non-first lines and trailing spaces on non-last lines.
|
|
339
|
-
* 5. Append a single space after each non-last non-empty line.
|
|
340
|
-
* @param text The raw JSX text string to collapse.
|
|
341
|
-
* @returns The collapsed string, or `null` when the text contains only whitespace.
|
|
342
|
-
* @see https://github.com/babel/babel/blob/main/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts
|
|
452
|
+
* Check if the node is a `JSXElement` or `JSXFragment`.
|
|
453
|
+
* @param node The node to check.
|
|
454
|
+
* @returns `true` if the node is a JSX element or fragment.
|
|
343
455
|
*/
|
|
344
|
-
export declare function
|
|
456
|
+
export declare function isElement(node: TSESTree.Node | null | undefined): node is TSESTreeJSXElementLike;
|
|
345
457
|
/**
|
|
346
|
-
* Check if the node is
|
|
347
|
-
* rendering, that is, a `JSXText` node that cleans to nothing (see
|
|
348
|
-
* {@link collapseMultilineText}) and contains a newline.
|
|
349
|
-
*
|
|
350
|
-
* For the looser "any whitespace-only text" check, see {@link isWhitespaceText}.
|
|
458
|
+
* Check if the node is a `JSXElement` or `JSXFragment` matching the given test.
|
|
351
459
|
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
* @param
|
|
356
|
-
* @returns `true` if the node is
|
|
460
|
+
* Modelled after [`hast-util-is-element`](https://github.com/syntax-tree/hast-util-is-element):
|
|
461
|
+
* the `test` parameter controls what counts as a match.
|
|
462
|
+
* @param node The node to check.
|
|
463
|
+
* @param test Test to match the full element type against.
|
|
464
|
+
* @returns `true` if the node is a matching JSX element or fragment.
|
|
465
|
+
* @remarks
|
|
466
|
+
* This is a match predicate, not a type guard: a `false` result does not mean
|
|
467
|
+
* the node is not a JSX element or fragment, only that it does not match the test.
|
|
357
468
|
*/
|
|
358
|
-
export declare function
|
|
469
|
+
export declare function isElement(node: TSESTree.Node | null | undefined, test: ElementTest): boolean;
|
|
359
470
|
/**
|
|
360
|
-
* Check if the node is
|
|
471
|
+
* Check if the node is a React Fragment element.
|
|
361
472
|
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
473
|
+
* Recognizes the shorthand `<>...</>` syntax (`JSXFragment`) and the explicit
|
|
474
|
+
* `<Fragment>` / `<React.Fragment>` form (`JSXElement`). Matching compares only
|
|
475
|
+
* the last dot-separated segment, so with the usual `"React.Fragment"` factory
|
|
476
|
+
* both `<React.Fragment>` and `<Fragment>` match.
|
|
364
477
|
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
478
|
+
* The factory is a required parameter (no implicit `"React.Fragment"` default) so
|
|
479
|
+
* that callers always pass the project-configured pragma — see `getJSXConfig` in
|
|
480
|
+
* `@eslint-react/core` — and cannot silently use the wrong factory under a custom
|
|
481
|
+
* JSX runtime (ex: Preact). Note the self-name comparison is a heuristic: any
|
|
482
|
+
* `<*.Fragment>` member expression matches, regardless of the qualifier.
|
|
483
|
+
* @param node The node to check.
|
|
484
|
+
* @param jsxFragmentFactory The configured fragment factory string (ex: "React.Fragment");
|
|
485
|
+
* only its last dot-separated segment is compared.
|
|
486
|
+
* @returns `true` if the node is a `JSXFragment` or its element type's self name matches the configured fragment self name.
|
|
487
|
+
* @remarks
|
|
488
|
+
* This is a match predicate, not a type guard: a `false` result does not mean
|
|
489
|
+
* the node is not a JSX element or fragment.
|
|
370
490
|
*/
|
|
371
|
-
export declare function
|
|
491
|
+
export declare function isFragmentElement(node: TSESTree.Node | null | undefined, jsxFragmentFactory: string): boolean;
|
|
372
492
|
/**
|
|
373
|
-
* Check if the node is
|
|
493
|
+
* Check if the node is a host (intrinsic / DOM) element, that is, a `JSXElement`
|
|
494
|
+
* whose tag name starts with an ASCII lowercase letter (ex: `<div>` vs
|
|
495
|
+
* `<MyComponent>`). For namespaced names, the local part is checked (ex: `rect`
|
|
496
|
+
* in `<svg:rect>`). Member-expression names (ex: `<foo.Bar>`) are not host elements.
|
|
497
|
+
* @param node The node to check.
|
|
498
|
+
* @returns `true` if the node is a `JSXElement` with a plain or namespaced tag
|
|
499
|
+
* name starting with an ASCII lowercase letter.
|
|
500
|
+
* @remarks
|
|
501
|
+
* This is a match predicate, not a type guard: a `false` result does not mean
|
|
502
|
+
* the node is not a `JSXElement`; custom components are also JSX elements.
|
|
503
|
+
*/
|
|
504
|
+
export declare function isHostElement(node: TSESTree.Node | null | undefined): boolean;
|
|
505
|
+
/**
|
|
506
|
+
* Collapse a JSX text string using Babel's `cleanJSXElementLiteralChild`
|
|
507
|
+
* whitespace rules.
|
|
508
|
+
*
|
|
509
|
+
* 1. Split the input on CRLF, LF, or CR.
|
|
510
|
+
* 2. Track the last line containing a character other than a space or tab,
|
|
511
|
+
* defaulting to the first line when there is none.
|
|
512
|
+
* 3. Replace each tab with a space.
|
|
513
|
+
* 4. Remove leading spaces from non-first lines and trailing spaces from
|
|
514
|
+
* non-last physical lines.
|
|
515
|
+
* 5. Append a single space after each line that still has content, except the
|
|
516
|
+
* last tracked line.
|
|
374
517
|
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
* @
|
|
518
|
+
* This function is the module's authority for JSX whitespace semantics.
|
|
519
|
+
* `tsc --jsx` trims raw line breaks the same way, but it may emit
|
|
520
|
+
* entity-decoded line breaks (ex: ` `, ` `) as text children, which
|
|
521
|
+
* this cleaning removes.
|
|
522
|
+
* @param text The JSX text string to collapse (typically a decoded `JSXText.value`).
|
|
523
|
+
* @returns The collapsed string, or `null` when the collapsed result is empty
|
|
524
|
+
* (for example, for empty input or multiline input containing only spaces, tabs,
|
|
525
|
+
* and line breaks).
|
|
526
|
+
* @see https://github.com/babel/babel/blob/main/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts
|
|
380
527
|
*/
|
|
381
|
-
export declare function
|
|
382
|
-
export type { AttributeValue, ElementTest };
|
|
528
|
+
export declare function collapseMultilineText(text: string): string | null;
|
|
529
|
+
export type { AttributeTest, AttributeValue, CreateElementCall, ElementTest };
|