@eslint-react/ast
Advanced tools
Comparing version
@@ -23,7 +23,2 @@ import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/types'; | ||
/** | ||
* Gets class identifier from ClassDeclaration or ClassExpression | ||
* @param node The AST node to check | ||
* @returns class identifier or null | ||
*/ | ||
declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | _; | ||
@@ -46,3 +41,2 @@ | ||
*/ | ||
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _; | ||
@@ -152,2 +146,3 @@ | ||
declare function isEmptyFunction(node: TSESTreeFunction): boolean; | ||
declare function isImmediatelyInvokedFunction(node: TSESTreeFunction): boolean; | ||
@@ -203,28 +198,2 @@ /** | ||
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 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; | ||
/** | ||
@@ -263,2 +232,37 @@ * Check if a node is multiline | ||
/** | ||
* @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; | ||
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 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` | ||
@@ -280,11 +284,4 @@ * @param node The AST node | ||
declare function toDelimiterCaseType(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`; | ||
/** | ||
* Returns human readable node name for given AST node | ||
* @param node AST node | ||
* @param getText A function that returns the text of the node in the source code | ||
* @returns Human readable node name | ||
*/ | ||
declare function toString(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string; | ||
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, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterCaseType, toString }; | ||
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 }; |
@@ -1,14 +0,12 @@ | ||
'use strict'; | ||
import { AST_NODE_TYPES } from '@typescript-eslint/types'; | ||
import { or, dual, _ } from '@eslint-react/eff'; | ||
import { ASTUtils } from '@typescript-eslint/utils'; | ||
import { simpleTraverse } from '@typescript-eslint/typescript-estree'; | ||
import { toLowerCase, delimiterCase, replace } from 'string-ts'; | ||
var types = require('@typescript-eslint/types'); | ||
var eff = require('@eslint-react/eff'); | ||
var utils = require('@typescript-eslint/utils'); | ||
var typescriptEstree = require('@typescript-eslint/typescript-estree'); | ||
var stringTs = require('string-ts'); | ||
// src/ast-array-method.ts | ||
function isArrayFromCall(node, loose = true) { | ||
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false; | ||
if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false; | ||
if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false; | ||
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; | ||
@@ -18,5 +16,5 @@ return name === "from" || loose && name.startsWith("from"); | ||
function isArrayMapCall(node, loose = true) { | ||
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false; | ||
if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false; | ||
if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false; | ||
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; | ||
@@ -46,149 +44,149 @@ return name === "map" || loose && name.endsWith("Map"); | ||
if (node.id != null) return node.id; | ||
if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) { | ||
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) { | ||
return node.parent.id; | ||
} | ||
return eff._; | ||
return _; | ||
} | ||
var is = utils.ASTUtils.isNodeOfType; | ||
var isOneOf = utils.ASTUtils.isNodeOfTypes; | ||
var is = ASTUtils.isNodeOfType; | ||
var isOneOf = ASTUtils.isNodeOfTypes; | ||
var isFunction = isOneOf([ | ||
types.AST_NODE_TYPES.ArrowFunctionExpression, | ||
types.AST_NODE_TYPES.FunctionDeclaration, | ||
types.AST_NODE_TYPES.FunctionExpression | ||
AST_NODE_TYPES.ArrowFunctionExpression, | ||
AST_NODE_TYPES.FunctionDeclaration, | ||
AST_NODE_TYPES.FunctionExpression | ||
]); | ||
var isFunctionType = isOneOf([ | ||
types.AST_NODE_TYPES.ArrowFunctionExpression, | ||
types.AST_NODE_TYPES.FunctionDeclaration, | ||
types.AST_NODE_TYPES.FunctionExpression, | ||
types.AST_NODE_TYPES.TSCallSignatureDeclaration, | ||
types.AST_NODE_TYPES.TSConstructSignatureDeclaration, | ||
types.AST_NODE_TYPES.TSDeclareFunction, | ||
types.AST_NODE_TYPES.TSEmptyBodyFunctionExpression, | ||
types.AST_NODE_TYPES.TSFunctionType, | ||
types.AST_NODE_TYPES.TSMethodSignature | ||
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([types.AST_NODE_TYPES.ClassDeclaration, types.AST_NODE_TYPES.ClassExpression]); | ||
var isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]); | ||
var isMethodOrProperty = isOneOf([ | ||
types.AST_NODE_TYPES.PropertyDefinition, | ||
types.AST_NODE_TYPES.MethodDefinition | ||
AST_NODE_TYPES.PropertyDefinition, | ||
AST_NODE_TYPES.MethodDefinition | ||
]); | ||
var isLoop = isOneOf([ | ||
types.AST_NODE_TYPES.DoWhileStatement, | ||
types.AST_NODE_TYPES.ForInStatement, | ||
types.AST_NODE_TYPES.ForOfStatement, | ||
types.AST_NODE_TYPES.ForStatement, | ||
types.AST_NODE_TYPES.WhileStatement | ||
AST_NODE_TYPES.DoWhileStatement, | ||
AST_NODE_TYPES.ForInStatement, | ||
AST_NODE_TYPES.ForOfStatement, | ||
AST_NODE_TYPES.ForStatement, | ||
AST_NODE_TYPES.WhileStatement | ||
]); | ||
var isControlFlow = eff.or( | ||
var isControlFlow = or( | ||
isLoop, | ||
isOneOf([ | ||
types.AST_NODE_TYPES.IfStatement, | ||
types.AST_NODE_TYPES.SwitchStatement | ||
AST_NODE_TYPES.IfStatement, | ||
AST_NODE_TYPES.SwitchStatement | ||
]) | ||
); | ||
var isConditional = eff.or( | ||
var isConditional = or( | ||
isControlFlow, | ||
isOneOf([ | ||
types.AST_NODE_TYPES.LogicalExpression, | ||
types.AST_NODE_TYPES.ConditionalExpression | ||
AST_NODE_TYPES.LogicalExpression, | ||
AST_NODE_TYPES.ConditionalExpression | ||
]) | ||
); | ||
var isArrayTupleType = isOneOf([types.AST_NODE_TYPES.TSArrayType, types.AST_NODE_TYPES.TSTupleType]); | ||
var isArrayTupleType = isOneOf([AST_NODE_TYPES.TSArrayType, AST_NODE_TYPES.TSTupleType]); | ||
var isProperty = isOneOf([ | ||
types.AST_NODE_TYPES.PropertyDefinition, | ||
types.AST_NODE_TYPES.TSIndexSignature, | ||
types.AST_NODE_TYPES.TSParameterProperty, | ||
types.AST_NODE_TYPES.TSPropertySignature | ||
AST_NODE_TYPES.PropertyDefinition, | ||
AST_NODE_TYPES.TSIndexSignature, | ||
AST_NODE_TYPES.TSParameterProperty, | ||
AST_NODE_TYPES.TSPropertySignature | ||
]); | ||
var isJSXElement = is(types.AST_NODE_TYPES.JSXElement); | ||
var isJSXFragment = is(types.AST_NODE_TYPES.JSXFragment); | ||
var isJSXElement = is(AST_NODE_TYPES.JSXElement); | ||
var isJSXFragment = is(AST_NODE_TYPES.JSXFragment); | ||
var isJSXTagNameExpression = isOneOf([ | ||
types.AST_NODE_TYPES.JSXIdentifier, | ||
types.AST_NODE_TYPES.JSXMemberExpression, | ||
types.AST_NODE_TYPES.JSXNamespacedName | ||
AST_NODE_TYPES.JSXIdentifier, | ||
AST_NODE_TYPES.JSXMemberExpression, | ||
AST_NODE_TYPES.JSXNamespacedName | ||
]); | ||
var isJSX = isOneOf([ | ||
types.AST_NODE_TYPES.JSXAttribute, | ||
types.AST_NODE_TYPES.JSXClosingElement, | ||
types.AST_NODE_TYPES.JSXClosingFragment, | ||
types.AST_NODE_TYPES.JSXElement, | ||
types.AST_NODE_TYPES.JSXEmptyExpression, | ||
types.AST_NODE_TYPES.JSXExpressionContainer, | ||
types.AST_NODE_TYPES.JSXFragment, | ||
types.AST_NODE_TYPES.JSXIdentifier, | ||
types.AST_NODE_TYPES.JSXMemberExpression, | ||
types.AST_NODE_TYPES.JSXNamespacedName, | ||
types.AST_NODE_TYPES.JSXOpeningElement, | ||
types.AST_NODE_TYPES.JSXOpeningFragment, | ||
types.AST_NODE_TYPES.JSXSpreadAttribute, | ||
types.AST_NODE_TYPES.JSXSpreadChild, | ||
types.AST_NODE_TYPES.JSXText | ||
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 isDestructuringPattern = isOneOf([ | ||
types.AST_NODE_TYPES.ArrayPattern, | ||
types.AST_NODE_TYPES.AssignmentPattern, | ||
types.AST_NODE_TYPES.ObjectPattern, | ||
types.AST_NODE_TYPES.RestElement | ||
AST_NODE_TYPES.ArrayPattern, | ||
AST_NODE_TYPES.AssignmentPattern, | ||
AST_NODE_TYPES.ObjectPattern, | ||
AST_NODE_TYPES.RestElement | ||
]); | ||
var isTypeDeclaration = isOneOf([ | ||
types.AST_NODE_TYPES.TSInterfaceDeclaration, | ||
types.AST_NODE_TYPES.TSTypeAliasDeclaration | ||
AST_NODE_TYPES.TSInterfaceDeclaration, | ||
AST_NODE_TYPES.TSTypeAliasDeclaration | ||
]); | ||
var isLeftHandSideExpression = isOneOf([ | ||
types.AST_NODE_TYPES.ArrayExpression, | ||
types.AST_NODE_TYPES.ArrayPattern, | ||
types.AST_NODE_TYPES.ArrowFunctionExpression, | ||
types.AST_NODE_TYPES.CallExpression, | ||
types.AST_NODE_TYPES.ClassExpression, | ||
types.AST_NODE_TYPES.FunctionExpression, | ||
types.AST_NODE_TYPES.Identifier, | ||
types.AST_NODE_TYPES.JSXElement, | ||
types.AST_NODE_TYPES.JSXFragment, | ||
types.AST_NODE_TYPES.Literal, | ||
types.AST_NODE_TYPES.TemplateLiteral, | ||
types.AST_NODE_TYPES.MemberExpression, | ||
types.AST_NODE_TYPES.MetaProperty, | ||
types.AST_NODE_TYPES.ObjectExpression, | ||
types.AST_NODE_TYPES.ObjectPattern, | ||
types.AST_NODE_TYPES.SequenceExpression, | ||
types.AST_NODE_TYPES.Super, | ||
types.AST_NODE_TYPES.TaggedTemplateExpression, | ||
types.AST_NODE_TYPES.ThisExpression | ||
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([ | ||
types.AST_NODE_TYPES.ArrayExpression, | ||
types.AST_NODE_TYPES.ArrayPattern, | ||
types.AST_NODE_TYPES.ArrowFunctionExpression, | ||
types.AST_NODE_TYPES.CallExpression, | ||
types.AST_NODE_TYPES.ClassExpression, | ||
types.AST_NODE_TYPES.FunctionExpression, | ||
types.AST_NODE_TYPES.Identifier, | ||
types.AST_NODE_TYPES.JSXElement, | ||
types.AST_NODE_TYPES.JSXFragment, | ||
types.AST_NODE_TYPES.Literal, | ||
types.AST_NODE_TYPES.TemplateLiteral, | ||
types.AST_NODE_TYPES.MemberExpression, | ||
types.AST_NODE_TYPES.MetaProperty, | ||
types.AST_NODE_TYPES.ObjectExpression, | ||
types.AST_NODE_TYPES.ObjectPattern, | ||
types.AST_NODE_TYPES.SequenceExpression, | ||
types.AST_NODE_TYPES.Super, | ||
types.AST_NODE_TYPES.TaggedTemplateExpression, | ||
types.AST_NODE_TYPES.ThisExpression, | ||
types.AST_NODE_TYPES.TSAsExpression, | ||
types.AST_NODE_TYPES.TSNonNullExpression, | ||
types.AST_NODE_TYPES.TSTypeAssertion | ||
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([ | ||
types.AST_NODE_TYPES.TSAsExpression, | ||
types.AST_NODE_TYPES.TSTypeAssertion, | ||
types.AST_NODE_TYPES.TSNonNullExpression, | ||
types.AST_NODE_TYPES.TSSatisfiesExpression, | ||
types.AST_NODE_TYPES.TSInstantiationExpression | ||
AST_NODE_TYPES.TSAsExpression, | ||
AST_NODE_TYPES.TSTypeAssertion, | ||
AST_NODE_TYPES.TSNonNullExpression, | ||
AST_NODE_TYPES.TSSatisfiesExpression, | ||
AST_NODE_TYPES.TSInstantiationExpression | ||
]); | ||
var isTypeAssertionExpression = isOneOf([ | ||
types.AST_NODE_TYPES.TSAsExpression, | ||
types.AST_NODE_TYPES.TSTypeAssertion, | ||
types.AST_NODE_TYPES.TSNonNullExpression, | ||
types.AST_NODE_TYPES.TSSatisfiesExpression | ||
AST_NODE_TYPES.TSAsExpression, | ||
AST_NODE_TYPES.TSTypeAssertion, | ||
AST_NODE_TYPES.TSNonNullExpression, | ||
AST_NODE_TYPES.TSSatisfiesExpression | ||
]); | ||
@@ -204,3 +202,3 @@ | ||
function isThisExpression(node) { | ||
return getJSExpression(node).type === types.AST_NODE_TYPES.ThisExpression; | ||
return getJSExpression(node).type === AST_NODE_TYPES.ThisExpression; | ||
} | ||
@@ -213,14 +211,14 @@ function getFunctionId(node) { | ||
// const whatever = function MaybeComponent() {}; | ||
case (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === types.AST_NODE_TYPES.Identifier): | ||
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 === types.AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === types.AST_NODE_TYPES.Identifier): | ||
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 === types.AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === types.AST_NODE_TYPES.Identifier): | ||
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 === types.AST_NODE_TYPES.Identifier): | ||
case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier): | ||
return node.parent.key; | ||
@@ -231,3 +229,3 @@ // Follow spec convention for `IsAnonymousFunctionDefinition()` usage. | ||
// ({MaybeComponent = () => {}} = {}); | ||
case (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier): | ||
case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier): | ||
return node.parent.left; | ||
@@ -240,6 +238,6 @@ // const MaybeComponent = (() => {})!; | ||
} | ||
return eff._; | ||
return _; | ||
} | ||
function getFunctionInitPath(node) { | ||
if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) { | ||
if (node.type === AST_NODE_TYPES.FunctionDeclaration) { | ||
return [node]; | ||
@@ -249,26 +247,26 @@ } | ||
switch (true) { | ||
case parent.type === types.AST_NODE_TYPES.VariableDeclarator: | ||
case parent.type === AST_NODE_TYPES.VariableDeclarator: | ||
return [parent.parent, parent, node]; | ||
case (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator): | ||
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 === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator): | ||
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 === types.AST_NODE_TYPES.Property && parent.parent.type === types.AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator): | ||
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 === types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration): | ||
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 === types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration): | ||
case (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration): | ||
return [parent.parent.parent, parent.parent, parent, node]; | ||
} | ||
return eff._; | ||
return _; | ||
} | ||
function hasCallInFunctionInitPath(callName, initPath) { | ||
return initPath.some((n) => { | ||
if (n.type !== types.AST_NODE_TYPES.CallExpression) { | ||
if (n.type !== AST_NODE_TYPES.CallExpression) { | ||
return false; | ||
} | ||
switch (n.callee.type) { | ||
case types.AST_NODE_TYPES.Identifier: | ||
case AST_NODE_TYPES.Identifier: | ||
return n.callee.name === callName; | ||
case types.AST_NODE_TYPES.MemberExpression: | ||
case AST_NODE_TYPES.MemberExpression: | ||
return "name" in n.callee.property && n.callee.property.name === callName; | ||
@@ -281,8 +279,11 @@ default: | ||
function isEmptyFunction(node) { | ||
return node.body.type === types.AST_NODE_TYPES.BlockStatement && node.body.body.length === 0; | ||
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; | ||
} | ||
function findParentNode(node, test) { | ||
if (node == null) return eff._; | ||
if (node == null) return _; | ||
let parent = node.parent; | ||
while (parent != null && parent.type !== types.AST_NODE_TYPES.Program) { | ||
while (parent != null && parent.type !== AST_NODE_TYPES.Program) { | ||
if (test(parent)) { | ||
@@ -293,7 +294,7 @@ return parent; | ||
} | ||
return eff._; | ||
return _; | ||
} | ||
function getNestedIdentifiers(node) { | ||
const identifiers = []; | ||
if (node.type === types.AST_NODE_TYPES.Identifier) { | ||
if (node.type === AST_NODE_TYPES.Identifier) { | ||
identifiers.push(node); | ||
@@ -325,31 +326,31 @@ } | ||
} | ||
if (node.type === types.AST_NODE_TYPES.Property) { | ||
if (node.type === AST_NODE_TYPES.Property) { | ||
const chunk = getNestedIdentifiers(node.value); | ||
identifiers.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.SpreadElement) { | ||
if (node.type === AST_NODE_TYPES.SpreadElement) { | ||
const chunk = getNestedIdentifiers(node.argument); | ||
identifiers.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.MemberExpression) { | ||
if (node.type === AST_NODE_TYPES.MemberExpression) { | ||
const chunk = getNestedIdentifiers(node.object); | ||
identifiers.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.UnaryExpression) { | ||
if (node.type === AST_NODE_TYPES.UnaryExpression) { | ||
const chunk = getNestedIdentifiers(node.argument); | ||
identifiers.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.ChainExpression) { | ||
if (node.type === AST_NODE_TYPES.ChainExpression) { | ||
const chunk = getNestedIdentifiers(node.expression); | ||
identifiers.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.TSNonNullExpression) { | ||
if (node.type === AST_NODE_TYPES.TSNonNullExpression) { | ||
const chunk = getNestedIdentifiers(node.expression); | ||
identifiers.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.TSAsExpression) { | ||
if (node.type === AST_NODE_TYPES.TSAsExpression) { | ||
const chunk = getNestedIdentifiers(node.expression); | ||
identifiers.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) { | ||
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) { | ||
const chunk = getNestedIdentifiers(node.expression); | ||
@@ -363,5 +364,5 @@ identifiers.push(...chunk); | ||
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction); | ||
typescriptEstree.simpleTraverse(node, { | ||
simpleTraverse(node, { | ||
enter(node2) { | ||
if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) { | ||
if (node2.type !== AST_NODE_TYPES.ReturnStatement) { | ||
return; | ||
@@ -426,31 +427,31 @@ } | ||
} | ||
if (node.type === types.AST_NODE_TYPES.Property) { | ||
if (node.type === AST_NODE_TYPES.Property) { | ||
const chunk = boundGetNestedExpressionsOfType(node.value); | ||
expressions.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.SpreadElement) { | ||
if (node.type === AST_NODE_TYPES.SpreadElement) { | ||
const chunk = boundGetNestedExpressionsOfType(node.argument); | ||
expressions.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.MemberExpression) { | ||
if (node.type === AST_NODE_TYPES.MemberExpression) { | ||
const chunk = boundGetNestedExpressionsOfType(node.object); | ||
expressions.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.UnaryExpression) { | ||
if (node.type === AST_NODE_TYPES.UnaryExpression) { | ||
const chunk = boundGetNestedExpressionsOfType(node.argument); | ||
expressions.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.ChainExpression) { | ||
if (node.type === AST_NODE_TYPES.ChainExpression) { | ||
const chunk = boundGetNestedExpressionsOfType(node.expression); | ||
expressions.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.TSNonNullExpression) { | ||
if (node.type === AST_NODE_TYPES.TSNonNullExpression) { | ||
const chunk = boundGetNestedExpressionsOfType(node.expression); | ||
expressions.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.TSAsExpression) { | ||
if (node.type === AST_NODE_TYPES.TSAsExpression) { | ||
const chunk = boundGetNestedExpressionsOfType(node.expression); | ||
expressions.push(...chunk); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) { | ||
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) { | ||
const chunk = boundGetNestedExpressionsOfType(node.expression); | ||
@@ -462,4 +463,4 @@ expressions.push(...chunk); | ||
} | ||
var getNestedNewExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.NewExpression); | ||
var getNestedCallExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.CallExpression); | ||
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression); | ||
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression); | ||
function isMultiLine(node) { | ||
@@ -469,6 +470,6 @@ return node.loc.start.line !== node.loc.end.line; | ||
function isLineBreak(node) { | ||
return isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node); | ||
return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node); | ||
} | ||
function isLiteral(node, type) { | ||
if (node.type !== types.AST_NODE_TYPES.Literal) return false; | ||
if (node.type !== AST_NODE_TYPES.Literal) return false; | ||
if (type == null) return true; | ||
@@ -488,3 +489,3 @@ switch (type) { | ||
} | ||
var isNodeEqual = eff.dual(2, (a, b) => { | ||
var isNodeEqual = dual(2, (a, b) => { | ||
switch (true) { | ||
@@ -495,7 +496,7 @@ case a === b: | ||
return false; | ||
case (a.type === types.AST_NODE_TYPES.Literal && b.type === types.AST_NODE_TYPES.Literal): | ||
case (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal): | ||
return a.value === b.value; | ||
case (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement): | ||
case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement): | ||
return a.value.raw === b.value.raw; | ||
case (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral): { | ||
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) { | ||
@@ -520,9 +521,9 @@ return false; | ||
} | ||
case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier): | ||
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier): | ||
return a.name === b.name; | ||
case (a.type === types.AST_NODE_TYPES.PrivateIdentifier && b.type === types.AST_NODE_TYPES.PrivateIdentifier): | ||
case (a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier): | ||
return a.name === b.name; | ||
case (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression): | ||
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 === types.AST_NODE_TYPES.JSXAttribute && b.type === types.AST_NODE_TYPES.JSXAttribute): { | ||
case (a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute): { | ||
if (a.name.name !== b.name.name) { | ||
@@ -536,3 +537,3 @@ return false; | ||
} | ||
case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression): | ||
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression): | ||
return true; | ||
@@ -543,8 +544,43 @@ default: | ||
}); | ||
function getLiteralValueType(input) { | ||
if (input === null) return "null"; | ||
return typeof input; | ||
} | ||
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 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 isProcessEnvNodeEnv(node) { | ||
return node != null && node.type === types.AST_NODE_TYPES.MemberExpression && node.object.type === types.AST_NODE_TYPES.MemberExpression && node.object.object.type === types.AST_NODE_TYPES.Identifier && node.object.object.name === "process" && node.object.property.type === types.AST_NODE_TYPES.Identifier && node.object.property.name === "env" && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === "NODE_ENV"; | ||
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"; | ||
} | ||
function isProcessEnvNodeEnvCompare(node, operator, value) { | ||
if (node == null) return false; | ||
if (node.type !== types.AST_NODE_TYPES.BinaryExpression) return false; | ||
if (node.type !== AST_NODE_TYPES.BinaryExpression) return false; | ||
if (node.operator !== operator) return false; | ||
@@ -563,94 +599,17 @@ if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) { | ||
} | ||
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) { | ||
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) { | ||
return node.name; | ||
} | ||
if (node.type === types.AST_NODE_TYPES.Literal) { | ||
if (node.type === AST_NODE_TYPES.Literal) { | ||
return String(node.value); | ||
} | ||
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) { | ||
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) { | ||
return node.quasis[0]?.value.raw; | ||
} | ||
return eff._; | ||
return _; | ||
} | ||
function getLiteralValueType(input) { | ||
if (input === null) return "null"; | ||
return typeof input; | ||
function isThenCall(node) { | ||
return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "then"; | ||
} | ||
function toDelimiterCaseType(node, delimiter = " ") { | ||
if (node.type === types.AST_NODE_TYPES.Literal) { | ||
if ("regex" in node) { | ||
return "RegExp literal"; | ||
} | ||
return `${getLiteralValueType(node.value)} literal`; | ||
} | ||
if (isJSX(node)) { | ||
return `JSX ${stringTs.toLowerCase(stringTs.delimiterCase(stringTs.replace(node.type, "JSX", ""), delimiter))}`; | ||
} | ||
return stringTs.toLowerCase(stringTs.delimiterCase(node.type, delimiter)); | ||
} | ||
function toString(node, getText) { | ||
switch (node.type) { | ||
case types.AST_NODE_TYPES.Identifier: | ||
case types.AST_NODE_TYPES.JSXIdentifier: | ||
case types.AST_NODE_TYPES.PrivateIdentifier: | ||
return node.name; | ||
case types.AST_NODE_TYPES.MemberExpression: | ||
case types.AST_NODE_TYPES.JSXMemberExpression: | ||
return `${toString(node.object, getText)}.${toString(node.property, getText)}`; | ||
case types.AST_NODE_TYPES.JSXNamespacedName: | ||
return `${node.namespace.name}:${node.name.name}`; | ||
case types.AST_NODE_TYPES.JSXText: | ||
return node.value; | ||
case types.AST_NODE_TYPES.Literal: | ||
return node.raw; | ||
default: | ||
return getText(node); | ||
} | ||
} | ||
exports.findParentNode = findParentNode; | ||
exports.getArrayMethodCallbackIndexParamPosition = getArrayMethodCallbackIndexParamPosition; | ||
exports.getClassId = getClassId; | ||
exports.getFunctionId = getFunctionId; | ||
exports.getFunctionInitPath = getFunctionInitPath; | ||
exports.getJSExpression = getJSExpression; | ||
exports.getNestedCallExpressions = getNestedCallExpressions; | ||
exports.getNestedExpressionsOfType = getNestedExpressionsOfType; | ||
exports.getNestedIdentifiers = getNestedIdentifiers; | ||
exports.getNestedNewExpressions = getNestedNewExpressions; | ||
exports.getNestedReturnStatements = getNestedReturnStatements; | ||
exports.getPropertyName = getPropertyName; | ||
exports.hasCallInFunctionInitPath = hasCallInFunctionInitPath; | ||
exports.is = is; | ||
exports.isArrayFromCall = isArrayFromCall; | ||
exports.isArrayMapCall = isArrayMapCall; | ||
exports.isArrayTupleType = isArrayTupleType; | ||
exports.isClass = isClass; | ||
exports.isConditional = isConditional; | ||
exports.isControlFlow = isControlFlow; | ||
exports.isDestructuringPattern = isDestructuringPattern; | ||
exports.isEmptyFunction = isEmptyFunction; | ||
exports.isFunction = isFunction; | ||
exports.isFunctionType = isFunctionType; | ||
exports.isJSX = isJSX; | ||
exports.isJSXElement = isJSXElement; | ||
exports.isJSXFragment = isJSXFragment; | ||
exports.isJSXTagNameExpression = isJSXTagNameExpression; | ||
exports.isLeftHandSideExpression = isLeftHandSideExpression; | ||
exports.isLeftHandSideExpressionType = isLeftHandSideExpressionType; | ||
exports.isLineBreak = isLineBreak; | ||
exports.isLiteral = isLiteral; | ||
exports.isLoop = isLoop; | ||
exports.isMethodOrProperty = isMethodOrProperty; | ||
exports.isMultiLine = isMultiLine; | ||
exports.isNodeEqual = isNodeEqual; | ||
exports.isOneOf = isOneOf; | ||
exports.isProcessEnvNodeEnv = isProcessEnvNodeEnv; | ||
exports.isProcessEnvNodeEnvCompare = isProcessEnvNodeEnvCompare; | ||
exports.isProperty = isProperty; | ||
exports.isThisExpression = isThisExpression; | ||
exports.isTypeAssertionExpression = isTypeAssertionExpression; | ||
exports.isTypeDeclaration = isTypeDeclaration; | ||
exports.isTypeExpression = isTypeExpression; | ||
exports.toDelimiterCaseType = toDelimiterCaseType; | ||
exports.toString = toString; | ||
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 }; |
{ | ||
"name": "@eslint-react/ast", | ||
"version": "1.49.0-next.0", | ||
"version": "2.0.0-beta.13", | ||
"description": "ESLint React's TSESTree AST utility module.", | ||
@@ -17,18 +17,10 @@ "homepage": "https://github.com/Rel1cx/eslint-react", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
@@ -44,3 +36,3 @@ "dist", | ||
"ts-pattern": "^5.7.0", | ||
"@eslint-react/eff": "1.49.0-next.0" | ||
"@eslint-react/eff": "2.0.0-beta.13" | ||
}, | ||
@@ -53,3 +45,3 @@ "devDependencies": { | ||
"bun": ">=1.0.15", | ||
"node": ">=18.18.0" | ||
"node": ">=20.19.0" | ||
}, | ||
@@ -56,0 +48,0 @@ "scripts": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Yes
NaN43489
-49.87%4
-33.33%872
-41.91%1
Infinity%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed