Socket
Book a DemoInstallSign in
Socket

@eslint-react/ast

Package Overview
Dependencies
Maintainers
1
Versions
1587
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eslint-react/ast - npm Package Compare versions

Comparing version

to
2.0.0-next.61

346

dist/index.d.ts

@@ -1,10 +0,56 @@

import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/types';
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
import { unit } from '@eslint-react/eff';
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
import { unit } from "@eslint-react/eff";
import { TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
//#region src/array-index.d.ts
declare function getArrayMethodCallbackIndexParamPosition(methodName: string): number;
//#endregion
//#region src/array-method.d.ts
declare function isArrayFromCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
declare function isArrayMapCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
declare function getArrayMethodCallbackIndexParamPosition(methodName: string): number;
//#endregion
//#region src/node-equal.d.ts
/**
* Determines whether node equals to another node
* @param a node to compare
* @param b node to compare
* @returns `true` if node equal
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
*/
declare const isNodeEqual: {
(a: TSESTree.Node): (b: TSESTree.Node) => boolean;
(a: TSESTree.Node, b: TSESTree.Node): boolean;
};
//#endregion
//#region src/node-format.d.ts
/**
* @internal
*/
declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
/**
* @internal
*/
declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
//#endregion
//#region src/node-is.d.ts
declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
type: NodeType;
}>;
declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
type: NodeTypes[number];
}>;
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
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;
declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
//#endregion
//#region src/node-types.d.ts
type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;

@@ -22,142 +68,28 @@ type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;

type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
//#endregion
//#region src/class-id.d.ts
declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | unit;
//#endregion
//#region src/expression-base.d.ts
/**
* Recursively get the inner expression until it's not a TypeExpression
* @param node - The node to get the expression from
* @returns The inner expression
* Unwraps any type expressions to get the underlying JavaScript expression node.
* Recursively processes nodes until a non-type expression is found.
*
* @param node - The AST node to unwrap
* @returns The underlying JavaScript expression node
*/
declare function getJSExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
declare function isThisExpression(node: TSESTree.Expression): boolean;
declare function getUnderlyingExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
//#endregion
//#region src/expression-is.d.ts
/**
* Gets the static name of a function AST node. For function declarations it is
* easy. For anonymous function expressions it is much harder. If you search for
* `IsAnonymousFunctionDefinition()` in the ECMAScript spec you'll find places
* where JS gives anonymous function expressions names. We roughly detect the
* same AST nodes with some exceptions to better fit our use case.
* Checks if the given expression is a 'this' expression.
* Unwraps any type expressions before checking.
*
* @param node - The expression node to check
* @returns true if the expression is a ThisExpression, false otherwise
*/
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | unit;
type FunctionInitPath =
declare function isThisExpression(node: TSESTree.Expression): boolean;
//#endregion
//#region src/expression-nested.d.ts
/**
* function Comp() { return <div />; }
*/
readonly [TSESTree.FunctionDeclaration]
/**
* const Comp = () => <div />;
* const Comp = function () { return <div />; };
*/
| readonly [
TSESTree.VariableDeclaration,
TSESTree.VariableDeclarator,
TSESTreeFunction
]
/**
* const Comp = React.memo(() => <div />);
* const Comp = React.forwardRef(() => <div />);
*/
| readonly [
TSESTree.VariableDeclaration,
TSESTree.VariableDeclarator,
TSESTree.CallExpression,
TSESTreeFunction
]
/**
* const Comp = React.memo(React.forwardRef(() => <div />));
*/
| readonly [
TSESTree.VariableDeclaration,
TSESTree.VariableDeclarator,
TSESTree.CallExpression,
TSESTree.CallExpression,
TSESTreeFunction
]
/**
* const Comps = {
* TopNav() { return <div />; },
* SidPanel: () => <div />,
* }
*/
| readonly [
TSESTree.VariableDeclaration,
TSESTree.VariableDeclarator,
TSESTree.ObjectExpression,
TSESTree.Property,
TSESTreeFunction
]
/**
* const Comps = {
* TopNav: React.memo(() => <div />),
* SidPanel: React.forwardRef(() => <div />),
* }
*/
| readonly [
TSESTree.VariableDeclaration,
TSESTree.VariableDeclarator,
TSESTree.ObjectExpression,
TSESTree.Property,
TSESTree.CallExpression,
TSESTreeFunction
]
/**
* const Comps = {
* TopNav: React.memo(React.forwardRef(() => <div />)),
* SidPanel: React.forwardRef(React.memo(() => <div />)),
* }
*/
| readonly [
TSESTree.VariableDeclaration,
TSESTree.VariableDeclarator,
TSESTree.ObjectExpression,
TSESTree.Property,
TSESTree.CallExpression,
TSESTree.CallExpression,
TSESTreeFunction
]
/**
* class Comp {
* TopNav() { return <div />; }
* }
*/
| readonly [
TSESTree.ClassDeclaration,
TSESTree.ClassBody,
TSESTree.MethodDefinition,
TSESTreeFunction
]
/**
* class Comp {
* TopNav = () => <div />;
* }
*/
| readonly [
TSESTree.ClassDeclaration,
TSESTree.ClassBody,
TSESTree.PropertyDefinition,
TSESTreeFunction
];
declare function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionInitPath;
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
declare function isEmptyFunction(node: TSESTreeFunction): boolean;
declare function isImmediatelyInvokedFunction(node: TSESTreeFunction): boolean;
/**
* Find the parent node that satisfies the test function
* @param node The AST node
* @param test The test function
* @returns The parent node that satisfies the test function or `_` if not found
*/
declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | unit, test: (n: TSESTree.Node) => n is A): A | unit;
/**
* Find the parent node that satisfies the test function or `_` if not found
* @param node The AST node
* @param test The test function
* @returns The parent node that satisfies the test function
*/
declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
/**
* Get all nested identifiers in a expression like node

@@ -181,3 +113,3 @@ * @param node The node to get the nested identifiers from

declare function getNestedExpressionsOfType<TNodeType extends AST_NODE_TYPES>(type: TNodeType): (node: TSESTree.Node) => Extract<TSESTree.Node, {
type: TNodeType;
type: TNodeType;
}>[];

@@ -196,16 +128,42 @@ /**

declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
//#endregion
//#region src/function-id.d.ts
/**
* Check if a node is multiline
* @param node The AST node to check
* @returns `true` if the node is multiline
* Gets the static name of a function AST node. For function declarations it is
* easy. For anonymous function expressions it is much harder. If you search for
* `IsAnonymousFunctionDefinition()` in the ECMAScript spec you'll find places
* where JS gives anonymous function expressions names. We roughly detect the
* same AST nodes with some exceptions to better fit our use case.
*/
declare function isMultiLine(node: TSESTree.Node): boolean;
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | unit;
//#endregion
//#region src/function-init-path.d.ts
/**
* Check if a node is a line break
* @param node The AST node to check
* @returns boolean
* Represents various AST paths for React component function declarations.
* Each tuple type represents a specific component definition pattern.
*/
declare function isLineBreak(node: TSESTree.Node): boolean;
type FunctionInitPath = readonly [TSESTree.FunctionDeclaration] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.MethodDefinition, TSESTreeFunction] | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.PropertyDefinition, TSESTreeFunction];
/**
* Identifies the initialization path of a function node in the AST.
* Determines what kind of component declaration pattern the function belongs to.
*
* @param node - The function node to analyze
* @returns The function initialization path or unit if not identifiable
*/
declare function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionInitPath;
/**
* Checks if a specific function call exists in the function initialization path.
* Useful for detecting HOCs like React.memo, React.forwardRef, etc.
*
* @param callName - The name of the call to check for (e.g., "memo", "forwardRef")
* @param initPath - The function initialization path to search in
* @returns True if the call exists in the path, false otherwise
*/
declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
//#endregion
//#region src/function-is.d.ts
declare function isFunctionEmpty(node: TSESTreeFunction): boolean;
declare function isFunctionImmediatelyInvoked(node: TSESTreeFunction): boolean;
//#endregion
//#region src/literal.d.ts
declare function isLiteral(node: TSESTree.Node): node is TSESTree.Literal;

