@eslint-react/jsx 1.40.2 → 1.40.3-next.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/index.d.mts CHANGED
@@ -50,6 +50,20 @@ declare function hasAttribute(name: string, attributes: TSESTree.JSXOpeningEleme
50
50
  declare function hasAnyAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
51
51
  declare function hasEveryAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
52
52
 
53
+ /**
54
+ * Check if a node is a `JSXFragment` or a `Fragment` element
55
+ * @param node The AST node to check
56
+ * @returns `true` if the node is a `JSXFragment` or a `Fragment` element
57
+ */
58
+ declare function isJSXFragmentLike(node: TSESTree.Node | null | _): boolean;
59
+
60
+ /**
61
+ * Check if a node is a `JSXText` or a `Literal` node
62
+ * @param node The AST node to check
63
+ * @returns `true` if the node is a `JSXText` or a `Literal` node
64
+ */
65
+ declare function isJSXTextLike(node: TSESTree.Node | null | _): node is TSESTree.JSXText | TSESTree.Literal;
66
+
53
67
  declare const JSXValueHint: {
54
68
  readonly None: 0n;
55
69
  readonly SkipUndefined: bigint;
@@ -91,43 +105,18 @@ declare function isFragmentElement(node: TSESTree.Node): boolean;
91
105
  */
92
106
  declare function isKeyedElement(node: TSESTree.Node, initialScope?: Scope): boolean;
93
107
  /**
94
- * Check if a node is a `JSXFragment` of `Built-in Component` type
108
+ * Check if a node is a `JSXElement` of built-in component
95
109
  * @param node The AST node to check
96
110
  * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
97
111
  */
98
112
  declare function isBuiltInElement(node: TSESTree.Node): boolean;
99
113
  /**
100
- * Check if a node is a `JSXElement` of `User-Defined Component` type
114
+ * Check if a node is a `JSXElement` of user-defined component
101
115
  * @param node The AST node to check
102
116
  * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
103
117
  */
104
118
  declare function isUserDefinedElement(node: TSESTree.Node): boolean;
105
119
 
106
- /**
107
- * Check if a node is a Literal or JSXText
108
- * @param node The AST node to check
109
- * @returns boolean `true` if the node is a Literal or JSXText
110
- */
111
- declare const isLiteral: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXText | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral;
112
- /**
113
- * Check if a Literal or JSXText node is whitespace
114
- * @param node The AST node to check
115
- * @returns boolean `true` if the node is whitespace
116
- */
117
- declare function isWhiteSpace(node: TSESTree.JSXText | TSESTree.Literal): boolean;
118
- /**
119
- * Check if a Literal or JSXText node is a line break
120
- * @param node The AST node to check
121
- * @returns boolean
122
- */
123
- declare function isLineBreak(node: TSESTree.Node): boolean;
124
- /**
125
- * Check if a Literal or JSXText node is padding spaces
126
- * @param node The AST node to check
127
- * @returns boolean
128
- */
129
- declare function isPaddingSpaces(node: TSESTree.Node): boolean;
130
-
131
120
  /**
132
121
  * Get the stringified representation of a JSX node
133
122
  * @param node The JSX node
@@ -135,4 +124,4 @@ declare function isPaddingSpaces(node: TSESTree.Node): boolean;
135
124
  */
136
125
  declare function toString(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
137
126
 
138
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
127
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXFragmentLike, isJSXTextLike, isJSXValue, isKeyedElement, isUserDefinedElement, toString };
package/dist/index.d.ts CHANGED
@@ -50,6 +50,20 @@ declare function hasAttribute(name: string, attributes: TSESTree.JSXOpeningEleme
50
50
  declare function hasAnyAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
51
51
  declare function hasEveryAttribute(names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
52
52
 
53
+ /**
54
+ * Check if a node is a `JSXFragment` or a `Fragment` element
55
+ * @param node The AST node to check
56
+ * @returns `true` if the node is a `JSXFragment` or a `Fragment` element
57
+ */
58
+ declare function isJSXFragmentLike(node: TSESTree.Node | null | _): boolean;
59
+
60
+ /**
61
+ * Check if a node is a `JSXText` or a `Literal` node
62
+ * @param node The AST node to check
63
+ * @returns `true` if the node is a `JSXText` or a `Literal` node
64
+ */
65
+ declare function isJSXTextLike(node: TSESTree.Node | null | _): node is TSESTree.JSXText | TSESTree.Literal;
66
+
53
67
  declare const JSXValueHint: {
54
68
  readonly None: 0n;
55
69
  readonly SkipUndefined: bigint;
@@ -91,43 +105,18 @@ declare function isFragmentElement(node: TSESTree.Node): boolean;
91
105
  */
92
106
  declare function isKeyedElement(node: TSESTree.Node, initialScope?: Scope): boolean;
93
107
  /**
94
- * Check if a node is a `JSXFragment` of `Built-in Component` type
108
+ * Check if a node is a `JSXElement` of built-in component
95
109
  * @param node The AST node to check
96
110
  * @returns `true` if the node is a `JSXFragment` of `Built-in Component` type
97
111
  */
98
112
  declare function isBuiltInElement(node: TSESTree.Node): boolean;
99
113
  /**
100
- * Check if a node is a `JSXElement` of `User-Defined Component` type
114
+ * Check if a node is a `JSXElement` of user-defined component
101
115
  * @param node The AST node to check
102
116
  * @returns `true` if the node is a `JSXElement` of `User-Defined Component` type
103
117
  */
104
118
  declare function isUserDefinedElement(node: TSESTree.Node): boolean;
105
119
 
106
- /**
107
- * Check if a node is a Literal or JSXText
108
- * @param node The AST node to check
109
- * @returns boolean `true` if the node is a Literal or JSXText
110
- */
111
- declare const isLiteral: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXText | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral;
112
- /**
113
- * Check if a Literal or JSXText node is whitespace
114
- * @param node The AST node to check
115
- * @returns boolean `true` if the node is whitespace
116
- */
117
- declare function isWhiteSpace(node: TSESTree.JSXText | TSESTree.Literal): boolean;
118
- /**
119
- * Check if a Literal or JSXText node is a line break
120
- * @param node The AST node to check
121
- * @returns boolean
122
- */
123
- declare function isLineBreak(node: TSESTree.Node): boolean;
124
- /**
125
- * Check if a Literal or JSXText node is padding spaces
126
- * @param node The AST node to check
127
- * @returns boolean
128
- */
129
- declare function isPaddingSpaces(node: TSESTree.Node): boolean;
130
-
131
120
  /**
132
121
  * Get the stringified representation of a JSX node
133
122
  * @param node The JSX node
@@ -135,4 +124,4 @@ declare function isPaddingSpaces(node: TSESTree.Node): boolean;
135
124
  */
136
125
  declare function toString(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
137
126
 
138
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
127
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXFragmentLike, isJSXTextLike, isJSXValue, isKeyedElement, isUserDefinedElement, toString };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var AST3 = require('@eslint-react/ast');
3
+ var AST = require('@eslint-react/ast');
4
4
  var eff = require('@eslint-react/eff');
5
5
  var types = require('@typescript-eslint/types');
6
6
  var VAR = require('@eslint-react/var');
@@ -24,7 +24,7 @@ function _interopNamespace(e) {
24
24
  return Object.freeze(n);
25
25
  }
26
26
 
27
- var AST3__namespace = /*#__PURE__*/_interopNamespace(AST3);
27
+ var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
28
28
  var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
29
29
 
30
30
  // src/find-parent-attribute.ts
@@ -32,7 +32,7 @@ function findParentAttribute(node, test = eff.constTrue) {
32
32
  const guard = (node2) => {
33
33
  return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
34
34
  };
35
- return AST3__namespace.findParentNode(node, guard);
35
+ return AST__namespace.findParentNode(node, guard);
36
36
  }
37
37
  function toString(node) {
38
38
  switch (node.type) {
@@ -138,6 +138,29 @@ function hasAnyAttribute(names, attributes, initialScope) {
138
138
  function hasEveryAttribute(names, attributes, initialScope) {
139
139
  return names.every((n) => hasAttribute(n, attributes, initialScope));
140
140
  }
141
+ function isFragmentElement(node) {
142
+ if (node.type !== types.AST_NODE_TYPES.JSXElement) return false;
143
+ return getElementType(node).split(".").at(-1) === "Fragment";
144
+ }
145
+ function isKeyedElement(node, initialScope) {
146
+ return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
147
+ }
148
+ function isBuiltInElement(node) {
149
+ return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
150
+ }
151
+ function isUserDefinedElement(node) {
152
+ return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
153
+ }
154
+
155
+ // src/is-jsx-fragment.ts
156
+ function isJSXFragmentLike(node) {
157
+ if (node == null) return false;
158
+ return node.type === types.AST_NODE_TYPES.JSXFragment || isFragmentElement(node);
159
+ }
160
+ function isJSXTextLike(node) {
161
+ if (node == null) return false;
162
+ return node.type === types.AST_NODE_TYPES.JSXText || node.type === types.AST_NODE_TYPES.Literal;
163
+ }
141
164
  var JSXValueHint = {
142
165
  None: 0n,
143
166
  SkipUndefined: 1n << 0n,
@@ -233,7 +256,7 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
233
256
  if (name === "undefined") {
234
257
  return !(hint & JSXValueHint.SkipUndefined);
235
258
  }
236
- if (AST3__namespace.isJSXTagNameExpression(node)) {
259
+ if (AST__namespace.isJSXTagNameExpression(node)) {
237
260
  return true;
238
261
  }
239
262
  const variable = VAR__namespace.findVariable(name, jsxCtx.getScope(node));
@@ -243,29 +266,6 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
243
266
  }
244
267
  return false;
245
268
  }
246
- function isFragmentElement(node) {
247
- if (node.type !== types.AST_NODE_TYPES.JSXElement) return false;
248
- return getElementType(node).split(".").at(-1) === "Fragment";
249
- }
250
- function isKeyedElement(node, initialScope) {
251
- return node.type === types.AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
252
- }
253
- function isBuiltInElement(node) {
254
- return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
255
- }
256
- function isUserDefinedElement(node) {
257
- return node.type === types.AST_NODE_TYPES.JSXElement && node.openingElement.name.type === types.AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
258
- }
259
- var isLiteral = AST3__namespace.isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText]);
260
- function isWhiteSpace(node) {
261
- return typeof node.value === "string" && node.value.trim() === "";
262
- }
263
- function isLineBreak(node) {
264
- return isLiteral(node) && isWhiteSpace(node) && AST3__namespace.isMultiLine(node);
265
- }
266
- function isPaddingSpaces(node) {
267
- return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
268
- }
269
269
 
270
270
  exports.DEFAULT_JSX_VALUE_HINT = DEFAULT_JSX_VALUE_HINT;
271
271
  exports.JSXValueHint = JSXValueHint;
@@ -279,11 +279,9 @@ exports.hasAttribute = hasAttribute;
279
279
  exports.hasEveryAttribute = hasEveryAttribute;
280
280
  exports.isBuiltInElement = isBuiltInElement;
281
281
  exports.isFragmentElement = isFragmentElement;
282
+ exports.isJSXFragmentLike = isJSXFragmentLike;
283
+ exports.isJSXTextLike = isJSXTextLike;
282
284
  exports.isJSXValue = isJSXValue;
283
285
  exports.isKeyedElement = isKeyedElement;
284
- exports.isLineBreak = isLineBreak;
285
- exports.isLiteral = isLiteral;
286
- exports.isPaddingSpaces = isPaddingSpaces;
287
286
  exports.isUserDefinedElement = isUserDefinedElement;
288
- exports.isWhiteSpace = isWhiteSpace;
289
287
  exports.toString = toString;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import * as AST3 from '@eslint-react/ast';
1
+ import * as AST from '@eslint-react/ast';
2
2
  import { constTrue } from '@eslint-react/eff';
3
3
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
4
4
  import * as VAR from '@eslint-react/var';
@@ -9,7 +9,7 @@ function findParentAttribute(node, test = constTrue) {
9
9
  const guard = (node2) => {
10
10
  return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
11
11
  };
12
- return AST3.findParentNode(node, guard);
12
+ return AST.findParentNode(node, guard);
13
13
  }
14
14
  function toString(node) {
15
15
  switch (node.type) {
@@ -115,6 +115,29 @@ function hasAnyAttribute(names, attributes, initialScope) {
115
115
  function hasEveryAttribute(names, attributes, initialScope) {
116
116
  return names.every((n) => hasAttribute(n, attributes, initialScope));
117
117
  }
118
+ function isFragmentElement(node) {
119
+ if (node.type !== AST_NODE_TYPES.JSXElement) return false;
120
+ return getElementType(node).split(".").at(-1) === "Fragment";
121
+ }
122
+ function isKeyedElement(node, initialScope) {
123
+ return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
124
+ }
125
+ function isBuiltInElement(node) {
126
+ return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
127
+ }
128
+ function isUserDefinedElement(node) {
129
+ return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
130
+ }
131
+
132
+ // src/is-jsx-fragment.ts
133
+ function isJSXFragmentLike(node) {
134
+ if (node == null) return false;
135
+ return node.type === AST_NODE_TYPES.JSXFragment || isFragmentElement(node);
136
+ }
137
+ function isJSXTextLike(node) {
138
+ if (node == null) return false;
139
+ return node.type === AST_NODE_TYPES.JSXText || node.type === AST_NODE_TYPES.Literal;
140
+ }
118
141
  var JSXValueHint = {
119
142
  None: 0n,
120
143
  SkipUndefined: 1n << 0n,
@@ -210,7 +233,7 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
210
233
  if (name === "undefined") {
211
234
  return !(hint & JSXValueHint.SkipUndefined);
212
235
  }
213
- if (AST3.isJSXTagNameExpression(node)) {
236
+ if (AST.isJSXTagNameExpression(node)) {
214
237
  return true;
215
238
  }
216
239
  const variable = VAR.findVariable(name, jsxCtx.getScope(node));
@@ -220,28 +243,5 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
220
243
  }
221
244
  return false;
222
245
  }
223
- function isFragmentElement(node) {
224
- if (node.type !== AST_NODE_TYPES.JSXElement) return false;
225
- return getElementType(node).split(".").at(-1) === "Fragment";
226
- }
227
- function isKeyedElement(node, initialScope) {
228
- return node.type === AST_NODE_TYPES.JSXElement && hasAttribute("key", node.openingElement.attributes, initialScope);
229
- }
230
- function isBuiltInElement(node) {
231
- return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && node.openingElement.name.name.toLowerCase() === node.openingElement.name.name && /^[a-z]/u.test(node.openingElement.name.name);
232
- }
233
- function isUserDefinedElement(node) {
234
- return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[A-Z]/u.test(node.openingElement.name.name);
235
- }
236
- var isLiteral = AST3.isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText]);
237
- function isWhiteSpace(node) {
238
- return typeof node.value === "string" && node.value.trim() === "";
239
- }
240
- function isLineBreak(node) {
241
- return isLiteral(node) && isWhiteSpace(node) && AST3.isMultiLine(node);
242
- }
243
- function isPaddingSpaces(node) {
244
- return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
245
- }
246
246
 
247
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
247
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementType, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isFragmentElement, isJSXFragmentLike, isJSXTextLike, isJSXValue, isKeyedElement, isUserDefinedElement, toString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/jsx",
3
- "version": "1.40.2",
3
+ "version": "1.40.3-next.0",
4
4
  "description": "ESLint React's TSESTree AST utility module for static analysis of JSX.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -39,9 +39,9 @@
39
39
  "@typescript-eslint/types": "^8.29.0",
40
40
  "@typescript-eslint/utils": "^8.29.0",
41
41
  "ts-pattern": "^5.7.0",
42
- "@eslint-react/ast": "1.40.2",
43
- "@eslint-react/eff": "1.40.2",
44
- "@eslint-react/var": "1.40.2"
42
+ "@eslint-react/ast": "1.40.3-next.0",
43
+ "@eslint-react/eff": "1.40.3-next.0",
44
+ "@eslint-react/var": "1.40.3-next.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "tsup": "^8.4.0",