@eslint-react/ast 5.30.0-beta.3 → 5.30.0-beta.5

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 CHANGED
@@ -1,30 +1,30 @@
1
1
  import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
2
2
  import { VisitorKeys } from "@typescript-eslint/visitor-keys";
3
- /** Union of function-like node types. */
4
- type TSESTreeFunction = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
5
- /** Union of class-like node types. */
6
- type TSESTreeClass = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
7
- /** Union of function-like and class-like node types. */
8
- type TSESTreeFunctionOrClass = TSESTreeFunction | TSESTreeClass;
9
- /** Union of method and property definition node types. */
10
- type TSESTreeMethodOrPropertyDefinition = TSESTree.PropertyDefinition | TSESTree.MethodDefinition;
11
3
  /** An expression statement that is a directive (ex: `"use strict"`). */
12
4
  type TSESTreeDirective = TSESTree.ExpressionStatement & {
13
5
  directive: string;
14
6
  expression: TSESTree.StringLiteral;
15
7
  };
8
+ /** Union of class-like node types. */
9
+ type TSESTreeClass = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
10
+ /** Union of function-like node types. */
11
+ type TSESTreeFunction = TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression;
12
+ /** Union of function-like and class-like node types. */
13
+ type TSESTreeFunctionOrClass = TSESTreeClass | TSESTreeFunction;
14
+ /** Union of method and property definition node types. */
15
+ type TSESTreeMethodOrPropertyDefinition = TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
16
16
  /** Union of all JSX-related node types. */
17
17
  type TSESTreeJSX = TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
18
- /** Union of JSX element-like node types (element or fragment). */
19
- type TSESTreeJSXElementLike = TSESTree.JSXElement | TSESTree.JSXFragment;
20
18
  /** Union of JSX attribute-like node types (attribute or spread attribute). */
21
19
  type TSESTreeJSXAttributeLike = TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute;
20
+ /** Union of JSX element-like node types (element or fragment). */
21
+ type TSESTreeJSXElementLike = TSESTree.JSXElement | TSESTree.JSXFragment;
22
22
  /** Union of TypeScript type expression node types. */
23
- type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.TSTypeAssertion | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSInstantiationExpression;
23
+ type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
24
24
  /** Union of expression node types that wrap another expression (TypeScript type expressions and chain expressions) — the nodes `Extract.unwrap` strips. */
25
- type TSESTreeTypeOrChainExpression = TSESTreeTypeExpression | TSESTree.ChainExpression;
25
+ type TSESTreeTypeOrChainExpression = TSESTree.ChainExpression | TSESTreeTypeExpression;
26
26
  declare namespace check_d_exports {
27
- export { is, isCallExpression, isClass, isConditional, isDirective, isExpression, isFunction, isFunctionOrClass, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXExpressionContainer, isJSXFragment, isJSXSpreadAttribute, isJSXTagNameExpression, isLoopStatement, isMemberExpression, isObjectExpression, isOneOf, isProperty, isPropertyOrMethod, isReturnStatement, isTypeAssertionExpression, isTypeExpression, isTypeOrChainExpression };
27
+ export { is, isArrayPatternElementDefault, isCallExpression, isClass, isConditional, isDirective, isExpression, isFunction, isFunctionOrClass, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXExpressionContainer, isJSXFragment, isJSXSpreadAttribute, isJSXTagNameExpression, isLoopStatement, isMemberExpression, isObjectExpression, isObjectPatternElementDefault, isOneOf, isProperty, isPropertyOrMethod, isReturnStatement, isTypeAssertionExpression, isTypeExpression, isTypeOrChainExpression };
28
28
  }
29
29
  /** Check if a node is of the given type. */
30
30
  declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
@@ -51,18 +51,20 @@ declare function isIdentifier(node: TSESTree.Node, name?: string): node is TSEST
51
51
  declare function isDirective(node: TSESTree.Node, name?: string): node is TSESTreeDirective;
52
52
  /** Check if a node is a call expression. */
53
53
  declare const isCallExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.CallExpression;
54
+ /** Check if a node is an expression node. */
55
+ declare const isExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression;
54
56
  /** Check if a node is a member expression. */
55
57
  declare const isMemberExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName;
56
58
  /** Check if a node is an object expression. */
57
59
  declare const isObjectExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ObjectExpression;
58
- /** Check if a node is an expression node. */
59
- declare const isExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression;
60
60
  /** Check if a node is a loop statement. */
61
61
  declare const isLoopStatement: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
