@eslint-react/jsx 1.23.2-next.2 → 1.23.2-next.6

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
@@ -1,9 +1,11 @@
1
- import { TSESTree } from '@typescript-eslint/types';
2
1
  import { O } from '@eslint-react/eff';
2
+ import { TSESTree } from '@typescript-eslint/types';
3
3
  import { Scope } from '@typescript-eslint/scope-manager';
4
4
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
5
5
  import * as _eslint_react_types from '@eslint-react/types';
6
6
 
7
+ declare function findParentProp(node: TSESTree.Node, predicate?: (node: TSESTree.JSXAttribute) => boolean): O.Option<TSESTree.JSXAttribute>;
8
+
7
9
  /**
8
10
  * Returns the tag name associated with a JSXOpeningElement.
9
11
  * @param node The visited JSXOpeningElement node object.
@@ -109,7 +111,7 @@ declare function isJSXValue(node: null | TSESTree$1.Node | undefined, jsxCtx: {
109
111
  * @param node The AST node to check
110
112
  * @returns boolean `true` if the node is a Literal or JSXText
111
113
  */
112
- declare const isLiteral: (node: TSESTree.Node | null | undefined) => node is TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.JSXText;
114
+ declare const isLiteral: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXText | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral;
113
115
  /**
114
116
  * Check if a Literal or JSXText node is whitespace
115
117
  * @param node The AST node to check
@@ -129,14 +131,6 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
129
131
  */
130
132
  declare function isPaddingSpaces(node: TSESTree.Node): boolean;
131
133
 
132
- /**
133
- * Traverses up prop node
134
- * @param node The AST node to start traversing from
135
- * @param predicate The predicate to check each node
136
- * @returns prop node if found
137
- */
138
- declare function traverseUpProp(node: TSESTree.Node, predicate?: (node: TSESTree.JSXAttribute) => boolean): O.Option<TSESTree.JSXAttribute>;
139
-
140
134
  /**
141
135
  * Unescape the text content of string literals, e.g. &amp; -> &
142
136
  * @param text The escaped string literal text.
@@ -400,4 +394,4 @@ declare const xhtmlEntities: _eslint_react_types.BiRecord<{
400
394
  readonly zwnj: "‌";
401
395
  }>;
402
396
 
403
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findPropInAttributes, findPropInProperties, getElementName, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp, unescapeStringLiteralText, xhtmlEntities };
397
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentProp, findPropInAttributes, findPropInProperties, getElementName, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, unescapeStringLiteralText, xhtmlEntities };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { TSESTree } from '@typescript-eslint/types';
2
1
  import { O } from '@eslint-react/eff';
2
+ import { TSESTree } from '@typescript-eslint/types';
3
3
  import { Scope } from '@typescript-eslint/scope-manager';
4
4
  import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
5
5
  import * as _eslint_react_types from '@eslint-react/types';
6
6
 
7
+ declare function findParentProp(node: TSESTree.Node, predicate?: (node: TSESTree.JSXAttribute) => boolean): O.Option<TSESTree.JSXAttribute>;
8
+
7
9
  /**
8
10
  * Returns the tag name associated with a JSXOpeningElement.
9
11
  * @param node The visited JSXOpeningElement node object.
@@ -109,7 +111,7 @@ declare function isJSXValue(node: null | TSESTree$1.Node | undefined, jsxCtx: {
109
111
  * @param node The AST node to check
110
112
  * @returns boolean `true` if the node is a Literal or JSXText
111
113
  */
112
- declare const isLiteral: (node: TSESTree.Node | null | undefined) => node is TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.JSXText;
114
+ declare const isLiteral: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXText | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral;
113
115
  /**
114
116
  * Check if a Literal or JSXText node is whitespace
115
117
  * @param node The AST node to check
@@ -129,14 +131,6 @@ declare function isLineBreak(node: TSESTree.Node): boolean;
129
131
  */
130
132
  declare function isPaddingSpaces(node: TSESTree.Node): boolean;
131
133
 
