🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@eslint-react/ast

Package Overview
Dependencies
Maintainers
1
Versions
2646
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
5.17.2
to
5.17.3
+11
-4
dist/index.d.ts

@@ -15,3 +15,3 @@ import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";

declare namespace check_d_exports {
export { is, isClass, isDirective, isExpression, isFunction, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXFragment, isJSXTagNameExpression, isOneOf, isProperty, isPropertyOrMethod, isTypeAssertionExpression, isTypeExpression };
export { is, isClass, isConditional, isDirective, isExpression, isFunction, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXFragment, isJSXTagNameExpression, isOneOf, isProperty, isPropertyOrMethod, isTypeAssertionExpression, isTypeExpression };
}

@@ -38,2 +38,8 @@ declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {

declare const isExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression;
/**
* Check if a node is a conditional expression or control flow statement
* @param node The node to check
* @returns True if the node is conditional
*/
declare const isConditional: (node: TSESTree.Node | null | undefined) => node is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
declare namespace compare_d_exports {

@@ -54,9 +60,10 @@ export { isEqual };

declare namespace extract_d_exports {
export { getCalleeName, getFullyQualifiedName, getRootIdentifier, getStaticPropertyName, unwrap };
export { findProperty, getCalleeName, getFullyQualifiedName, getIdentifierAt, getPropertyName, unwrap };
}
declare function unwrap(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
declare function getRootIdentifier(node: TSESTree.Expression | TSESTree.PrivateIdentifier): TSESTree.Identifier | null;
declare function findProperty(properties: TSESTree.ObjectLiteralElement[], name: string): TSESTree.Property | null;
declare function getCalleeName(node: TSESTree.CallExpression): string | null;
declare function getStaticPropertyName(prop: TSESTree.Property): string | null;
declare function getPropertyName(property: TSESTree.Property, effort?: "min" | "max"): string | null;
declare function getFullyQualifiedName(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
declare function getIdentifierAt(node: TSESTree.Expression | TSESTree.PrivateIdentifier, position: number): TSESTree.Identifier | null;
declare namespace traverse_d_exports {

@@ -63,0 +70,0 @@ export { findParent };

@@ -9,2 +9,3 @@ import { t as __exportAll } from "./rolldown-runtime-w6R9maHv.js";

isClass: () => isClass,
isConditional: () => isConditional,
isDirective: () => isDirective,

@@ -121,2 +122,18 @@ isExpression: () => isExpression,

]);
/**
* Check if a node is a conditional expression or control flow statement
* @param node The node to check
* @returns True if the node is conditional
*/
const isConditional = isOneOf([
AST_NODE_TYPES.DoWhileStatement,
AST_NODE_TYPES.ForInStatement,
AST_NODE_TYPES.ForOfStatement,
AST_NODE_TYPES.ForStatement,
AST_NODE_TYPES.WhileStatement,
AST_NODE_TYPES.IfStatement,
AST_NODE_TYPES.SwitchStatement,
AST_NODE_TYPES.LogicalExpression,
AST_NODE_TYPES.ConditionalExpression
]);

@@ -600,6 +617,7 @@ //#endregion

var extract_exports = /* @__PURE__ */ __exportAll({
findProperty: () => findProperty,
getCalleeName: () => getCalleeName,
getFullyQualifiedName: () => getFullyQualifiedName,
getRootIdentifier: () => getRootIdentifier,
getStaticPropertyName: () => getStaticPropertyName,
getIdentifierAt: () => getIdentifierAt,
getPropertyName: () => getPropertyName,
unwrap: () => unwrap

@@ -611,6 +629,10 @@ });

}
function getRootIdentifier(node) {
const expr = unwrap(node);
if (expr.type === AST_NODE_TYPES.Identifier) return expr;
if (expr.type === AST_NODE_TYPES.MemberExpression) return getRootIdentifier(expr.object);
function findProperty(properties, name) {
for (const property of properties) {
if (property.type === AST_NODE_TYPES.Property && getPropertyName(property) === name) return property;
if (property.type === AST_NODE_TYPES.SpreadElement && property.argument.type === AST_NODE_TYPES.ObjectExpression) {
const found = findProperty(property.argument.properties, name);
if (found != null) return found;
}
}
return null;

@@ -624,5 +646,6 @@ }

}
function getStaticPropertyName(prop) {
const key = unwrap(prop.key);
if (key.type === AST_NODE_TYPES.Identifier && !prop.computed) return key.name;
function getPropertyName(property, effort = "min") {
const key = unwrap(property.key);
if (key.type === AST_NODE_TYPES.Identifier && !property.computed) return key.name;
if (effort === "min") return null;
if (key.type === AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;

@@ -648,2 +671,13 @@ if (key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0) return key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null;

}
function getIdentifierAt(node, position) {
const identifiers = [];
let current = unwrap(node);
while (current.type === AST_NODE_TYPES.MemberExpression) {
const property = unwrap(current.property);
identifiers.unshift(property.type === AST_NODE_TYPES.Identifier ? property : null);
current = unwrap(current.object);
}
identifiers.unshift(current.type === AST_NODE_TYPES.Identifier ? current : null);
return identifiers.at(position) ?? null;
}

@@ -650,0 +684,0 @@ //#endregion

{
"name": "@eslint-react/ast",
"version": "5.17.2",
"version": "5.17.3",
"description": "ESLint React's TSESTree AST utility module.",

@@ -44,4 +44,4 @@ "homepage": "https://github.com/Rel1cx/eslint-react",

"@local/configs": "0.0.0",
"@local/testkit": "0.0.0",
"@local/eff": "0.0.0"
"@local/eff": "0.0.0",
"@local/testkit": "0.0.0"
},

@@ -48,0 +48,0 @@ "peerDependencies": {