@eslint-react/jsx 5.27.2 → 5.27.4
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 +13 -4
- package/dist/index.js +12 -5
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -128,7 +128,7 @@ type AttributeValue = {
|
|
|
128
128
|
toStatic(): unknown;
|
|
129
129
|
} | {
|
|
130
130
|
readonly kind: "element";
|
|
131
|
-
readonly node:
|
|
131
|
+
readonly node: TSESTreeJSXElementLike;
|
|
132
132
|
toStatic(): undefined;
|
|
133
133
|
} | {
|
|
134
134
|
readonly kind: "missing";
|
|
@@ -194,7 +194,8 @@ export declare function getAttributeStaticValue(context: RuleContext, element: T
|
|
|
194
194
|
export declare function getChildren(element: TSESTreeJSXElementLike): TSESTree.JSXChild[];
|
|
195
195
|
/**
|
|
196
196
|
* Check if the element has at least one meaningful child, that is, a child that
|
|
197
|
-
* is not purely whitespace text
|
|
197
|
+
* is not purely whitespace text, an empty expression container (`{}`), or an
|
|
198
|
+
* empty string expression (`{""}`).
|
|
198
199
|
*
|
|
199
200
|
* Unlike {@link getChildren} (which only filters whitespace containing a newline),
|
|
200
201
|
* this check treats any whitespace-only text as non-meaningful, so `hasChildren(node)`
|
|
@@ -282,8 +283,8 @@ export declare function getElementSelfType(node: TSESTreeJSXElementLike): string
|
|
|
282
283
|
* Mirrors Babel's `cleanJSXElementLiteralChild` algorithm:
|
|
283
284
|
* 1. Split the raw text into lines.
|
|
284
285
|
* 2. Find the last non-empty line.
|
|
285
|
-
* 3.
|
|
286
|
-
* 4.
|
|
286
|
+
* 3. Collapse tabs into spaces.
|
|
287
|
+
* 4. Trim leading spaces on non-first lines and trailing spaces on non-last lines.
|
|
287
288
|
* 5. Append a single space after each non-last non-empty line.
|
|
288
289
|
* @param text The raw JSX text string to collapse.
|
|
289
290
|
* @returns The collapsed string, or `null` when the text contains only whitespace.
|
|
@@ -296,6 +297,10 @@ export declare function collapseMultilineText(text: string): string | null;
|
|
|
296
297
|
* {@link collapseMultilineText}) and contains a newline.
|
|
297
298
|
*
|
|
298
299
|
* For the looser "any whitespace-only text" check, see {@link isWhitespaceText}.
|
|
300
|
+
*
|
|
301
|
+
* Reads the entity-decoded `node.value`; `value` and `raw` differ only when the
|
|
302
|
+
* text contains HTML entities (ex: ` `), which is never whitespace-only,
|
|
303
|
+
* so reading either field yields the same result here.
|
|
299
304
|
* @param node The JSX child node to check.
|
|
300
305
|
* @returns `true` if the node is purely formatting whitespace.
|
|
301
306
|
*/
|
|
@@ -305,6 +310,10 @@ export declare function isPaddingWhitespace(node: TSESTree.JSXChild): boolean;
|
|
|
305
310
|
*
|
|
306
311
|
* Looser variant of {@link isPaddingWhitespace}; matches every `JSXText` node
|
|
307
312
|
* whose raw content is empty after trimming, regardless of newlines.
|
|
313
|
+
*
|
|
314
|
+
* Reads `node.raw` rather than the entity-decoded `value`; for whitespace-only
|
|
315
|
+
* text the two are identical (an entity is never whitespace), matching React's
|
|
316
|
+
* behavior of rendering entity text like ` ` as a real text node.
|
|
308
317
|
* @param node The JSX child node to check.
|
|
309
318
|
* @returns `true` if the node is a whitespace-only `JSXText`.
|
|
310
319
|
*/
|
package/dist/index.js
CHANGED
|
@@ -213,6 +213,11 @@ function resolveJsxAttribute(context, node) {
|
|
|
213
213
|
node: node.value,
|
|
214
214
|
toStatic() {}
|
|
215
215
|
};
|
|
216
|
+
case AST_NODE_TYPES.JSXFragment: return {
|
|
217
|
+
kind: "element",
|
|
218
|
+
node: node.value,
|
|
219
|
+
toStatic() {}
|
|
220
|
+
};
|
|
216
221
|
case AST_NODE_TYPES.JSXSpreadChild: return {
|
|
217
222
|
kind: "spreadChild",
|
|
218
223
|
node: node.value,
|
|
@@ -266,6 +271,10 @@ function isWhitespaceText(node) {
|
|
|
266
271
|
if (node.type !== AST_NODE_TYPES.JSXText) return false;
|
|
267
272
|
return node.raw.trim() === "";
|
|
268
273
|
}
|
|
274
|
+
function isEmptyExpressionContainer(node) {
|
|
275
|
+
if (node.type !== AST_NODE_TYPES.JSXExpressionContainer) return false;
|
|
276
|
+
return node.expression.type === AST_NODE_TYPES.JSXEmptyExpression;
|
|
277
|
+
}
|
|
269
278
|
function isEmptyStringExpression(node) {
|
|
270
279
|
if (node.type !== AST_NODE_TYPES.JSXExpressionContainer) return false;
|
|
271
280
|
const expr = node.expression;
|
|
@@ -278,17 +287,15 @@ function getChildren(element) {
|
|
|
278
287
|
const children = [];
|
|
279
288
|
for (const child of element.children) {
|
|
280
289
|
if (isPaddingWhitespace(child)) continue;
|
|
281
|
-
if (child
|
|
282
|
-
|
|
283
|
-
if (isEmptyStringExpression(child)) continue;
|
|
284
|
-
}
|
|
290
|
+
if (isEmptyExpressionContainer(child)) continue;
|
|
291
|
+
if (isEmptyStringExpression(child)) continue;
|
|
285
292
|
children.push(child);
|
|
286
293
|
}
|
|
287
294
|
return children;
|
|
288
295
|
}
|
|
289
296
|
function hasChildren(element) {
|
|
290
297
|
if (element.children.length === 0) return false;
|
|
291
|
-
return !element.children.every(or(isWhitespaceText, isEmptyStringExpression));
|
|
298
|
+
return !element.children.every(or(or(isWhitespaceText, isEmptyExpressionContainer), isEmptyStringExpression));
|
|
292
299
|
}
|
|
293
300
|
//#endregion
|
|
294
301
|
//#region src/element-type.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/jsx",
|
|
3
|
-
"version": "5.27.
|
|
3
|
+
"version": "5.27.4",
|
|
4
4
|
"description": "ESLint React's TSESTree JSX utility module for static analysis of JSX patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@eslint-react/ast": "5.27.
|
|
33
|
-
"@eslint-react/eslint": "5.27.
|
|
34
|
-
"@eslint-react/var": "5.27.
|
|
32
|
+
"@eslint-react/ast": "5.27.4",
|
|
33
|
+
"@eslint-react/eslint": "5.27.4",
|
|
34
|
+
"@eslint-react/var": "5.27.4",
|
|
35
35
|
"@typescript-eslint/types": "^8.71.2",
|
|
36
36
|
"@typescript-eslint/utils": "^8.71.2",
|
|
37
37
|
"ts-pattern": "^5.9.2"
|