@eslint-react/jsx 1.24.0-next.11 → 1.24.0-next.13

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
@@ -4,19 +4,47 @@ import { Scope } from '@typescript-eslint/scope-manager';
4
4
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
5
5
  import * as VAR from '@eslint-react/var';
6
6
 
7
- declare function findParentAttributeNode(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
7
+ /**
8
+ * Find the parent JSX attribute node of a node
9
+ * @param node The node to find the parent attribute of
10
+ * @param test The test to apply to the parent attribute
11
+ * @returns The parent attribute node or undefined
12
+ */
13
+ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
14
+
15
+ /**
16
+ * Get the JSX attribute node with the given name
17
+ * @param name The name of the attribute
18
+ * @param initialScope The initial scope to use for variable resolution
19
+ * @param attributes The attributes to search
20
+ * @returns The JSX attribute node or undefined
21
+ */
22
+ declare function getAttribute(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
8
23
 
24
+ /**
25
+ * Get the stringified name of a JSX attribute
26
+ * @param node The JSX attribute node
27
+ * @returns The name of the attribute
28
+ */
9
29
  declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
10
- declare function getAttributeNode(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
11
30
 
12
- declare function getAttributeStaticValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, initialScope: Scope): VAR.StaticValue;
31
+ /**
32
+ * Get a StaticValue of the attribute value
33
+ * @param node The JSX attribute node
34
+ * @param name The name of the attribute
35
+ * @param initialScope The initial scope to use
36
+ * @returns The StaticValue of the attribute value
37
+ */
38
+ declare function getAttributeValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, name: string, initialScope: Scope): Exclude<VAR.LazyValue, {
39
+ kind: "lazy";
40
+ }>;
13
41
 
14
42
  /**
15
- * Returns the tag name associated with a JSXOpeningElement.
16
- * @param node The visited JSXOpeningElement node object.
17
- * @returns The element's tag name.
43
+ * Get the stringified name of a JSX element
44
+ * @param node The JSX element node
45
+ * @returns The name of the element
18
46
  */
19
- declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
47
+ declare function getElementName(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
20
48
 
21
49
  declare function hasAttribute(name: string, initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
22
50
  declare function hasAnyAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
@@ -52,7 +80,7 @@ declare const JSXValueHint: {
52
80
  };
53
81
  declare const DEFAULT_JSX_VALUE_HINT: bigint;
54
82
  /**
55
- * Check if a node is a JSX value
83
+ * Heruistic decision to determine if a node is a JSX value
56
84
  * @param node The AST node to check
57
85
  * @param jsxCtx The requirements for the check
58
86
  * @param jsxCtx.getScope The function to get the scope of a node
@@ -88,15 +116,11 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
88
116
  */
89
117
  declare function isPaddingSpaces(node: TSESTree.Node): boolean;
90
118
 
91
- declare function toResolvedAttributeValue(name: string, value: VAR.StaticValue): string | undefined;
92
-
93
119
  /**
94
- * Unescape the text content of string literals, e.g. &amp; -> &
95
- * @param text The escaped string literal text.
96
- * @returns The unescaped string literal text.
120
+ * Get the stringified representation of a JSX node
121
+ * @param node The JSX node
122
+ * @returns The stringified representation
97
123
  */
98
- declare function unescapeStringLiteralText(text: string): string;
99
-
100
- declare const xhtmlEntities: Record<string, string>;
124
+ 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;
101
125
 
102
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttributeNode, getAttributeName, getAttributeNode, getAttributeStaticValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toResolvedAttributeValue, unescapeStringLiteralText, xhtmlEntities };
126
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
package/dist/index.d.ts CHANGED
@@ -4,19 +4,47 @@ import { Scope } from '@typescript-eslint/scope-manager';
4
4
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
5
5
  import * as VAR from '@eslint-react/var';
6
6
 
7
- declare function findParentAttributeNode(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
7
+ /**
8
+ * Find the parent JSX attribute node of a node
9
+ * @param node The node to find the parent attribute of
10
+ * @param test The test to apply to the parent attribute
11
+ * @returns The parent attribute node or undefined
12
+ */
13
+ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | _;
14
+
15
+ /**
16
+ * Get the JSX attribute node with the given name
17
+ * @param name The name of the attribute
18
+ * @param initialScope The initial scope to use for variable resolution
19
+ * @param attributes The attributes to search
20
+ * @returns The JSX attribute node or undefined
21
+ */
22
+ declare function getAttribute(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
8
23
 
24
+ /**
25
+ * Get the stringified name of a JSX attribute
26
+ * @param node The JSX attribute node
27
+ * @returns The name of the attribute
28
+ */
9
29
  declare function getAttributeName(node: TSESTree$1.JSXAttribute): string;
10
- declare function getAttributeNode(name: string, initialScope: Scope, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[]): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
11
30
 
12
- declare function getAttributeStaticValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, initialScope: Scope): VAR.StaticValue;
31
+ /**
32
+ * Get a StaticValue of the attribute value
33
+ * @param node The JSX attribute node
34
+ * @param name The name of the attribute
35
+ * @param initialScope The initial scope to use
36
+ * @returns The StaticValue of the attribute value
37
+ */
38
+ declare function getAttributeValue(node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, name: string, initialScope: Scope): Exclude<VAR.LazyValue, {
39
+ kind: "lazy";
40
+ }>;
13
41
 
14
42
  /**
15
- * Returns the tag name associated with a JSXOpeningElement.
16
- * @param node The visited JSXOpeningElement node object.
17
- * @returns The element's tag name.
43
+ * Get the stringified name of a JSX element
44
+ * @param node The JSX element node
45
+ * @returns The name of the element
18
46
  */
19
- declare function getElementName(node: TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment): string;
47
+ declare function getElementName(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
20
48
 
21
49
  declare function hasAttribute(name: string, initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
22
50
  declare function hasAnyAttribute(names: string[], initialScope: Scope, attributes: TSESTree.JSXOpeningElement["attributes"]): boolean;
@@ -52,7 +80,7 @@ declare const JSXValueHint: {
52
80
  };
53
81
  declare const DEFAULT_JSX_VALUE_HINT: bigint;
54
82
  /**
55
- * Check if a node is a JSX value
83
+ * Heruistic decision to determine if a node is a JSX value
56
84
  * @param node The AST node to check
57
85
  * @param jsxCtx The requirements for the check
58
86
  * @param jsxCtx.getScope The function to get the scope of a node
@@ -88,15 +116,11 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
88
116
  */
89
117
  declare function isPaddingSpaces(node: TSESTree.Node): boolean;
90
118
 
91
- declare function toResolvedAttributeValue(name: string, value: VAR.StaticValue): string | undefined;
92
-
93
119
  /**
94
- * Unescape the text content of string literals, e.g. &amp; -> &
95
- * @param text The escaped string literal text.
96
- * @returns The unescaped string literal text.
120
+ * Get the stringified representation of a JSX node
121
+ * @param node The JSX node
122
+ * @returns The stringified representation
97
123
  */
98
- declare function unescapeStringLiteralText(text: string): string;
99
-
100
- declare const xhtmlEntities: Record<string, string>;
124
+ 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;
101
125
 
102
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttributeNode, getAttributeName, getAttributeNode, getAttributeStaticValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toResolvedAttributeValue, unescapeStringLiteralText, xhtmlEntities };
126
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
package/dist/index.js CHANGED
@@ -27,22 +27,41 @@ function _interopNamespace(e) {
27
27
  var AST3__namespace = /*#__PURE__*/_interopNamespace(AST3);
28
28
  var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
29
29
 
30
- // src/find-parent-attribute-node.ts
31
- function findParentAttributeNode(node, test = eff.returnTrue) {
30
+ // src/find-parent-attribute.ts
31
+ function findParentAttribute(node, test = eff.returnTrue) {
32
32
  const guard = (node2) => {
33
33
  return node2.type === types.AST_NODE_TYPES.JSXAttribute && test(node2);
34
34
  };
35
35
  return AST3__namespace.findParentNode(node, guard);
36
36
  }
37
- function getAttributeName(node) {
38
- switch (node.name.type) {
37
+ function toString(node) {
38
+ switch (node.type) {
39
39
  case types.AST_NODE_TYPES.JSXIdentifier:
40
- return node.name.name;
40
+ return node.name;
41
41
  case types.AST_NODE_TYPES.JSXNamespacedName:
42
- return `${node.name.namespace.name}:${node.name.name.name}`;
42
+ return `${node.namespace.name}:${node.name.name}`;
43
+ case types.AST_NODE_TYPES.JSXMemberExpression:
44
+ return `${toString(node.object)}.${toString(node.property)}`;
45
+ case types.AST_NODE_TYPES.JSXText:
46
+ return node.value;
47
+ case types.AST_NODE_TYPES.JSXOpeningElement:
48
+ return `<${toString(node.name)}>`;
49
+ case types.AST_NODE_TYPES.JSXClosingElement:
50
+ return `</${toString(node.name)}>`;
51
+ case types.AST_NODE_TYPES.JSXOpeningFragment:
52
+ return "<>";
53
+ case types.AST_NODE_TYPES.JSXClosingFragment:
54
+ return "</>";
43
55
  }
44
56
  }
45
- function getAttributeNode(name, initialScope, attributes) {
57
+
58
+ // src/get-attribute-name.ts
59
+ function getAttributeName(node) {
60
+ return toString(node.name);
61
+ }
62
+
63
+ // src/get-attribute.ts
64
+ function getAttribute(name, initialScope, attributes) {
46
65
  return attributes.findLast((attr) => {
47
66
  if (attr.type === types.AST_NODE_TYPES.JSXAttribute) {
48
67
  return getAttributeName(attr) === name;
@@ -62,7 +81,7 @@ function getAttributeNode(name, initialScope, attributes) {
62
81
  return false;
63
82
  });
64
83
  }
65
- function getAttributeStaticValue(node, initialScope) {
84
+ function getAttributeValue(node, name, initialScope) {
66
85
  switch (node.type) {
67
86
  case types.AST_NODE_TYPES.JSXAttribute:
68
87
  if (node.value?.type === types.AST_NODE_TYPES.Literal) {
@@ -74,50 +93,43 @@ function getAttributeStaticValue(node, initialScope) {
74
93
  };
75
94
  }
76
95
  if (node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) {
77
- return {
96
+ return VAR__namespace.toStaticValue({
78
97
  kind: "lazy",
79
98
  node: node.value.expression,
80
99
  initialScope
81
- };
100
+ });
82
101
  }
83
102
  return { kind: "none", node, initialScope };
84
- case types.AST_NODE_TYPES.JSXSpreadAttribute:
85
- return {
103
+ case types.AST_NODE_TYPES.JSXSpreadAttribute: {
104
+ const staticValue = VAR__namespace.toStaticValue({
86
105
  kind: "lazy",
87
106
  node: node.argument,
88
107
  initialScope
89
- };
108
+ });
109
+ if (staticValue.kind === "none") {
110
+ return staticValue;
111
+ }
112
+ return tsPattern.match(staticValue.value).with({ [name]: tsPattern.P.select(tsPattern.P.any) }, (value) => ({
113
+ kind: "some",
114
+ node: node.argument,
115
+ initialScope,
116
+ value
117
+ })).otherwise(() => ({ kind: "none", node, initialScope }));
118
+ }
90
119
  default:
91
120
  return { kind: "none", node, initialScope };
92
121
  }
93
122
  }
94
- function resolveJSXMemberExpressions(object, property) {
95
- if (object.type === types.AST_NODE_TYPES.JSXMemberExpression) {
96
- return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
97
- }
98
- if (object.type === types.AST_NODE_TYPES.JSXNamespacedName) {
99
- return `${object.namespace.name}:${object.name.name}.${property.name}`;
100
- }
101
- return `${object.name}.${property.name}`;
102
- }
103
123
  function getElementName(node) {
104
- if (node.type === types.AST_NODE_TYPES.JSXOpeningFragment) {
105
- return "<>";
124
+ if (node.type === types.AST_NODE_TYPES.JSXFragment) {
125
+ return "";
106
126
  }
107
- const { name } = node;
108
- if (name.type === types.AST_NODE_TYPES.JSXMemberExpression) {
109
- const { object, property } = name;
110
- return resolveJSXMemberExpressions(object, property);
111
- }
112
- if (name.type === types.AST_NODE_TYPES.JSXNamespacedName) {
113
- return `${name.namespace.name}:${name.name.name}`;
114
- }
115
- return name.name;
127
+ return toString(node.openingElement.name);
116
128
  }
117
129
 
118
130
  // src/has-attribute.ts
119
131
  function hasAttribute(name, initialScope, attributes) {
120
- return getAttributeNode(name, initialScope, attributes) != null;
132
+ return getAttribute(name, initialScope, attributes) != null;
121
133
  }
122
134
  function hasAnyAttribute(names, initialScope, attributes) {
123
135
  return names.some((n) => hasAttribute(n, initialScope, attributes));
@@ -249,285 +261,13 @@ function isLineBreak(node) {
249
261
  function isPaddingSpaces(node) {
250
262
  return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
251
263
  }
252
- function toResolvedAttributeValue(name, value) {
253
- return tsPattern.match(VAR__namespace.toResolved(value).value).with(tsPattern.P.string, eff.identity).with({ [name]: tsPattern.P.select(tsPattern.P.string) }, eff.identity).otherwise(() => eff._);
254
- }
255
-
256
- // src/xhtml-entities.ts
257
- var xhtmlEntities = {
258
- Aacute: "\xC1",
259
- aacute: "\xE1",
260
- Acirc: "\xC2",
261
- acirc: "\xE2",
262
- acute: "\xB4",
263
- AElig: "\xC6",
264
- aelig: "\xE6",
265
- Agrave: "\xC0",
266
- agrave: "\xE0",
267
- alefsym: "\u2135",
268
- Alpha: "\u0391",
269
- alpha: "\u03B1",
270
- amp: "&",
271
- and: "\u2227",
272
- ang: "\u2220",
273
- apos: "'",
274
- Aring: "\xC5",
275
- aring: "\xE5",
276
- asymp: "\u2248",
277
- Atilde: "\xC3",
278
- atilde: "\xE3",
279
- Auml: "\xC4",
280
- auml: "\xE4",
281
- bdquo: "\u201E",
282
- Beta: "\u0392",
283
- beta: "\u03B2",
284
- brvbar: "\xA6",
285
- bull: "\u2022",
286
- cap: "\u2229",
287
- Ccedil: "\xC7",
288
- ccedil: "\xE7",
289
- cedil: "\xB8",
290
- cent: "\xA2",
291
- Chi: "\u03A7",
292
- chi: "\u03C7",
293
- circ: "\u02C6",
294
- clubs: "\u2663",
295
- cong: "\u2245",
296
- copy: "\xA9",
297
- crarr: "\u21B5",
298
- cup: "\u222A",
299
- curren: "\xA4",
300
- dagger: "\u2020",
301
- Dagger: "\u2021",
302
- darr: "\u2193",
303
- dArr: "\u21D3",
304
- deg: "\xB0",
305
- Delta: "\u0394",
306
- delta: "\u03B4",
307
- diams: "\u2666",
308
- divide: "\xF7",
309
- Eacute: "\xC9",
310
- eacute: "\xE9",
311
- Ecirc: "\xCA",
312
- ecirc: "\xEA",
313
- Egrave: "\xC8",
314
- egrave: "\xE8",
315
- empty: "\u2205",
316
- emsp: "\u2003",
317
- ensp: "\u2002",
318
- Epsilon: "\u0395",
319
- epsilon: "\u03B5",
320
- equiv: "\u2261",
321
- Eta: "\u0397",
322
- eta: "\u03B7",
323
- ETH: "\xD0",
324
- eth: "\xF0",
325
- Euml: "\xCB",
326
- euml: "\xEB",
327
- euro: "\u20AC",
328
- exist: "\u2203",
329
- fnof: "\u0192",
330
- forall: "\u2200",
331
- frac12: "\xBD",
332
- frac14: "\xBC",
333
- frac34: "\xBE",
334
- frasl: "\u2044",
335
- Gamma: "\u0393",
336
- gamma: "\u03B3",
337
- ge: "\u2265",
338
- gt: ">",
339
- harr: "\u2194",
340
- hArr: "\u21D4",
341
- hearts: "\u2665",
342
- hellip: "\u2026",
343
- Iacute: "\xCD",
344
- iacute: "\xED",
345
- Icirc: "\xCE",
346
- icirc: "\xEE",
347
- iexcl: "\xA1",
348
- Igrave: "\xCC",
349
- igrave: "\xEC",
350
- image: "\u2111",
351
- infin: "\u221E",
352
- int: "\u222B",
353
- Iota: "\u0399",
354
- iota: "\u03B9",
355
- iquest: "\xBF",
356
- isin: "\u2208",
357
- Iuml: "\xCF",
358
- iuml: "\xEF",
359
- Kappa: "\u039A",
360
- kappa: "\u03BA",
361
- Lambda: "\u039B",
362
- lambda: "\u03BB",
363
- lang: "\u2329",
364
- laquo: "\xAB",
365
- larr: "\u2190",
366
- lArr: "\u21D0",
367
- lceil: "\u2308",
368
- ldquo: "\u201C",
369
- le: "\u2264",
370
- lfloor: "\u230A",
371
- lowast: "\u2217",
372
- loz: "\u25CA",
373
- lrm: "\u200E",
374
- lsaquo: "\u2039",
375
- lsquo: "\u2018",
376
- lt: "<",
377
- macr: "\xAF",
378
- mdash: "\u2014",
379
- micro: "\xB5",
380
- middot: "\xB7",
381
- minus: "\u2212",
382
- Mu: "\u039C",
383
- mu: "\u03BC",
384
- nabla: "\u2207",
385
- nbsp: "\xA0",
386
- ndash: "\u2013",
387
- ne: "\u2260",
388
- ni: "\u220B",
389
- not: "\xAC",
390
- notin: "\u2209",
391
- nsub: "\u2284",
392
- Ntilde: "\xD1",
393
- ntilde: "\xF1",
394
- Nu: "\u039D",
395
- nu: "\u03BD",
396
- Oacute: "\xD3",
397
- oacute: "\xF3",
398
- Ocirc: "\xD4",
399
- ocirc: "\xF4",
400
- OElig: "\u0152",
401
- oelig: "\u0153",
402
- Ograve: "\xD2",
403
- ograve: "\xF2",
404
- oline: "\u203E",
405
- Omega: "\u03A9",
406
- omega: "\u03C9",
407
- Omicron: "\u039F",
408
- omicron: "\u03BF",
409
- oplus: "\u2295",
410
- or: "\u2228",
411
- ordf: "\xAA",
412
- ordm: "\xBA",
413
- Oslash: "\xD8",
414
- oslash: "\xF8",
415
- Otilde: "\xD5",
416
- otilde: "\xF5",
417
- otimes: "\u2297",
418
- Ouml: "\xD6",
419
- ouml: "\xF6",
420
- para: "\xB6",
421
- part: "\u2202",
422
- permil: "\u2030",
423
- perp: "\u22A5",
424
- Phi: "\u03A6",
425
- phi: "\u03C6",
426
- Pi: "\u03A0",
427
- pi: "\u03C0",
428
- piv: "\u03D6",
429
- plusmn: "\xB1",
430
- pound: "\xA3",
431
- prime: "\u2032",
432
- Prime: "\u2033",
433
- prod: "\u220F",
434
- prop: "\u221D",
435
- Psi: "\u03A8",
436
- psi: "\u03C8",
437
- quot: '"',
438
- radic: "\u221A",
439
- rang: "\u232A",
440
- raquo: "\xBB",
441
- rarr: "\u2192",
442
- rArr: "\u21D2",
443
- rceil: "\u2309",
444
- rdquo: "\u201D",
445
- real: "\u211C",
446
- reg: "\xAE",
447
- rfloor: "\u230B",
448
- Rho: "\u03A1",
449
- rho: "\u03C1",
450
- rlm: "\u200F",
451
- rsaquo: "\u203A",
452
- rsquo: "\u2019",
453
- sbquo: "\u201A",
454
- Scaron: "\u0160",
455
- scaron: "\u0161",
456
- sdot: "\u22C5",
457
- sect: "\xA7",
458
- shy: "\xAD",
459
- Sigma: "\u03A3",
460
- sigma: "\u03C3",
461
- sigmaf: "\u03C2",
462
- sim: "\u223C",
463
- spades: "\u2660",
464
- sub: "\u2282",
465
- sube: "\u2286",
466
- sum: "\u2211",
467
- sup: "\u2283",
468
- sup1: "\xB9",
469
- sup2: "\xB2",
470
- sup3: "\xB3",
471
- supe: "\u2287",
472
- szlig: "\xDF",
473
- Tau: "\u03A4",
474
- tau: "\u03C4",
475
- there4: "\u2234",
476
- Theta: "\u0398",
477
- theta: "\u03B8",
478
- thetasym: "\u03D1",
479
- thinsp: "\u2009",
480
- THORN: "\xDE",
481
- thorn: "\xFE",
482
- tilde: "\u02DC",
483
- times: "\xD7",
484
- trade: "\u2122",
485
- Uacute: "\xDA",
486
- uacute: "\xFA",
487
- uarr: "\u2191",
488
- uArr: "\u21D1",
489
- Ucirc: "\xDB",
490
- ucirc: "\xFB",
491
- Ugrave: "\xD9",
492
- ugrave: "\xF9",
493
- uml: "\xA8",
494
- upsih: "\u03D2",
495
- Upsilon: "\u03A5",
496
- upsilon: "\u03C5",
497
- Uuml: "\xDC",
498
- uuml: "\xFC",
499
- weierp: "\u2118",
500
- Xi: "\u039E",
501
- xi: "\u03BE",
502
- Yacute: "\xDD",
503
- yacute: "\xFD",
504
- yen: "\xA5",
505
- yuml: "\xFF",
506
- Yuml: "\u0178",
507
- Zeta: "\u0396",
508
- zeta: "\u03B6",
509
- zwj: "\u200D",
510
- zwnj: "\u200C"
511
- };
512
-
513
- // src/unescape-string-literal-text.ts
514
- function unescapeStringLiteralText(text) {
515
- return text.replaceAll(/&(?:#\d+|#x[\da-fA-F]+|[0-9a-zA-Z]+);/g, (entity) => {
516
- const item = entity.slice(1, -1);
517
- if (item[0] === "#") {
518
- const codePoint = item[1] === "x" ? parseInt(item.slice(2), 16) : parseInt(item.slice(1), 10);
519
- return codePoint > 1114111 ? entity : String.fromCodePoint(codePoint);
520
- }
521
- return xhtmlEntities[item] ?? entity;
522
- });
523
- }
524
264
 
525
265
  exports.DEFAULT_JSX_VALUE_HINT = DEFAULT_JSX_VALUE_HINT;
526
266
  exports.JSXValueHint = JSXValueHint;
527
- exports.findParentAttributeNode = findParentAttributeNode;
267
+ exports.findParentAttribute = findParentAttribute;
268
+ exports.getAttribute = getAttribute;
528
269
  exports.getAttributeName = getAttributeName;
529
- exports.getAttributeNode = getAttributeNode;
530
- exports.getAttributeStaticValue = getAttributeStaticValue;
270
+ exports.getAttributeValue = getAttributeValue;
531
271
  exports.getElementName = getElementName;
532
272
  exports.hasAnyAttribute = hasAnyAttribute;
533
273
  exports.hasAttribute = hasAttribute;
@@ -540,6 +280,4 @@ exports.isLiteral = isLiteral;
540
280
  exports.isPaddingSpaces = isPaddingSpaces;
541
281
  exports.isUserDefinedElement = isUserDefinedElement;
542
282
  exports.isWhiteSpace = isWhiteSpace;
543
- exports.toResolvedAttributeValue = toResolvedAttributeValue;
544
- exports.unescapeStringLiteralText = unescapeStringLiteralText;
545
- exports.xhtmlEntities = xhtmlEntities;
283
+ exports.toString = toString;
package/dist/index.mjs CHANGED
@@ -1,25 +1,44 @@
1
1
  import * as AST3 from '@eslint-react/ast';
2
- import { returnTrue, identity, _ } from '@eslint-react/eff';
2
+ import { returnTrue } from '@eslint-react/eff';
3
3
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
4
4
  import * as VAR from '@eslint-react/var';
5
5
  import { match, P } from 'ts-pattern';
6
6
 
7
- // src/find-parent-attribute-node.ts
8
- function findParentAttributeNode(node, test = returnTrue) {
7
+ // src/find-parent-attribute.ts
8
+ function findParentAttribute(node, test = returnTrue) {
9
9
  const guard = (node2) => {
10
10
  return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
11
11
  };
12
12
  return AST3.findParentNode(node, guard);
13
13
  }
14
- function getAttributeName(node) {
15
- switch (node.name.type) {
14
+ function toString(node) {
15
+ switch (node.type) {
16
16
  case AST_NODE_TYPES.JSXIdentifier:
17
- return node.name.name;
17
+ return node.name;
18
18
  case AST_NODE_TYPES.JSXNamespacedName:
19
- return `${node.name.namespace.name}:${node.name.name.name}`;
19
+ return `${node.namespace.name}:${node.name.name}`;
20
+ case AST_NODE_TYPES.JSXMemberExpression:
21
+ return `${toString(node.object)}.${toString(node.property)}`;
22
+ case AST_NODE_TYPES.JSXText:
23
+ return node.value;
24
+ case AST_NODE_TYPES.JSXOpeningElement:
25
+ return `<${toString(node.name)}>`;
26
+ case AST_NODE_TYPES.JSXClosingElement:
27
+ return `</${toString(node.name)}>`;
28
+ case AST_NODE_TYPES.JSXOpeningFragment:
29
+ return "<>";
30
+ case AST_NODE_TYPES.JSXClosingFragment:
31
+ return "</>";
20
32
  }
21
33
  }
22
- function getAttributeNode(name, initialScope, attributes) {
34
+
35
+ // src/get-attribute-name.ts
36
+ function getAttributeName(node) {
37
+ return toString(node.name);
38
+ }
39
+
40
+ // src/get-attribute.ts
41
+ function getAttribute(name, initialScope, attributes) {
23
42
  return attributes.findLast((attr) => {
24
43
  if (attr.type === AST_NODE_TYPES.JSXAttribute) {
25
44
  return getAttributeName(attr) === name;
@@ -39,7 +58,7 @@ function getAttributeNode(name, initialScope, attributes) {
39
58
  return false;
40
59
  });
41
60
  }
42
- function getAttributeStaticValue(node, initialScope) {
61
+ function getAttributeValue(node, name, initialScope) {
43
62
  switch (node.type) {
44
63
  case AST_NODE_TYPES.JSXAttribute:
45
64
  if (node.value?.type === AST_NODE_TYPES.Literal) {
@@ -51,50 +70,43 @@ function getAttributeStaticValue(node, initialScope) {
51
70
  };
52
71
  }
53
72
  if (node.value?.type === AST_NODE_TYPES.JSXExpressionContainer) {
54
- return {
73
+ return VAR.toStaticValue({
55
74
  kind: "lazy",
56
75
  node: node.value.expression,
57
76
  initialScope
58
- };
77
+ });
59
78
  }
60
79
  return { kind: "none", node, initialScope };
61
- case AST_NODE_TYPES.JSXSpreadAttribute:
62
- return {
80
+ case AST_NODE_TYPES.JSXSpreadAttribute: {
81
+ const staticValue = VAR.toStaticValue({
63
82
  kind: "lazy",
64
83
  node: node.argument,
65
84
  initialScope
66
- };
85
+ });
86
+ if (staticValue.kind === "none") {
87
+ return staticValue;
88
+ }
89
+ return match(staticValue.value).with({ [name]: P.select(P.any) }, (value) => ({
90
+ kind: "some",
91
+ node: node.argument,
92
+ initialScope,
93
+ value
94
+ })).otherwise(() => ({ kind: "none", node, initialScope }));
95
+ }
67
96
  default:
68
97
  return { kind: "none", node, initialScope };
69
98
  }
70
99
  }
71
- function resolveJSXMemberExpressions(object, property) {
72
- if (object.type === AST_NODE_TYPES.JSXMemberExpression) {
73
- return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
74
- }
75
- if (object.type === AST_NODE_TYPES.JSXNamespacedName) {
76
- return `${object.namespace.name}:${object.name.name}.${property.name}`;
77
- }
78
- return `${object.name}.${property.name}`;
79
- }
80
100
  function getElementName(node) {
81
- if (node.type === AST_NODE_TYPES.JSXOpeningFragment) {
82
- return "<>";
101
+ if (node.type === AST_NODE_TYPES.JSXFragment) {
102
+ return "";
83
103
  }
84
- const { name } = node;
85
- if (name.type === AST_NODE_TYPES.JSXMemberExpression) {
86
- const { object, property } = name;
87
- return resolveJSXMemberExpressions(object, property);
88
- }
89
- if (name.type === AST_NODE_TYPES.JSXNamespacedName) {
90
- return `${name.namespace.name}:${name.name.name}`;
91
- }
92
- return name.name;
104
+ return toString(node.openingElement.name);
93
105
  }
94
106
 
95
107
  // src/has-attribute.ts
96
108
  function hasAttribute(name, initialScope, attributes) {
97
- return getAttributeNode(name, initialScope, attributes) != null;
109
+ return getAttribute(name, initialScope, attributes) != null;
98
110
  }
99
111
  function hasAnyAttribute(names, initialScope, attributes) {
100
112
  return names.some((n) => hasAttribute(n, initialScope, attributes));
@@ -226,277 +238,5 @@ function isLineBreak(node) {
226
238
  function isPaddingSpaces(node) {
227
239
  return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
228
240
  }
229
- function toResolvedAttributeValue(name, value) {
230
- return match(VAR.toResolved(value).value).with(P.string, identity).with({ [name]: P.select(P.string) }, identity).otherwise(() => _);
231
- }
232
-
233
- // src/xhtml-entities.ts
234
- var xhtmlEntities = {
235
- Aacute: "\xC1",
236
- aacute: "\xE1",
237
- Acirc: "\xC2",
238
- acirc: "\xE2",
239
- acute: "\xB4",
240
- AElig: "\xC6",
241
- aelig: "\xE6",
242
- Agrave: "\xC0",
243
- agrave: "\xE0",
244
- alefsym: "\u2135",
245
- Alpha: "\u0391",
246
- alpha: "\u03B1",
247
- amp: "&",
248
- and: "\u2227",
249
- ang: "\u2220",
250
- apos: "'",
251
- Aring: "\xC5",
252
- aring: "\xE5",
253
- asymp: "\u2248",
254
- Atilde: "\xC3",
255
- atilde: "\xE3",
256
- Auml: "\xC4",
257
- auml: "\xE4",
258
- bdquo: "\u201E",
259
- Beta: "\u0392",
260
- beta: "\u03B2",
261
- brvbar: "\xA6",
262
- bull: "\u2022",
263
- cap: "\u2229",
264
- Ccedil: "\xC7",
265
- ccedil: "\xE7",
266
- cedil: "\xB8",
267
- cent: "\xA2",
268
- Chi: "\u03A7",
269
- chi: "\u03C7",
270
- circ: "\u02C6",
271
- clubs: "\u2663",
272
- cong: "\u2245",
273
- copy: "\xA9",
274
- crarr: "\u21B5",
275
- cup: "\u222A",
276
- curren: "\xA4",
277
- dagger: "\u2020",
278
- Dagger: "\u2021",
279
- darr: "\u2193",
280
- dArr: "\u21D3",
281
- deg: "\xB0",
282
- Delta: "\u0394",
283
- delta: "\u03B4",
284
- diams: "\u2666",
285
- divide: "\xF7",
286
- Eacute: "\xC9",
287
- eacute: "\xE9",
288
- Ecirc: "\xCA",
289
- ecirc: "\xEA",
290
- Egrave: "\xC8",
291
- egrave: "\xE8",
292
- empty: "\u2205",
293
- emsp: "\u2003",
294
- ensp: "\u2002",
295
- Epsilon: "\u0395",
296
- epsilon: "\u03B5",
297
- equiv: "\u2261",
298
- Eta: "\u0397",
299
- eta: "\u03B7",
300
- ETH: "\xD0",
301
- eth: "\xF0",
302
- Euml: "\xCB",
303
- euml: "\xEB",
304
- euro: "\u20AC",
305
- exist: "\u2203",
306
- fnof: "\u0192",
307
- forall: "\u2200",
308
- frac12: "\xBD",
309
- frac14: "\xBC",
310
- frac34: "\xBE",
311
- frasl: "\u2044",
312
- Gamma: "\u0393",
313
- gamma: "\u03B3",
314
- ge: "\u2265",
315
- gt: ">",
316
- harr: "\u2194",
317
- hArr: "\u21D4",
318
- hearts: "\u2665",
319
- hellip: "\u2026",
320
- Iacute: "\xCD",
321
- iacute: "\xED",
322
- Icirc: "\xCE",
323
- icirc: "\xEE",
324
- iexcl: "\xA1",
325
- Igrave: "\xCC",
326
- igrave: "\xEC",
327
- image: "\u2111",
328
- infin: "\u221E",
329
- int: "\u222B",
330
- Iota: "\u0399",
331
- iota: "\u03B9",
332
- iquest: "\xBF",
333
- isin: "\u2208",
334
- Iuml: "\xCF",
335
- iuml: "\xEF",
336
- Kappa: "\u039A",
337
- kappa: "\u03BA",
338
- Lambda: "\u039B",
339
- lambda: "\u03BB",
340
- lang: "\u2329",
341
- laquo: "\xAB",
342
- larr: "\u2190",
343
- lArr: "\u21D0",
344
- lceil: "\u2308",
345
- ldquo: "\u201C",
346
- le: "\u2264",
347
- lfloor: "\u230A",
348
- lowast: "\u2217",
349
- loz: "\u25CA",
350
- lrm: "\u200E",
351
- lsaquo: "\u2039",
352
- lsquo: "\u2018",
353
- lt: "<",
354
- macr: "\xAF",
355
- mdash: "\u2014",
356
- micro: "\xB5",
357
- middot: "\xB7",
358
- minus: "\u2212",
359
- Mu: "\u039C",
360
- mu: "\u03BC",
361
- nabla: "\u2207",
362
- nbsp: "\xA0",
363
- ndash: "\u2013",
364
- ne: "\u2260",
365
- ni: "\u220B",
366
- not: "\xAC",
367
- notin: "\u2209",
368
- nsub: "\u2284",
369
- Ntilde: "\xD1",
370
- ntilde: "\xF1",
371
- Nu: "\u039D",
372
- nu: "\u03BD",
373
- Oacute: "\xD3",
374
- oacute: "\xF3",
375
- Ocirc: "\xD4",
376
- ocirc: "\xF4",
377
- OElig: "\u0152",
378
- oelig: "\u0153",
379
- Ograve: "\xD2",
380
- ograve: "\xF2",
381
- oline: "\u203E",
382
- Omega: "\u03A9",
383
- omega: "\u03C9",
384
- Omicron: "\u039F",
385
- omicron: "\u03BF",
386
- oplus: "\u2295",
387
- or: "\u2228",
388
- ordf: "\xAA",
389
- ordm: "\xBA",
390
- Oslash: "\xD8",
391
- oslash: "\xF8",
392
- Otilde: "\xD5",
393
- otilde: "\xF5",
394
- otimes: "\u2297",
395
- Ouml: "\xD6",
396
- ouml: "\xF6",
397
- para: "\xB6",
398
- part: "\u2202",
399
- permil: "\u2030",
400
- perp: "\u22A5",
401
- Phi: "\u03A6",
402
- phi: "\u03C6",
403
- Pi: "\u03A0",
404
- pi: "\u03C0",
405
- piv: "\u03D6",
406
- plusmn: "\xB1",
407
- pound: "\xA3",
408
- prime: "\u2032",
409
- Prime: "\u2033",
410
- prod: "\u220F",
411
- prop: "\u221D",
412
- Psi: "\u03A8",
413
- psi: "\u03C8",
414
- quot: '"',
415
- radic: "\u221A",
416
- rang: "\u232A",
417
- raquo: "\xBB",
418
- rarr: "\u2192",
419
- rArr: "\u21D2",
420
- rceil: "\u2309",
421
- rdquo: "\u201D",
422
- real: "\u211C",
423
- reg: "\xAE",
424
- rfloor: "\u230B",
425
- Rho: "\u03A1",
426
- rho: "\u03C1",
427
- rlm: "\u200F",
428
- rsaquo: "\u203A",
429
- rsquo: "\u2019",
430
- sbquo: "\u201A",
431
- Scaron: "\u0160",
432
- scaron: "\u0161",
433
- sdot: "\u22C5",
434
- sect: "\xA7",
435
- shy: "\xAD",
436
- Sigma: "\u03A3",
437
- sigma: "\u03C3",
438
- sigmaf: "\u03C2",
439
- sim: "\u223C",
440
- spades: "\u2660",
441
- sub: "\u2282",
442
- sube: "\u2286",
443
- sum: "\u2211",
444
- sup: "\u2283",
445
- sup1: "\xB9",
446
- sup2: "\xB2",
447
- sup3: "\xB3",
448
- supe: "\u2287",
449
- szlig: "\xDF",
450
- Tau: "\u03A4",
451
- tau: "\u03C4",
452
- there4: "\u2234",
453
- Theta: "\u0398",
454
- theta: "\u03B8",
455
- thetasym: "\u03D1",
456
- thinsp: "\u2009",
457
- THORN: "\xDE",
458
- thorn: "\xFE",
459
- tilde: "\u02DC",
460
- times: "\xD7",
461
- trade: "\u2122",
462
- Uacute: "\xDA",
463
- uacute: "\xFA",
464
- uarr: "\u2191",
465
- uArr: "\u21D1",
466
- Ucirc: "\xDB",
467
- ucirc: "\xFB",
468
- Ugrave: "\xD9",
469
- ugrave: "\xF9",
470
- uml: "\xA8",
471
- upsih: "\u03D2",
472
- Upsilon: "\u03A5",
473
- upsilon: "\u03C5",
474
- Uuml: "\xDC",
475
- uuml: "\xFC",
476
- weierp: "\u2118",
477
- Xi: "\u039E",
478
- xi: "\u03BE",
479
- Yacute: "\xDD",
480
- yacute: "\xFD",
481
- yen: "\xA5",
482
- yuml: "\xFF",
483
- Yuml: "\u0178",
484
- Zeta: "\u0396",
485
- zeta: "\u03B6",
486
- zwj: "\u200D",
487
- zwnj: "\u200C"
488
- };
489
-
490
- // src/unescape-string-literal-text.ts
491
- function unescapeStringLiteralText(text) {
492
- return text.replaceAll(/&(?:#\d+|#x[\da-fA-F]+|[0-9a-zA-Z]+);/g, (entity) => {
493
- const item = entity.slice(1, -1);
494
- if (item[0] === "#") {
495
- const codePoint = item[1] === "x" ? parseInt(item.slice(2), 16) : parseInt(item.slice(1), 10);
496
- return codePoint > 1114111 ? entity : String.fromCodePoint(codePoint);
497
- }
498
- return xhtmlEntities[item] ?? entity;
499
- });
500
- }
501
241
 
502
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttributeNode, getAttributeName, getAttributeNode, getAttributeStaticValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toResolvedAttributeValue, unescapeStringLiteralText, xhtmlEntities };
242
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getElementName, hasAnyAttribute, hasAttribute, hasEveryAttribute, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, toString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/jsx",
3
- "version": "1.24.0-next.11",
3
+ "version": "1.24.0-next.13",
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": {
@@ -37,9 +37,9 @@
37
37
  "@typescript-eslint/types": "^8.20.0",
38
38
  "@typescript-eslint/utils": "^8.20.0",
39
39
  "ts-pattern": "^5.6.0",
40
- "@eslint-react/ast": "1.24.0-next.11",
41
- "@eslint-react/eff": "1.24.0-next.11",
42
- "@eslint-react/var": "1.24.0-next.11"
40
+ "@eslint-react/ast": "1.24.0-next.13",
41
+ "@eslint-react/eff": "1.24.0-next.13",
42
+ "@eslint-react/var": "1.24.0-next.13"
43
43
  },
44
44
  "devDependencies": {
45
45
  "tsup": "^8.3.5",