@@ -217,69 +175,39 @@ declare function isLiteral(node: TSESTree.Node, type: "boolean"): node is TSESTree.BooleanLiteral;

declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
//#endregion
//#region src/misc.d.ts
/**
* Determines whether node equals to another node
* @param a node to compare
* @param b node to compare
* @returns `true` if node equal
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
* Check if a node is multiline
* @param node The AST node to check
* @returns `true` if the node is multiline
*/
declare const isNodeEqual: {
(a: TSESTree.Node): (b: TSESTree.Node) => boolean;
(a: TSESTree.Node, b: TSESTree.Node): boolean;
};
declare function isMultiLine(node: TSESTree.Node): boolean;
/**
* @internal
* Check if a node is a line break
* @param node The AST node to check
* @returns boolean
*/
declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
declare function isLineBreak(node: TSESTree.Node): boolean;
//#endregion
//#region src/promise-then.d.ts
declare function isThenCall(node: TSESTree.CallExpression): boolean;
//#endregion
//#region src/property-name.d.ts
declare function getPropertyName(node: TSESTree.Node): string | unit;
//#endregion
//#region src/traverse-up.d.ts
/**
* @internal
*/
declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
type: NodeType;
}>;
declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
type: NodeTypes[number];
}>;
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
declare const isControlFlow: (data: TSESTree.Node | null | undefined) => data is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.SwitchStatement | TSESTree.WhileStatement;
declare const isConditional: (data: TSESTree.Node | null | undefined) => data is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
declare const isArrayTupleType: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSArrayType | TSESTree.TSTupleType;
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
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;
declare const isDestructuringPattern: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayPattern | TSESTree.AssignmentPattern | TSESTree.ObjectPattern | TSESTree.RestElement;
declare const isTypeDeclaration: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeAliasDeclaration;
declare const isLeftHandSideExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.CallExpression | TSESTree.ClassExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression;
declare const isLeftHandSideExpressionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.CallExpression | TSESTree.ClassExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSTypeAssertion;
declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
/**
* Check if the given node is a member expression that accesses `process.env.NODE_ENV`
* Find the parent node that satisfies the test function
* @param node The AST node
* @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
* @param test The test function
* @returns The parent node that satisfies the test function or `_` if not found
*/
declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | unit, test: (n: TSESTree.Node) => n is A): A | unit;
/**
* Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal
* Find the parent node that satisfies the test function or `_` if not found
* @param node The AST node
* @param operator The operator used in the comparison
* @param value The string literal value to compare against
* @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
* @param test The test function
* @returns The parent node that satisfies the test function
*/
declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
declare function getPropertyName(node: TSESTree.Node): string | unit;
declare function isThenCall(node: TSESTree.CallExpression): boolean;
export { type FunctionInitPath, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isImmediatelyInvokedFunction, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterFormat, toStringFormat };
declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
//#endregion
export { FunctionInitPath, TSESTreeArrayTupleType, TSESTreeClass, TSESTreeDestructuringPattern, TSESTreeFunction, TSESTreeFunctionType, TSESTreeJSX, TSESTreeLoop, TSESTreeMethodOrProperty, TSESTreeProperty, TSESTreeTypeAssertionExpression, TSESTreeTypeDeclaration, TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterFormat, toStringFormat };