62
62
  /** Check if a node is a return statement. */
63
63
  declare const isReturnStatement: (node: TSESTree.Node | null | undefined) => node is TSESTree.ReturnStatement;
64
64
  /** Check if a node is a class declaration or class expression. */
65
65
  declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
66
+ /** Check if a node is a conditional or logical expression, or a control flow statement. */
67
+ declare const isConditional: (node: TSESTree.Node | null | undefined) => node is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
66
68
  /** Check if a node is a function declaration, function expression, or arrow function expression. */
67
69
  declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
68
70
  /** Check if a node is a function declaration, function expression, arrow function expression, class declaration, or class expression. */
@@ -71,26 +73,39 @@ declare const isFunctionOrClass: (node: TSESTree.Node | null | undefined) => nod
71
73
  declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
72
74
  /** Check if a node is a property or method definition. */
73
75
  declare const isPropertyOrMethod: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
74
- /** Check if a node is a conditional or logical expression, or a control flow statement. */
75
- declare const isConditional: (node: TSESTree.Node | null | undefined) => node is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
76
+ /**
77
+ * Check if a node is the default value of an array pattern element, i.e. an
78
+ * `AssignmentPattern` directly nested in an `ArrayPattern` (ex: `const [a = 1] = arr`).
79
+ * @param node The node to check.
80
+ * @returns `true` if the node is an array pattern element default.
81
+ */
82
+ declare function isArrayPatternElementDefault(node: TSESTree.Node): node is TSESTree.AssignmentPattern;
83
+ /**
84
+ * Check if a node is the default value of an object pattern property, i.e. an
85
+ * `AssignmentPattern` used as the `value` of a `Property` inside an `ObjectPattern`
86
+ * (ex: `const { a = 1 } = obj`).
87
+ * @param node The node to check.
88
+ * @returns `true` if the node is an object pattern element default.
89
+ */
90
+ declare function isObjectPatternElementDefault(node: TSESTree.Node): node is TSESTree.AssignmentPattern;
76
91
  /** Check if a node is any JSX-related node. */
77
92
  declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
78
93
  /** Check if a node is a JSX element. */
79
94
  declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
80
- /** Check if a node is a JSX fragment. */
81
- declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
82
95
  /** Check if a node is a JSX element or JSX fragment. */
83
96
  declare const isJSXElementOrFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment;
84
97
  /** Check if a node is a JSX expression container. */
85
98
  declare const isJSXExpressionContainer: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXExpressionContainer;
99
+ /** Check if a node is a JSX fragment. */
100
+ declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
86
101
  /** Check if a node is a JSX spread attribute. */
87
102
  declare const isJSXSpreadAttribute: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXSpreadAttribute;
88
103
  /** Check if a node can appear as a JSX tag name. */
89
104
  declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
90
- /** Check if a node is a TypeScript type expression (assertion, non-null, satisfies, or instantiation). */
91
- declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
92
105
  /** Check if a node is a TypeScript type assertion-like expression (as, assertion, non-null, or satisfies). */
93
106
  declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
107
+ /** Check if a node is a TypeScript type expression (assertion, non-null, satisfies, or instantiation). */
108
+ declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
94
109
  /** Check if a node is a TypeScript type expression or a chain expression (i.e. a transparent wrapper around an inner expression). */
95
110
  declare const isTypeOrChainExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ChainExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