132
- /**
133
- * Traverses up prop node
134
- * @param node The AST node to start traversing from
135
- * @param predicate The predicate to check each node
136
- * @returns prop node if found
137
- */
138
- declare function traverseUpProp(node: TSESTree.Node, predicate?: (node: TSESTree.JSXAttribute) => boolean): O.Option<TSESTree.JSXAttribute>;
139
-
140
134
  /**
141
135
  * Unescape the text content of string literals, e.g. &amp; -> &
142
136
  * @param text The escaped string literal text.
@@ -400,4 +394,4 @@ declare const xhtmlEntities: _eslint_react_types.BiRecord<{
400
394
  readonly zwnj: "‌";
401
395
  }>;
402
396
 
403
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findPropInAttributes, findPropInProperties, getElementName, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp, unescapeStringLiteralText, xhtmlEntities };
397
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentProp, findPropInAttributes, findPropInProperties, getElementName, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, unescapeStringLiteralText, xhtmlEntities };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var types = require('@typescript-eslint/types');
4
- var AST = require('@eslint-react/ast');
3
+ var AST2 = require('@eslint-react/ast');
5
4
  var eff = require('@eslint-react/eff');
5
+ var types = require('@typescript-eslint/types');
6
6
  var VAR = require('@eslint-react/var');
7
7
  var tsPattern = require('ts-pattern');
8
8
  var types$1 = require('@eslint-react/types');
@@ -25,10 +25,16 @@ function _interopNamespace(e) {
25
25
  return Object.freeze(n);
26
26
  }
27
27
 
28
- var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
28
+ var AST2__namespace = /*#__PURE__*/_interopNamespace(AST2);
29
29
  var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
30
30
 
31
- // src/get-element-name.ts
31
+ // src/find-parent-prop.ts
32
+ function findParentProp(node, predicate = eff.F.constTrue) {
33
+ const guard = (node2) => {
34
+ return node2.type === types.AST_NODE_TYPES.JSXAttribute && predicate(node2);
35
+ };
36
+ return AST2__namespace.findParentNodeGuard(node, guard);
37
+ }
32
38
  function resolveJSXMemberExpressions(object, property) {
33
39
  if (object.type === types.AST_NODE_TYPES.JSXMemberExpression) {
34
40
  return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
@@ -87,16 +93,15 @@ function findPropInProperties(properties, initialScope, seenProps = []) {
87
93
  switch (true) {
88
94
  case prop.argument.type === types.AST_NODE_TYPES.Identifier: {
89
95
  const { name } = prop.argument;
90
- const maybeInit = eff.O.flatMap(
91
- VAR__namespace.findVariable(name, initialScope),
92
- VAR__namespace.getVariableNode(0)
93
- );
94
- if (eff.O.isNone(maybeInit)) return false;
95
- const init = maybeInit.value;
96
- if (!AST__namespace.is(types.AST_NODE_TYPES.ObjectExpression)(init)) return false;
97
96
  if (seenProps.includes(name)) return false;
98
- return eff.O.isSome(
99
- findPropInProperties(init.properties, initialScope, [...seenProps, name])(propName)
97
+ return eff.F.pipe(
98
+ VAR__namespace.findVariable(name, initialScope),
99
+ eff.O.flatMap(VAR__namespace.getVariableNode(0)),
100
+ eff.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.ObjectExpression)),
101
+ eff.O.flatMap(
102
+ (init) => findPropInProperties(init.properties, initialScope, [...seenProps, name])(propName)
103
+ ),
104
+ eff.O.isSome
100
105
  );
101
106
  }
102
107
  case prop.argument.type === types.AST_NODE_TYPES.ObjectExpression: {
@@ -130,14 +135,13 @@ function findPropInAttributes(attributes, initialScope) {
130
135
  return false;
131
136
  case types.AST_NODE_TYPES.Identifier: {
132
137
  const { name } = attr.argument;
133
- const maybeInit = eff.O.flatMap(
138
+ return eff.F.pipe(
134
139
  VAR__namespace.findVariable(name, initialScope),
135
- VAR__namespace.getVariableNode(0)
140
+ eff.O.flatMap(VAR__namespace.getVariableNode(0)),
141
+ eff.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.ObjectExpression)),
142
+ eff.O.flatMap((init) => findPropInProperties(init.properties, initialScope)(propName)),
143
+ eff.O.isSome
136
144
  );
137
- if (eff.O.isNone(maybeInit)) return false;
138
- const init = maybeInit.value;
139
- if (!AST__namespace.is(types.AST_NODE_TYPES.ObjectExpression)(init)) return false;
140
- return eff.O.isSome(findPropInProperties(init.properties, initialScope)(propName));
141
145
  }
142
146
  case types.AST_NODE_TYPES.MemberExpression:
143
147
  return false;
@@ -224,7 +228,7 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
224
228
  }).with({ type: types.AST_NODE_TYPES.Identifier }, (node2) => {
225
229
  const { name } = node2;
226
230
  if (name === "undefined") return !(hint & JSXValueHint.SkipUndefinedLiteral);
227
- if (AST__namespace.isJSXTagNameExpression(node2)) return true;
231
+ if (AST2__namespace.isJSXTagNameExpression(node2)) return true;
228
232
  const initialScope = jsxCtx.getScope(node2);
229
233
  return eff.F.pipe(
230
234
  VAR__namespace.findVariable(name, initialScope),
@@ -233,22 +237,16 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
233
237
  );
234
238
  }).otherwise(eff.F.constFalse);
235
239
  }
236
- var isLiteral = AST__namespace.isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText]);
240
+ var isLiteral = AST2__namespace.isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText]);
237
241
  function isWhiteSpace(node) {
238
242
  return eff.isString(node.value) && node.value.trim() === "";
239
243
  }