@@ -1,595 +0,572 @@

import { AST_NODE_TYPES } from '@typescript-eslint/types';
import { or, dual, unit } from '@eslint-react/eff';
import { ASTUtils } from '@typescript-eslint/utils';
import { simpleTraverse } from '@typescript-eslint/typescript-estree';
import { toLowerCase, delimiterCase, replace } from 'string-ts';
import { AST_NODE_TYPES } from "@typescript-eslint/types";
import { dual, unit } from "@eslint-react/eff";
import { delimiterCase, replace, toLowerCase } from "string-ts";
import { ASTUtils } from "@typescript-eslint/utils";
import { simpleTraverse } from "@typescript-eslint/typescript-estree";
// src/ast-array-method.ts
//#region src/array-index.ts
const indexParamPosition = new Map([
["every", 1],
["filter", 1],
["find", 1],
["findIndex", 1],
["findLast", 1],
["findLastIndex", 1],
["flatMap", 1],
["forEach", 1],
["map", 1],
["reduce", 2],
["reduceRight", 2],
["some", 1]
]);
function getArrayMethodCallbackIndexParamPosition(methodName) {
return indexParamPosition.get(methodName) ?? -1;
}
//#endregion
//#region src/array-method.ts
function isArrayFromCall(node, loose = true) {
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
const name = node.callee.property.name;
return name === "from" || loose && name.startsWith("from");
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
const name = node.callee.property.name;
return name === "from" || loose && name.startsWith("from");
}
function isArrayMapCall(node, loose = true) {
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
const name = node.callee.property.name;
return name === "map" || loose && name.endsWith("Map");
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
const name = node.callee.property.name;
return name === "map" || loose && name.endsWith("Map");
}
// src/ast-array-method-callback.ts
var indexParamPosition = /* @__PURE__ */ new Map([
["every", 1],
["filter", 1],
["find", 1],
["findIndex", 1],
["findLast", 1],
["findLastIndex", 1],
["flatMap", 1],
["forEach", 1],
["map", 1],
["reduce", 2],
["reduceRight", 2],
["some", 1]
]);
function getArrayMethodCallbackIndexParamPosition(methodName) {
return indexParamPosition.get(methodName) ?? -1;
}
//#endregion
//#region src/class-id.ts
function getClassId(node) {
if (node.id != null) return node.id;
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
return node.parent.id;
}
return unit;
if (node.id != null) return node.id;
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) return node.parent.id;
return unit;
}
var is = ASTUtils.isNodeOfType;
var isOneOf = ASTUtils.isNodeOfTypes;
var isFunction = isOneOf([
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.FunctionDeclaration,
AST_NODE_TYPES.FunctionExpression
//#endregion
//#region src/node-equal.ts
/**
* Determines whether node equals to another node
* @param a node to compare
* @param b node to compare
* @returns `true` if node equal
* @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
*/
const isNodeEqual = dual(2, (a, b) => {
switch (true) {
case a === b: return true;
case a.type !== b.type: return false;
case a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal: return a.value === b.value;
case a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement: return a.value.raw === b.value.raw;
case a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral: {
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
let i = a.quasis.length;
while (i--) if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) return false;
i = a.expressions.length;
while (i--) {
const exprA = a.expressions[i];
const exprB = b.expressions[i];
if (!isNodeEqual(exprA, exprB)) return false;
}
return true;
}
case a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier: return a.name === b.name;
case a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
case a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute:
if (a.name.name !== b.name.name) return false;
if (a.value == null || b.value == null) return a.value === b.value;
return isNodeEqual(a.value, b.value);
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression: return true;
default: return false;
}
});
//#endregion
//#region src/node-is.ts
const is = ASTUtils.isNodeOfType;
const isOneOf = ASTUtils.isNodeOfTypes;
const isFunction = isOneOf([
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.FunctionDeclaration,
AST_NODE_TYPES.FunctionExpression
]);
var isFunctionType = isOneOf([
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.FunctionDeclaration,
AST_NODE_TYPES.FunctionExpression,
AST_NODE_TYPES.TSCallSignatureDeclaration,
AST_NODE_TYPES.TSConstructSignatureDeclaration,
AST_NODE_TYPES.TSDeclareFunction,
AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
AST_NODE_TYPES.TSFunctionType,
AST_NODE_TYPES.TSMethodSignature
const isFunctionType = isOneOf([
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.FunctionDeclaration,
AST_NODE_TYPES.FunctionExpression,
AST_NODE_TYPES.TSCallSignatureDeclaration,
AST_NODE_TYPES.TSConstructSignatureDeclaration,
AST_NODE_TYPES.TSDeclareFunction,
AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
AST_NODE_TYPES.TSFunctionType,
AST_NODE_TYPES.TSMethodSignature
]);
var isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
var isMethodOrProperty = isOneOf([
AST_NODE_TYPES.PropertyDefinition,
AST_NODE_TYPES.MethodDefinition
const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
const isMethodOrProperty = isOneOf([AST_NODE_TYPES.PropertyDefinition, AST_NODE_TYPES.MethodDefinition]);
const isProperty = isOneOf([
AST_NODE_TYPES.PropertyDefinition,
AST_NODE_TYPES.TSIndexSignature,
AST_NODE_TYPES.TSParameterProperty,
AST_NODE_TYPES.TSPropertySignature
]);
var isLoop = isOneOf([
AST_NODE_TYPES.DoWhileStatement,
AST_NODE_TYPES.ForInStatement,
AST_NODE_TYPES.ForOfStatement,
AST_NODE_TYPES.ForStatement,
AST_NODE_TYPES.WhileStatement
const isJSXElement = is(AST_NODE_TYPES.JSXElement);
const isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
const isJSXTagNameExpression = isOneOf([
AST_NODE_TYPES.JSXIdentifier,
AST_NODE_TYPES.JSXMemberExpression,
AST_NODE_TYPES.JSXNamespacedName
]);
var isControlFlow = or(
isLoop,
isOneOf([
AST_NODE_TYPES.IfStatement,
AST_NODE_TYPES.SwitchStatement
])
);
var isConditional = or(
isControlFlow,
isOneOf([
AST_NODE_TYPES.LogicalExpression,
AST_NODE_TYPES.ConditionalExpression
])
);
var isArrayTupleType = isOneOf([AST_NODE_TYPES.TSArrayType, AST_NODE_TYPES.TSTupleType]);
var isProperty = isOneOf([
AST_NODE_TYPES.PropertyDefinition,
AST_NODE_TYPES.TSIndexSignature,
AST_NODE_TYPES.TSParameterProperty,
AST_NODE_TYPES.TSPropertySignature
const isJSX = isOneOf([
AST_NODE_TYPES.JSXAttribute,
AST_NODE_TYPES.JSXClosingElement,
AST_NODE_TYPES.JSXClosingFragment,
AST_NODE_TYPES.JSXElement,
AST_NODE_TYPES.JSXEmptyExpression,
AST_NODE_TYPES.JSXExpressionContainer,
AST_NODE_TYPES.JSXFragment,
AST_NODE_TYPES.JSXIdentifier,
AST_NODE_TYPES.JSXMemberExpression,
AST_NODE_TYPES.JSXNamespacedName,
AST_NODE_TYPES.JSXOpeningElement,
AST_NODE_TYPES.JSXOpeningFragment,
AST_NODE_TYPES.JSXSpreadAttribute,
AST_NODE_TYPES.JSXSpreadChild,
AST_NODE_TYPES.JSXText
]);
var isJSXElement = is(AST_NODE_TYPES.JSXElement);
var isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
var isJSXTagNameExpression = isOneOf([
AST_NODE_TYPES.JSXIdentifier,
AST_NODE_TYPES.JSXMemberExpression,
AST_NODE_TYPES.JSXNamespacedName
const isLoop = isOneOf([
AST_NODE_TYPES.DoWhileStatement,
AST_NODE_TYPES.ForInStatement,
AST_NODE_TYPES.ForOfStatement,
AST_NODE_TYPES.ForStatement,
AST_NODE_TYPES.WhileStatement
]);
var isJSX = isOneOf([
AST_NODE_TYPES.JSXAttribute,
AST_NODE_TYPES.JSXClosingElement,
AST_NODE_TYPES.JSXClosingFragment,
AST_NODE_TYPES.JSXElement,
AST_NODE_TYPES.JSXEmptyExpression,
AST_NODE_TYPES.JSXExpressionContainer,
AST_NODE_TYPES.JSXFragment,
AST_NODE_TYPES.JSXIdentifier,
AST_NODE_TYPES.JSXMemberExpression,
AST_NODE_TYPES.JSXNamespacedName,
AST_NODE_TYPES.JSXOpeningElement,
AST_NODE_TYPES.JSXOpeningFragment,
AST_NODE_TYPES.JSXSpreadAttribute,
AST_NODE_TYPES.JSXSpreadChild,
AST_NODE_TYPES.JSXText
const isTypeExpression = isOneOf([
AST_NODE_TYPES.TSAsExpression,
AST_NODE_TYPES.TSTypeAssertion,
AST_NODE_TYPES.TSNonNullExpression,
AST_NODE_TYPES.TSSatisfiesExpression,
AST_NODE_TYPES.TSInstantiationExpression
]);
var isDestructuringPattern = isOneOf([
AST_NODE_TYPES.ArrayPattern,
AST_NODE_TYPES.AssignmentPattern,
AST_NODE_TYPES.ObjectPattern,
AST_NODE_TYPES.RestElement
const isTypeAssertionExpression = isOneOf([
AST_NODE_TYPES.TSAsExpression,
AST_NODE_TYPES.TSTypeAssertion,
AST_NODE_TYPES.TSNonNullExpression,
AST_NODE_TYPES.TSSatisfiesExpression
]);
var isTypeDeclaration = isOneOf([
AST_NODE_TYPES.TSInterfaceDeclaration,
AST_NODE_TYPES.TSTypeAliasDeclaration
]);
var isLeftHandSideExpression = isOneOf([
AST_NODE_TYPES.ArrayExpression,
AST_NODE_TYPES.ArrayPattern,
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.CallExpression,
AST_NODE_TYPES.ClassExpression,
AST_NODE_TYPES.FunctionExpression,
AST_NODE_TYPES.Identifier,
AST_NODE_TYPES.JSXElement,
AST_NODE_TYPES.JSXFragment,
AST_NODE_TYPES.Literal,
AST_NODE_TYPES.TemplateLiteral,
AST_NODE_TYPES.MemberExpression,
AST_NODE_TYPES.MetaProperty,
AST_NODE_TYPES.ObjectExpression,
AST_NODE_TYPES.ObjectPattern,
AST_NODE_TYPES.SequenceExpression,
AST_NODE_TYPES.Super,
AST_NODE_TYPES.TaggedTemplateExpression,
AST_NODE_TYPES.ThisExpression
]);
var isLeftHandSideExpressionType = isOneOf([
AST_NODE_TYPES.ArrayExpression,
AST_NODE_TYPES.ArrayPattern,
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.CallExpression,
AST_NODE_TYPES.ClassExpression,
AST_NODE_TYPES.FunctionExpression,
AST_NODE_TYPES.Identifier,
AST_NODE_TYPES.JSXElement,
AST_NODE_TYPES.JSXFragment,
AST_NODE_TYPES.Literal,
AST_NODE_TYPES.TemplateLiteral,
AST_NODE_TYPES.MemberExpression,
AST_NODE_TYPES.MetaProperty,
AST_NODE_TYPES.ObjectExpression,
AST_NODE_TYPES.ObjectPattern,
AST_NODE_TYPES.SequenceExpression,
AST_NODE_TYPES.Super,
AST_NODE_TYPES.TaggedTemplateExpression,
AST_NODE_TYPES.ThisExpression,
AST_NODE_TYPES.TSAsExpression,
AST_NODE_TYPES.TSNonNullExpression,
AST_NODE_TYPES.TSTypeAssertion
]);
var isTypeExpression = isOneOf([
AST_NODE_TYPES.TSAsExpression,
AST_NODE_TYPES.TSTypeAssertion,
AST_NODE_TYPES.TSNonNullExpression,
AST_NODE_TYPES.TSSatisfiesExpression,
AST_NODE_TYPES.TSInstantiationExpression
]);
var isTypeAssertionExpression = isOneOf([
AST_NODE_TYPES.TSAsExpression,
AST_NODE_TYPES.TSTypeAssertion,
AST_NODE_TYPES.TSNonNullExpression,
AST_NODE_TYPES.TSSatisfiesExpression
]);
// src/ast-expression.ts
function getJSExpression(node) {
if (isTypeExpression(node)) {
return getJSExpression(node.expression);
}
return node;
//#endregion
//#region src/node-format.ts
function getLiteralValueType(input) {
if (input === null) return "null";
return typeof input;
}
function isThisExpression(node) {
return getJSExpression(node).type === AST_NODE_TYPES.ThisExpression;
/**
* @internal
*/
function toDelimiterFormat(node, delimiter = " ") {
if (node.type === AST_NODE_TYPES.Literal) {
if ("regex" in node) return "RegExp literal";
return `${getLiteralValueType(node.value)} literal`;
}
if (isJSX(node)) return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
return toLowerCase(delimiterCase(node.type, delimiter));
}
function getFunctionId(node) {
switch (true) {
// function MaybeComponent() {}
case ("id" in node && node.id != null):
return node.id;
// const whatever = function MaybeComponent() {};
case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
return node.parent.id;
// MaybeComponent = () => {};
case (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier):
return node.parent.left;
// {MaybeComponent: () => {}}
// {MaybeComponent() {}}
case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
return node.parent.key;
// class {MaybeComponent = () => {}}
// class {MaybeComponent() {}}
case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
return node.parent.key;
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
//
// const {MaybeComponent = () => {}} = {};
// ({MaybeComponent = () => {}} = {});
case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
return node.parent.left;
// const MaybeComponent = (() => {})!;
// const MaybeComponent = (() => {}) as FunctionComponent;
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
case isTypeAssertionExpression(node.parent):
return getFunctionId(node.parent);
}
return unit;
/**
* @internal
*/
function toStringFormat(node, getText) {
switch (node.type) {
case AST_NODE_TYPES.Identifier:
case AST_NODE_TYPES.JSXIdentifier:
case AST_NODE_TYPES.PrivateIdentifier: return node.name;
case AST_NODE_TYPES.MemberExpression:
case AST_NODE_TYPES.JSXMemberExpression: return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
case AST_NODE_TYPES.JSXText: return node.value;
case AST_NODE_TYPES.Literal: return node.raw;
default: return getText(node);
}
}
function getFunctionInitPath(node) {
if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
return [node];
}
const { parent } = node;
switch (true) {
case parent.type === AST_NODE_TYPES.VariableDeclarator:
return [parent.parent, parent, node];
case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
return [parent.parent.parent, parent.parent, parent, node];
case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
case (parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
case (parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
return [parent.parent.parent, parent.parent, parent, node];
case (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
return [parent.parent.parent, parent.parent, parent, node];
}
return unit;
//#endregion
//#region src/expression-base.ts
/**
* Unwraps any type expressions to get the underlying JavaScript expression node.
* Recursively processes nodes until a non-type expression is found.
*
* @param node - The AST node to unwrap
* @returns The underlying JavaScript expression node
*/
function getUnderlyingExpression(node) {
if (isTypeExpression(node)) return getUnderlyingExpression(node.expression);
return node;
}
function hasCallInFunctionInitPath(callName, initPath) {
return initPath.some((n) => {
if (n.type !== AST_NODE_TYPES.CallExpression) {
return false;
}
switch (n.callee.type) {
case AST_NODE_TYPES.Identifier:
return n.callee.name === callName;
case AST_NODE_TYPES.MemberExpression:
return "name" in n.callee.property && n.callee.property.name === callName;
default:
return false;
}
});
//#endregion
//#region src/expression-is.ts
/**
* Checks if the given expression is a 'this' expression.
* Unwraps any type expressions before checking.
*
* @param node - The expression node to check
* @returns true if the expression is a ThisExpression, false otherwise
*/
function isThisExpression(node) {
return getUnderlyingExpression(node).type === AST_NODE_TYPES.ThisExpression;
}
function isEmptyFunction(node) {
return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
}
function isImmediatelyInvokedFunction(node) {
return node.type !== AST_NODE_TYPES.FunctionDeclaration && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
}
//#endregion
//#region src/traverse-up.ts
function findParentNode(node, test) {
if (node == null) return unit;
let parent = node.parent;
while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
if (test(parent)) {
return parent;
}
parent = parent.parent;
}
return unit;
if (node == null) return unit;
let parent = node.parent;
while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
if (test(parent)) return parent;
parent = parent.parent;
}
return unit;
}
//#endregion
//#region src/expression-nested.ts
/**
* Get all nested identifiers in a expression like node
* @param node The node to get the nested identifiers from
* @returns All nested identifiers
*/
function getNestedIdentifiers(node) {
const identifiers = [];
if (node.type === AST_NODE_TYPES.Identifier) {
identifiers.push(node);
}
if ("arguments" in node) {
const chunk = node.arguments.map(getNestedIdentifiers).flat(1);
identifiers.push(...chunk);
}
if ("elements" in node) {
const chunk = node.elements.filter((x) => x != null).map(getNestedIdentifiers).flat(1);
identifiers.push(...chunk);
}
if ("properties" in node) {
const chunk = node.properties.map(getNestedIdentifiers).flat(1);
identifiers.push(...chunk);
}
if ("expressions" in node) {
const chunk = node.expressions.map(getNestedIdentifiers).flat(1);
identifiers.push(...chunk);
}
if ("left" in node) {
const chunk = getNestedIdentifiers(node.left);
identifiers.push(...chunk);
}
if ("right" in node) {
const chunk = getNestedIdentifiers(node.right);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.Property) {
const chunk = getNestedIdentifiers(node.value);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.SpreadElement) {
const chunk = getNestedIdentifiers(node.argument);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.MemberExpression) {
const chunk = getNestedIdentifiers(node.object);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.UnaryExpression) {
const chunk = getNestedIdentifiers(node.argument);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.ChainExpression) {
const chunk = getNestedIdentifiers(node.expression);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
const chunk = getNestedIdentifiers(node.expression);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSAsExpression) {
const chunk = getNestedIdentifiers(node.expression);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
const chunk = getNestedIdentifiers(node.expression);
identifiers.push(...chunk);
}
return identifiers;
const identifiers = [];
if (node.type === AST_NODE_TYPES.Identifier) identifiers.push(node);
if ("arguments" in node) {
const chunk = node.arguments.map(getNestedIdentifiers).flat(1);
identifiers.push(...chunk);
}
if ("elements" in node) {
const chunk = node.elements.filter((x) => x != null).map(getNestedIdentifiers).flat(1);
identifiers.push(...chunk);
}
if ("properties" in node) {
const chunk = node.properties.map(getNestedIdentifiers).flat(1);
identifiers.push(...chunk);
}
if ("expressions" in node) {
const chunk = node.expressions.map(getNestedIdentifiers).flat(1);
identifiers.push(...chunk);
}
if ("left" in node) {
const chunk = getNestedIdentifiers(node.left);
identifiers.push(...chunk);
}
if ("right" in node) {
const chunk = getNestedIdentifiers(node.right);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.Property) {
const chunk = getNestedIdentifiers(node.value);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.SpreadElement) {
const chunk = getNestedIdentifiers(node.argument);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.MemberExpression) {
const chunk = getNestedIdentifiers(node.object);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.UnaryExpression) {
const chunk = getNestedIdentifiers(node.argument);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.ChainExpression) {
const chunk = getNestedIdentifiers(node.expression);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
const chunk = getNestedIdentifiers(node.expression);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSAsExpression) {
const chunk = getNestedIdentifiers(node.expression);
identifiers.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
const chunk = getNestedIdentifiers(node.expression);
identifiers.push(...chunk);
}
return identifiers;
}
/**
* Gets the nested return statements in the node that are within the same function
* @param node The AST node
* @returns The nested return statements in the node
*/
function getNestedReturnStatements(node) {
const statements = [];
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
simpleTraverse(node, {
enter(node2) {
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
return;
}
const parentFunction = findParentNode(node2, isFunction);
if (parentFunction !== boundaryNode) {
return;
}
statements.push(node2);
}
});
return statements;
const statements = [];
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
simpleTraverse(node, { enter(node$1) {
if (node$1.type !== AST_NODE_TYPES.ReturnStatement) return;
const parentFunction = findParentNode(node$1, isFunction);
if (parentFunction !== boundaryNode) return;
statements.push(node$1);
} });
return statements;
}
/**
* Get all nested expressions of type T in an expression like node
* @param type The type of the expression to retrieve within the node
* @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
* node, and it will return an array of all nested expressions of type T.
*/
function getNestedExpressionsOfType(type) {
const isNodeOfType = is(type);
return function(node) {
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
const expressions = [];
if (isNodeOfType(node)) {
expressions.push(node);
}
if ("arguments" in node) {
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
expressions.push(...chunk);
}
if ("expression" in node && node.expression !== true && node.expression !== false) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
if ("left" in node) {
const chunk = boundGetNestedExpressionsOfType(node.left);
expressions.push(...chunk);
}
if ("right" in node) {
const chunk = boundGetNestedExpressionsOfType(node.right);
expressions.push(...chunk);
}
if ("test" in node && node.test != null) {
const chunk = boundGetNestedExpressionsOfType(node.test);
expressions.push(...chunk);
}
if ("consequent" in node) {
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
expressions.push(...chunk);
}
if ("alternate" in node && node.alternate != null) {
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
expressions.push(...chunk);
}
if ("elements" in node) {
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
expressions.push(...chunk);
}
if ("properties" in node) {
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
expressions.push(...chunk);
}
if ("expressions" in node) {
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.Property) {
const chunk = boundGetNestedExpressionsOfType(node.value);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.SpreadElement) {
const chunk = boundGetNestedExpressionsOfType(node.argument);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.MemberExpression) {
const chunk = boundGetNestedExpressionsOfType(node.object);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.UnaryExpression) {
const chunk = boundGetNestedExpressionsOfType(node.argument);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.ChainExpression) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSAsExpression) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
return expressions;
};
const isNodeOfType = is(type);
return function(node) {
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
const expressions = [];
if (isNodeOfType(node)) expressions.push(node);
if ("arguments" in node) {
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
expressions.push(...chunk);
}
if ("expression" in node && node.expression !== true && node.expression !== false) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
if ("left" in node) {
const chunk = boundGetNestedExpressionsOfType(node.left);
expressions.push(...chunk);
}
if ("right" in node) {
const chunk = boundGetNestedExpressionsOfType(node.right);
expressions.push(...chunk);
}
if ("test" in node && node.test != null) {
const chunk = boundGetNestedExpressionsOfType(node.test);
expressions.push(...chunk);
}
if ("consequent" in node) {
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
expressions.push(...chunk);
}
if ("alternate" in node && node.alternate != null) {
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
expressions.push(...chunk);
}
if ("elements" in node) {
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
expressions.push(...chunk);
}
if ("properties" in node) {
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
expressions.push(...chunk);
}
if ("expressions" in node) {
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.Property) {
const chunk = boundGetNestedExpressionsOfType(node.value);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.SpreadElement) {
const chunk = boundGetNestedExpressionsOfType(node.argument);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.MemberExpression) {
const chunk = boundGetNestedExpressionsOfType(node.object);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.UnaryExpression) {
const chunk = boundGetNestedExpressionsOfType(node.argument);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.ChainExpression) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSAsExpression) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
const chunk = boundGetNestedExpressionsOfType(node.expression);
expressions.push(...chunk);
}
return expressions;
};
}
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
function isMultiLine(node) {
return node.loc.start.line !== node.loc.end.line;
/**
* Get all nested new expressions in an expression like node
* @param node The node to get the nested new expressions from
* @returns All nested new expressions
*/
const getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
/**
* Get all nested call expressions in a expression like node
* @param node The node to get the nested call expressions from
* @returns All nested call expressions
*/
const getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
//#endregion
//#region src/function-id.ts
/**
* Gets the static name of a function AST node. For function declarations it is
* easy. For anonymous function expressions it is much harder. If you search for
* `IsAnonymousFunctionDefinition()` in the ECMAScript spec you'll find places
* where JS gives anonymous function expressions names. We roughly detect the
* same AST nodes with some exceptions to better fit our use case.
*/
function getFunctionId(node) {
switch (true) {
case "id" in node && node.id != null: return node.id;
case node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier: return node.parent.id;
case node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier: return node.parent.left;
case node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier: return node.parent.key;
case isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier: return node.parent.key;
case node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier: return node.parent.left;
case isTypeAssertionExpression(node.parent): return getFunctionId(node.parent);
}
return unit;
}
function isLineBreak(node) {
return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
//#endregion
//#region src/function-init-path.ts
/**
* Identifies the initialization path of a function node in the AST.
* Determines what kind of component declaration pattern the function belongs to.
*
* @param node - The function node to analyze
* @returns The function initialization path or unit if not identifiable
*/
function getFunctionInitPath(node) {
if (node.type === AST_NODE_TYPES.FunctionDeclaration) return [node];
const { parent } = node;
switch (true) {
case parent.type === AST_NODE_TYPES.VariableDeclarator: return [
parent.parent,
parent,
node
];
case parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator: return [
parent.parent.parent,
parent.parent,
parent,
node
];
case parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator: return [
parent.parent.parent.parent,
parent.parent.parent,
parent.parent,
parent,
node
];
case parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator: return [
parent.parent.parent.parent,
parent.parent.parent,
parent.parent,
parent,
node
];
case parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration: return [
parent.parent.parent,
parent.parent,
parent,
node
];
case parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration: return [
parent.parent.parent,
parent.parent,
parent,
node
];
}
return unit;
}
function isLiteral(node, type) {
if (node.type !== AST_NODE_TYPES.Literal) return false;
if (type == null) return true;
switch (type) {
case "boolean":
return typeof node.value === "boolean";
case "null":
return node.value === null;
case "number":
return typeof node.value === "number";
case "regexp":
return "regex" in node;
case "string":
return typeof node.value === "string";
}
/**
* Checks if a specific function call exists in the function initialization path.
* Useful for detecting HOCs like React.memo, React.forwardRef, etc.
*
* @param callName - The name of the call to check for (e.g., "memo", "forwardRef")
* @param initPath - The function initialization path to search in
* @returns True if the call exists in the path, false otherwise
*/
function hasCallInFunctionInitPath(callName, initPath) {
return initPath.some((node) => {
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
const { callee } = node;
if (callee.type === AST_NODE_TYPES.Identifier) return callee.name === callName;
if (callee.type === AST_NODE_TYPES.MemberExpression && "name" in callee.property) return callee.property.name === callName;
return false;
});
}
var isNodeEqual = dual(2, (a, b) => {
switch (true) {
case a === b:
return true;
case a.type !== b.type:
return false;
case (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal):
return a.value === b.value;
case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement):
return a.value.raw === b.value.raw;
case (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral): {
if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) {
return false;
}
let i = a.quasis.length;
while (i--) {
if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) {
return false;
}
}
i = a.expressions.length;
while (i--) {
const exprA = a.expressions[i];
const exprB = b.expressions[i];
if (!isNodeEqual(exprA, exprB)) {
return false;
}
}
return true;
}
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier):
return a.name === b.name;
case (a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier):
return a.name === b.name;
case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression):
return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
case (a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute): {
if (a.name.name !== b.name.name) {
return false;
}
if (a.value == null || b.value == null) {
return a.value === b.value;
}
return isNodeEqual(a.value, b.value);
}
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression):
return true;
default:
return false;
}
});
function getLiteralValueType(input) {
if (input === null) return "null";
return typeof input;
//#endregion
//#region src/function-is.ts
function isFunctionEmpty(node) {
return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
}
function toDelimiterFormat(node, delimiter = " ") {
if (node.type === AST_NODE_TYPES.Literal) {
if ("regex" in node) {
return "RegExp literal";
}
return `${getLiteralValueType(node.value)} literal`;
}
if (isJSX(node)) {
return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
}
return toLowerCase(delimiterCase(node.type, delimiter));
function isFunctionImmediatelyInvoked(node) {
return node.type !== AST_NODE_TYPES.FunctionDeclaration && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
}
function toStringFormat(node, getText) {
switch (node.type) {
case AST_NODE_TYPES.Identifier:
case AST_NODE_TYPES.JSXIdentifier:
case AST_NODE_TYPES.PrivateIdentifier:
return node.name;
case AST_NODE_TYPES.MemberExpression:
case AST_NODE_TYPES.JSXMemberExpression:
return `${toStringFormat(node.object, getText)}.${toStringFormat(node.property, getText)}`;
case AST_NODE_TYPES.JSXNamespacedName:
return `${node.namespace.name}:${node.name.name}`;
case AST_NODE_TYPES.JSXText:
return node.value;
case AST_NODE_TYPES.Literal:
return node.raw;
default:
return getText(node);
}
//#endregion
//#region src/literal.ts
function isLiteral(node, type) {
if (node.type !== AST_NODE_TYPES.Literal) return false;
if (type == null) return true;
switch (type) {
case "boolean": return typeof node.value === "boolean";
case "null": return node.value === null;
case "number": return typeof node.value === "number";
case "regexp": return "regex" in node;
case "string": return typeof node.value === "string";
}
}
function isProcessEnvNodeEnv(node) {
return node != null && node.type === AST_NODE_TYPES.MemberExpression && node.object.type === AST_NODE_TYPES.MemberExpression && node.object.object.type === AST_NODE_TYPES.Identifier && node.object.object.name === "process" && node.object.property.type === AST_NODE_TYPES.Identifier && node.object.property.name === "env" && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === "NODE_ENV";
//#endregion
//#region src/misc.ts
/**
* Check if a node is multiline
* @param node The AST node to check
* @returns `true` if the node is multiline
*/
function isMultiLine(node) {
return node.loc.start.line !== node.loc.end.line;
}
function isProcessEnvNodeEnvCompare(node, operator, value) {
if (node == null) return false;
if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
if (node.operator !== operator) return false;
if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) {
return node.right.value === value;
}
if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) {
return node.left.value === value;
}
return false;
/**
* Check if a node is a line break
* @param node The AST node to check
* @returns boolean
*/
function isLineBreak(node) {
return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
}
function getPropertyName(node) {
if (isTypeExpression(node)) {
return getPropertyName(getJSExpression(node));
}
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
return node.name;
}
if (node.type === AST_NODE_TYPES.Literal) {
return String(node.value);
}
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
return node.quasis[0]?.value.raw;
}
return unit;
}
//#endregion
//#region src/promise-then.ts
function isThenCall(node) {
return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "then";
return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "then";
}
export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isImmediatelyInvokedFunction, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterFormat, toStringFormat };
//#endregion
//#region src/property-name.ts
function getPropertyName(node) {
if (isTypeExpression(node)) return getPropertyName(getUnderlyingExpression(node));
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) return node.name;
if (node.type === AST_NODE_TYPES.Literal) return String(node.value);
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.raw;
return unit;
}
//#endregion
export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterFormat, toStringFormat };
{
"name": "@eslint-react/ast",
"version": "2.0.0-next.58",
"version": "2.0.0-next.61",
"description": "ESLint React's TSESTree AST utility module.",

@@ -30,19 +30,18 @@ "homepage": "https://github.com/Rel1cx/eslint-react",

"dependencies": {
"@typescript-eslint/types": "^8.35.0",
"@typescript-eslint/typescript-estree": "^8.35.0",
"@typescript-eslint/utils": "^8.35.0",
"@typescript-eslint/types": "^8.41.0",
"@typescript-eslint/typescript-estree": "^8.41.0",
"@typescript-eslint/utils": "^8.41.0",
"string-ts": "^2.2.1",
"ts-pattern": "^5.7.1",
"@eslint-react/eff": "2.0.0-next.58"
"ts-pattern": "^5.8.0",
"@eslint-react/eff": "2.0.0-next.61"
},
"devDependencies": {
"tsup": "^8.5.0",
"tsdown": "^0.14.2",
"@local/configs": "0.0.0"
},
"engines": {
"bun": ">=1.0.15",
"node": ">=20.19.0"
},
"scripts": {
"build": "tsup",
"build": "tsdown --dts-resolve",
"lint:publish": "publint",

@@ -49,0 +48,0 @@ "lint:ts": "tsc --noEmit"

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.