96
111
  declare namespace compare_d_exports {
@@ -211,6 +226,29 @@ declare function getPropertyName(property: TSESTree.Property, effort?: "min" | "
211
226
  * @returns The fully qualified name.
212
227
  */
213
228
  declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
229
+ declare namespace analyze_d_exports {
230
+ export { isTerminatingStatement, isUnconditionallyTerminating };
231
+ }
232
+ /**
233
+ * Check if a statement terminates the control flow of its block.
234
+ *
235
+ * A statement terminates when it cannot complete normally: a `return`, `throw`,
236
+ * `break`, or `continue`, a block containing such a statement, an `if` whose
237
+ * branches both terminate, or a `try` whose paths all terminate. `switch`
238
+ * statements are not analyzed, so a `switch` whose entry paths all terminate is
239
+ * not treated as terminating.
240
+ * @param node The node to check.
241
+ * @returns `true` if the statement terminates the control flow.
242
+ */
243
+ declare function isTerminatingStatement(node: TSESTree.Node): boolean;
244
+ /**
245
+ * Check if every path through a statement exits the current function with a
246
+ * `return` or `throw`. Unlike {@link isTerminatingStatement}, `break` and
247
+ * `continue` are not considered terminating.
248
+ * @param node The node to check.
249
+ * @returns `true` if the statement unconditionally terminates.
250
+ */
251
+ declare function isUnconditionallyTerminating(node: TSESTree.Node): boolean;
214
252
  declare namespace traverse_d_exports {
215
253
  export { SimpleTraverseOptions, findEnclosingTryBlock, findParent, hasEnclosingTryBlock, hasParent, simpleTraverse };
216
254
  }
@@ -276,4 +314,4 @@ declare function findEnclosingTryBlock(node: TSESTree.Node): TSESTree.TryStateme
276
314
  * @returns `true` when an enclosing `try` block exists.
277
315
  */
278
316
  declare function hasEnclosingTryBlock(node: TSESTree.Node): boolean;
279
- export { check_d_exports as Check, collect_d_exports as Collect, compare_d_exports as Compare, extract_d_exports as Extract, type TSESTreeClass, type TSESTreeDirective, type TSESTreeFunction, type TSESTreeFunctionOrClass, type TSESTreeJSX, type TSESTreeJSXAttributeLike, type TSESTreeJSXElementLike, type TSESTreeMethodOrPropertyDefinition, type TSESTreeTypeExpression, type TSESTreeTypeOrChainExpression, traverse_d_exports as Traverse };
317
+ export { analyze_d_exports as Analyze, check_d_exports as Check, collect_d_exports as Collect, compare_d_exports as Compare, extract_d_exports as Extract, type TSESTreeClass, type TSESTreeDirective, type TSESTreeFunction, type TSESTreeFunctionOrClass, type TSESTreeJSX, type TSESTreeJSXAttributeLike, type TSESTreeJSXElementLike, type TSESTreeMethodOrPropertyDefinition, type TSESTreeTypeExpression, type TSESTreeTypeOrChainExpression, traverse_d_exports as Traverse };
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import { visitorKeys } from "@typescript-eslint/visitor-keys";
5
5
  // src/check.ts
6
6
  var check_exports = /* @__PURE__ */ __exportAll({
7
7
  is: () => is,
8
+ isArrayPatternElementDefault: () => isArrayPatternElementDefault,
8
9
  isCallExpression: () => isCallExpression,
9
10
  isClass: () => isClass,
10
11
  isConditional: () => isConditional,
@@ -23,6 +24,7 @@ var check_exports = /* @__PURE__ */ __exportAll({
23
24
  isLoopStatement: () => isLoopStatement,
24
25
  isMemberExpression: () => isMemberExpression,
25
26
  isObjectExpression: () => isObjectExpression,
27
+ isObjectPatternElementDefault: () => isObjectPatternElementDefault,
26
28
  isOneOf: () => isOneOf,
27
29
  isProperty: () => isProperty,
28
30
  isPropertyOrMethod: () => isPropertyOrMethod,
@@ -40,54 +42,65 @@ function isDirective(node, name) {
40
42
  return node.type === AST_NODE_TYPES.ExpressionStatement && (name == null || node.directive === name);
41
43
  }
42
44
  const isCallExpression = is(AST_NODE_TYPES.CallExpression);
43
- const isMemberExpression = is(AST_NODE_TYPES.MemberExpression);
44
- const isObjectExpression = is(AST_NODE_TYPES.ObjectExpression);
45
45
  const isExpression = isOneOf([
46
+ AST_NODE_TYPES.Identifier,
47
+ AST_NODE_TYPES.Literal,
48
+ AST_NODE_TYPES.CallExpression,
49
+ AST_NODE_TYPES.MemberExpression,
50
+ AST_NODE_TYPES.ObjectExpression,
51
+ AST_NODE_TYPES.TemplateLiteral,
46
52
  AST_NODE_TYPES.ArrayExpression,
47
- AST_NODE_TYPES.ArrayPattern,
53
+ AST_NODE_TYPES.TaggedTemplateExpression,
54
+ AST_NODE_TYPES.BinaryExpression,
48
55
  AST_NODE_TYPES.ArrowFunctionExpression,
56
+ AST_NODE_TYPES.LogicalExpression,
57
+ AST_NODE_TYPES.UnaryExpression,
49
58
  AST_NODE_TYPES.AssignmentExpression,
50
- AST_NODE_TYPES.AwaitExpression,
51
- AST_NODE_TYPES.BinaryExpression,
52
- AST_NODE_TYPES.CallExpression,
59
+ AST_NODE_TYPES.FunctionExpression,
53
60
  AST_NODE_TYPES.ChainExpression,
54
- AST_NODE_TYPES.ClassExpression,
61
+ AST_NODE_TYPES.TSNonNullExpression,
62
+ AST_NODE_TYPES.NewExpression,
63
+ AST_NODE_TYPES.ObjectPattern,
64
+ AST_NODE_TYPES.TSAsExpression,
55
65
  AST_NODE_TYPES.ConditionalExpression,
56
- AST_NODE_TYPES.FunctionExpression,
57
- AST_NODE_TYPES.Identifier,
58
- AST_NODE_TYPES.ImportExpression,
66
+ AST_NODE_TYPES.ThisExpression,
67
+ AST_NODE_TYPES.YieldExpression,
68
+ AST_NODE_TYPES.TSSatisfiesExpression,
59
69
  AST_NODE_TYPES.JSXElement,
60
- AST_NODE_TYPES.JSXFragment,
61
- AST_NODE_TYPES.Literal,
62
- AST_NODE_TYPES.LogicalExpression,
63
- AST_NODE_TYPES.MemberExpression,
70
+ AST_NODE_TYPES.ArrayPattern,
71
+ AST_NODE_TYPES.UpdateExpression,
72
+ AST_NODE_TYPES.AwaitExpression,
64
73
  AST_NODE_TYPES.MetaProperty,
65
- AST_NODE_TYPES.NewExpression,
66
- AST_NODE_TYPES.ObjectExpression,
67
- AST_NODE_TYPES.ObjectPattern,
74
+ AST_NODE_TYPES.ImportExpression,
75
+ AST_NODE_TYPES.ClassExpression,
76
+ AST_NODE_TYPES.JSXFragment,
68
77
  AST_NODE_TYPES.SequenceExpression,
69
78
  AST_NODE_TYPES.Super,
70
- AST_NODE_TYPES.TSAsExpression,
71
79
  AST_NODE_TYPES.TSInstantiationExpression,
72
- AST_NODE_TYPES.TSNonNullExpression,
73
- AST_NODE_TYPES.TSSatisfiesExpression,
74
- AST_NODE_TYPES.TSTypeAssertion,
75
- AST_NODE_TYPES.TaggedTemplateExpression,
76
- AST_NODE_TYPES.TemplateLiteral,
77
- AST_NODE_TYPES.ThisExpression,
78
- AST_NODE_TYPES.UnaryExpression,
79
- AST_NODE_TYPES.UpdateExpression,
80
- AST_NODE_TYPES.YieldExpression
80
+ AST_NODE_TYPES.TSTypeAssertion
81
81
  ]);
82
+ const isMemberExpression = is(AST_NODE_TYPES.MemberExpression);
83
+ const isObjectExpression = is(AST_NODE_TYPES.ObjectExpression);
82
84
  const isLoopStatement = isOneOf([
83
- AST_NODE_TYPES.DoWhileStatement,
84
- AST_NODE_TYPES.ForInStatement,
85
85
  AST_NODE_TYPES.ForOfStatement,
86
+ AST_NODE_TYPES.WhileStatement,
86
87
  AST_NODE_TYPES.ForStatement,
87
- AST_NODE_TYPES.WhileStatement
88
+ AST_NODE_TYPES.ForInStatement,
89
+ AST_NODE_TYPES.DoWhileStatement
88
90
  ]);
89
91
  const isReturnStatement = is(AST_NODE_TYPES.ReturnStatement);
90
92
  const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
93
+ const isConditional = isOneOf([
94
+ AST_NODE_TYPES.IfStatement,
95
+ AST_NODE_TYPES.LogicalExpression,
96
+ AST_NODE_TYPES.ConditionalExpression,
97
+ AST_NODE_TYPES.ForOfStatement,
98
+ AST_NODE_TYPES.SwitchStatement,
99
+ AST_NODE_TYPES.WhileStatement,
100
+ AST_NODE_TYPES.ForStatement,
101
+ AST_NODE_TYPES.ForInStatement,
102
+ AST_NODE_TYPES.DoWhileStatement
103
+ ]);
91
104
  const isFunction$1 = isOneOf([
92
105
  AST_NODE_TYPES.ArrowFunctionExpression,
93
106
  AST_NODE_TYPES.FunctionDeclaration,
@@ -101,70 +114,65 @@ const isFunctionOrClass = isOneOf([
101
114
  AST_NODE_TYPES.ClassExpression
102
115
  ]);
103
116
  const isProperty = isOneOf([
117
+ AST_NODE_TYPES.TSPropertySignature,
104
118
  AST_NODE_TYPES.PropertyDefinition,
105
119
  AST_NODE_TYPES.TSIndexSignature,
106
- AST_NODE_TYPES.TSParameterProperty,
107
- AST_NODE_TYPES.TSPropertySignature
108
- ]);
109
- const isPropertyOrMethod = isOneOf([AST_NODE_TYPES.PropertyDefinition, AST_NODE_TYPES.MethodDefinition]);
110
- const isConditional = isOneOf([
111
- AST_NODE_TYPES.DoWhileStatement,
112
- AST_NODE_TYPES.ForInStatement,
113
- AST_NODE_TYPES.ForOfStatement,
114
- AST_NODE_TYPES.ForStatement,
115
- AST_NODE_TYPES.WhileStatement,
116
- AST_NODE_TYPES.IfStatement,
117
- AST_NODE_TYPES.SwitchStatement,
118
- AST_NODE_TYPES.LogicalExpression,
119
- AST_NODE_TYPES.ConditionalExpression
120
+ AST_NODE_TYPES.TSParameterProperty
120
121
  ]);
122
+ const isPropertyOrMethod = isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition]);
123
+ function isArrayPatternElementDefault(node) {
124
+ return node.type === AST_NODE_TYPES.AssignmentPattern && node.parent.type === AST_NODE_TYPES.ArrayPattern;
125
+ }
126
+ function isObjectPatternElementDefault(node) {
127
+ return node.type === AST_NODE_TYPES.AssignmentPattern && node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && node.parent.parent.type === AST_NODE_TYPES.ObjectPattern;
128
+ }
121
129
  const isJSX = isOneOf([
130
+ AST_NODE_TYPES.JSXIdentifier,
131
+ AST_NODE_TYPES.JSXText,
122
132
  AST_NODE_TYPES.JSXAttribute,
133
+ AST_NODE_TYPES.JSXElement,
134
+ AST_NODE_TYPES.JSXOpeningElement,
123
135
  AST_NODE_TYPES.JSXClosingElement,
136
+ AST_NODE_TYPES.JSXExpressionContainer,
137
+ AST_NODE_TYPES.JSXMemberExpression,
138
+ AST_NODE_TYPES.JSXSpreadAttribute,
124
139
  AST_NODE_TYPES.JSXClosingFragment,
125
- AST_NODE_TYPES.JSXElement,
126
140
  AST_NODE_TYPES.JSXEmptyExpression,
127
- AST_NODE_TYPES.JSXExpressionContainer,
128
141
  AST_NODE_TYPES.JSXFragment,
129
- AST_NODE_TYPES.JSXIdentifier,
130
- AST_NODE_TYPES.JSXMemberExpression,
131
142
  AST_NODE_TYPES.JSXNamespacedName,
132
- AST_NODE_TYPES.JSXOpeningElement,
133
143
  AST_NODE_TYPES.JSXOpeningFragment,
134
- AST_NODE_TYPES.JSXSpreadAttribute,
135
- AST_NODE_TYPES.JSXSpreadChild,
136
- AST_NODE_TYPES.JSXText
144
+ AST_NODE_TYPES.JSXSpreadChild
137
145
  ]);
138
146
  const isJSXElement = is(AST_NODE_TYPES.JSXElement);
139
- const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
140
147
  const isJSXElementOrFragment = isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment]);
141
148
  const isJSXExpressionContainer = is(AST_NODE_TYPES.JSXExpressionContainer);
149
+ const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
142
150
  const isJSXSpreadAttribute = is(AST_NODE_TYPES.JSXSpreadAttribute);
143
151
  const isJSXTagNameExpression = isOneOf([
144
152
  AST_NODE_TYPES.JSXIdentifier,
145
153
  AST_NODE_TYPES.JSXMemberExpression,
146
154
  AST_NODE_TYPES.JSXNamespacedName
147
155
  ]);
148
- const isTypeExpression = isOneOf([
149
- AST_NODE_TYPES.TSAsExpression,
150
- AST_NODE_TYPES.TSTypeAssertion,
156
+ const isTypeAssertionExpression = isOneOf([
151
157
  AST_NODE_TYPES.TSNonNullExpression,
158
+ AST_NODE_TYPES.TSAsExpression,
152
159
  AST_NODE_TYPES.TSSatisfiesExpression,
153
- AST_NODE_TYPES.TSInstantiationExpression
160
+ AST_NODE_TYPES.TSTypeAssertion
154
161
  ]);
155
- const isTypeAssertionExpression = isOneOf([
156
- AST_NODE_TYPES.TSAsExpression,
157
- AST_NODE_TYPES.TSTypeAssertion,
162
+ const isTypeExpression = isOneOf([
158
163
  AST_NODE_TYPES.TSNonNullExpression,
159
- AST_NODE_TYPES.TSSatisfiesExpression
164
+ AST_NODE_TYPES.TSAsExpression,
165
+ AST_NODE_TYPES.TSSatisfiesExpression,
166
+ AST_NODE_TYPES.TSInstantiationExpression,
167
+ AST_NODE_TYPES.TSTypeAssertion
160
168
  ]);
161
169
  const isTypeOrChainExpression = isOneOf([
162
- AST_NODE_TYPES.TSAsExpression,
163
- AST_NODE_TYPES.TSTypeAssertion,
170
+ AST_NODE_TYPES.ChainExpression,
164
171
  AST_NODE_TYPES.TSNonNullExpression,
172
+ AST_NODE_TYPES.TSAsExpression,
165
173
  AST_NODE_TYPES.TSSatisfiesExpression,
166
174
  AST_NODE_TYPES.TSInstantiationExpression,
167
- AST_NODE_TYPES.ChainExpression
175
+ AST_NODE_TYPES.TSTypeAssertion
168
176
  ]);
169
177
  // ../../.pkgs/eff/dist/index.js
170
178
  const pipeArguments = (self, args) => {
@@ -564,4 +572,36 @@ function getReturnExpressions(node) {
564
572
  if (node.body.type !== AST_NODE_TYPES.BlockStatement) return [node.body];
565
573
  return getReturnStatements(node).flatMap((stmt) => stmt.argument == null ? [] : [stmt.argument]);
566
574
  }
567
- export { check_exports as Check, collect_exports as Collect, compare_exports as Compare, extract_exports as Extract, traverse_exports as Traverse };
575
+ // src/analyze.ts
576
+ var analyze_exports = /* @__PURE__ */ __exportAll({
577
+ isTerminatingStatement: () => isTerminatingStatement,
578
+ isUnconditionallyTerminating: () => isUnconditionallyTerminating
579
+ });
580
+ function isTerminatingStatement(node) {
581
+ switch (node.type) {
582
+ case AST_NODE_TYPES.ReturnStatement:
583
+ case AST_NODE_TYPES.ThrowStatement:
584
+ case AST_NODE_TYPES.BreakStatement:
585
+ case AST_NODE_TYPES.ContinueStatement: return true;
586
+ case AST_NODE_TYPES.BlockStatement: return node.body.some(isTerminatingStatement);
587
+ case AST_NODE_TYPES.IfStatement: return node.alternate != null && isTerminatingStatement(node.consequent) && isTerminatingStatement(node.alternate);
588
+ case AST_NODE_TYPES.TryStatement:
589
+ if (node.finalizer != null && isTerminatingStatement(node.finalizer)) return true;
590
+ if (node.handler == null) return isTerminatingStatement(node.block);
591
+ return isTerminatingStatement(node.block) && isTerminatingStatement(node.handler.body);
592
+ default: return false;
593
+ }
594
+ }
595
+ function isUnconditionallyTerminating(node) {
596
+ switch (node.type) {
597
+ case AST_NODE_TYPES.ReturnStatement:
598
+ case AST_NODE_TYPES.ThrowStatement: return true;
599
+ case AST_NODE_TYPES.BlockStatement: {
600
+ const last = node.body.at(-1);
601
+ return last != null && isUnconditionallyTerminating(last);
602
+ }
603
+ case AST_NODE_TYPES.IfStatement: return node.alternate != null && isUnconditionallyTerminating(node.consequent) && isUnconditionallyTerminating(node.alternate);
604
+ default: return false;
605
+ }
606
+ }
607
+ export { analyze_exports as Analyze, check_exports as Check, collect_exports as Collect, compare_exports as Compare, extract_exports as Extract, traverse_exports as Traverse };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "5.30.0-beta.3",
3
+ "version": "5.30.0-beta.5",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
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
- "@typescript-eslint/types": "^8.72.0",
33
- "@typescript-eslint/utils": "^8.72.0",
34
- "@typescript-eslint/visitor-keys": "^8.72.0"
32
+ "@typescript-eslint/types": "^8.72.1",
33
+ "@typescript-eslint/utils": "^8.72.1",
34
+ "@typescript-eslint/visitor-keys": "^8.72.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@local/configs": "0.0.0",