240
244
  function isLineBreak(node) {
241
- return isLiteral(node) && isWhiteSpace(node) && AST__namespace.isMultiLine(node);
245
+ return isLiteral(node) && isWhiteSpace(node) && AST2__namespace.isMultiLine(node);
242
246
  }
243
247
  function isPaddingSpaces(node) {
244
248
  return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
245
249
  }
246
- function traverseUpProp(node, predicate = eff.F.constTrue) {
247
- const guard = (node2) => {
248
- return node2.type === types.AST_NODE_TYPES.JSXAttribute && predicate(node2);
249
- };
250
- return AST__namespace.traverseUpGuard(node, guard);
251
- }
252
250
  var xhtmlEntities = types$1.birecord({
253
251
  Aacute: "\xC1",
254
252
  aacute: "\xE1",
@@ -519,6 +517,7 @@ function unescapeStringLiteralText(text) {
519
517
 
520
518
  exports.DEFAULT_JSX_VALUE_HINT = DEFAULT_JSX_VALUE_HINT;
521
519
  exports.JSXValueHint = JSXValueHint;
520
+ exports.findParentProp = findParentProp;
522
521
  exports.findPropInAttributes = findPropInAttributes;
523
522
  exports.findPropInProperties = findPropInProperties;
524
523
  exports.getElementName = getElementName;
@@ -536,6 +535,5 @@ exports.isLiteral = isLiteral;
536
535
  exports.isPaddingSpaces = isPaddingSpaces;
537
536
  exports.isUserDefinedElement = isUserDefinedElement;
538
537
  exports.isWhiteSpace = isWhiteSpace;
539
- exports.traverseUpProp = traverseUpProp;
540
538
  exports.unescapeStringLiteralText = unescapeStringLiteralText;
541
539
  exports.xhtmlEntities = xhtmlEntities;
package/dist/index.mjs CHANGED
@@ -1,11 +1,17 @@
1
+ import * as AST2 from '@eslint-react/ast';
2
+ import { F, O, isString } from '@eslint-react/eff';
1
3
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
2
- import * as AST from '@eslint-react/ast';
3
- import { O, F, isString } from '@eslint-react/eff';
4
4
  import * as VAR from '@eslint-react/var';
5
5
  import { match, P } from 'ts-pattern';
6
6
  import { birecord } from '@eslint-react/types';
7
7
 
8
- // src/get-element-name.ts
8
+ // src/find-parent-prop.ts
9
+ function findParentProp(node, predicate = F.constTrue) {
10
+ const guard = (node2) => {
11
+ return node2.type === AST_NODE_TYPES.JSXAttribute && predicate(node2);
12
+ };
13
+ return AST2.findParentNodeGuard(node, guard);
14
+ }
9
15
  function resolveJSXMemberExpressions(object, property) {
10
16
  if (object.type === AST_NODE_TYPES.JSXMemberExpression) {
11
17
  return `${resolveJSXMemberExpressions(object.object, object.property)}.${property.name}`;
@@ -64,16 +70,15 @@ function findPropInProperties(properties, initialScope, seenProps = []) {
64
70
  switch (true) {
65
71
  case prop.argument.type === AST_NODE_TYPES.Identifier: {
66
72
  const { name } = prop.argument;
67
- const maybeInit = O.flatMap(
68
- VAR.findVariable(name, initialScope),
69
- VAR.getVariableNode(0)
70
- );
71
- if (O.isNone(maybeInit)) return false;
72
- const init = maybeInit.value;
73
- if (!AST.is(AST_NODE_TYPES.ObjectExpression)(init)) return false;
74
73
  if (seenProps.includes(name)) return false;
75
- return O.isSome(
76
- findPropInProperties(init.properties, initialScope, [...seenProps, name])(propName)
74
+ return F.pipe(
75
+ VAR.findVariable(name, initialScope),
76
+ O.flatMap(VAR.getVariableNode(0)),
77
+ O.filter(AST2.is(AST_NODE_TYPES.ObjectExpression)),
78
+ O.flatMap(
79
+ (init) => findPropInProperties(init.properties, initialScope, [...seenProps, name])(propName)
80
+ ),
81
+ O.isSome
77
82
  );
78
83
  }
79
84
  case prop.argument.type === AST_NODE_TYPES.ObjectExpression: {
@@ -107,14 +112,13 @@ function findPropInAttributes(attributes, initialScope) {
107
112
  return false;
108
113
  case AST_NODE_TYPES.Identifier: {
109
114
  const { name } = attr.argument;
110
- const maybeInit = O.flatMap(
115
+ return F.pipe(
111
116
  VAR.findVariable(name, initialScope),
112
- VAR.getVariableNode(0)
117
+ O.flatMap(VAR.getVariableNode(0)),
118
+ O.filter(AST2.is(AST_NODE_TYPES.ObjectExpression)),
119
+ O.flatMap((init) => findPropInProperties(init.properties, initialScope)(propName)),
120
+ O.isSome
113
121
  );
114
- if (O.isNone(maybeInit)) return false;
115
- const init = maybeInit.value;
116
- if (!AST.is(AST_NODE_TYPES.ObjectExpression)(init)) return false;
117
- return O.isSome(findPropInProperties(init.properties, initialScope)(propName));
118
122
  }
119
123
  case AST_NODE_TYPES.MemberExpression:
120
124
  return false;
@@ -201,7 +205,7 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
201
205
  }).with({ type: AST_NODE_TYPES.Identifier }, (node2) => {
202
206
  const { name } = node2;
203
207
  if (name === "undefined") return !(hint & JSXValueHint.SkipUndefinedLiteral);
204
- if (AST.isJSXTagNameExpression(node2)) return true;
208
+ if (AST2.isJSXTagNameExpression(node2)) return true;
205
209
  const initialScope = jsxCtx.getScope(node2);
206
210
  return F.pipe(
207
211
  VAR.findVariable(name, initialScope),
@@ -210,22 +214,16 @@ function isJSXValue(node, jsxCtx, hint = DEFAULT_JSX_VALUE_HINT) {
210
214
  );
211
215
  }).otherwise(F.constFalse);
212
216
  }
213
- var isLiteral = AST.isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText]);
217
+ var isLiteral = AST2.isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText]);
214
218
  function isWhiteSpace(node) {
215
219
  return isString(node.value) && node.value.trim() === "";
216
220
  }
217
221
  function isLineBreak(node) {
218
- return isLiteral(node) && isWhiteSpace(node) && AST.isMultiLine(node);
222
+ return isLiteral(node) && isWhiteSpace(node) && AST2.isMultiLine(node);
219
223
  }
220
224
  function isPaddingSpaces(node) {
221
225
  return isLiteral(node) && isWhiteSpace(node) && node.raw.includes("\n");
222
226
  }
223
- function traverseUpProp(node, predicate = F.constTrue) {
224
- const guard = (node2) => {
225
- return node2.type === AST_NODE_TYPES.JSXAttribute && predicate(node2);
226
- };
227
- return AST.traverseUpGuard(node, guard);
228
- }
229
227
  var xhtmlEntities = birecord({
230
228
  Aacute: "\xC1",
231
229
  aacute: "\xE1",
@@ -494,4 +492,4 @@ function unescapeStringLiteralText(text) {
494
492
  });
495
493
  }
496
494
 
497
- export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findPropInAttributes, findPropInProperties, getElementName, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, traverseUpProp, unescapeStringLiteralText, xhtmlEntities };
495
+ export { DEFAULT_JSX_VALUE_HINT, JSXValueHint, findParentProp, findPropInAttributes, findPropInProperties, getElementName, getProp, getPropName, getPropValue, hasAnyProp, hasEveryProp, hasProp, isBuiltInElement, isJSXValue, isKeyedElement, isLineBreak, isLiteral, isPaddingSpaces, isUserDefinedElement, isWhiteSpace, unescapeStringLiteralText, xhtmlEntities };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/jsx",
3
- "version": "1.23.2-next.2",
3
+ "version": "1.23.2-next.6",
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": {
@@ -33,14 +33,14 @@
33
33
  "./package.json"
34
34
  ],
35
35
  "dependencies": {
36
- "@typescript-eslint/scope-manager": "^8.19.0",
37
- "@typescript-eslint/types": "^8.19.0",
38
- "@typescript-eslint/utils": "^8.19.0",
36
+ "@typescript-eslint/scope-manager": "^8.19.1",
37
+ "@typescript-eslint/types": "^8.19.1",
38
+ "@typescript-eslint/utils": "^8.19.1",
39
39
  "ts-pattern": "^5.6.0",
40
- "@eslint-react/ast": "1.23.2-next.2",
41
- "@eslint-react/eff": "1.23.2-next.2",
42
- "@eslint-react/types": "1.23.2-next.2",
43
- "@eslint-react/var": "1.23.2-next.2"
40
+ "@eslint-react/ast": "1.23.2-next.6",
41
+ "@eslint-react/eff": "1.23.2-next.6",
42
+ "@eslint-react/types": "1.23.2-next.6",
43
+ "@eslint-react/var": "1.23.2-next.6"
44
44
  },
45
45
  "devDependencies": {
46
46
  "tsup": "^8.3.5",