@eslint-react/var
Advanced tools
+1
-10
@@ -20,11 +20,2 @@ import { unit } from "@eslint-react/eff"; | ||
| //#endregion | ||
| //#region src/find-import-source.d.ts | ||
| /** | ||
| * Find the import source of a variable | ||
| * @param name The variable name | ||
| * @param initialScope The initial scope to search | ||
| * @returns The import source or undefined if not found | ||
| */ | ||
| declare function findImportSource(name: string, initialScope: Scope): string | undefined; | ||
| //#endregion | ||
| //#region src/find-variable.d.ts | ||
@@ -121,2 +112,2 @@ /** | ||
| //#endregion | ||
| export { AssignmentTarget, ObjectType, findEnclosingAssignmentTarget, findImportSource, findVariable, getObjectType, getVariableInitializer, getVariableInitializerLoose, isAssignmentTargetEqual, isValueEqual }; | ||
| export { AssignmentTarget, ObjectType, findEnclosingAssignmentTarget, findVariable, getObjectType, getVariableInitializer, getVariableInitializerLoose, isAssignmentTargetEqual, isValueEqual }; |
+3
-46
@@ -1,7 +0,6 @@ | ||
| import { dual, identity, unit } from "@eslint-react/eff"; | ||
| import { dual, unit } from "@eslint-react/eff"; | ||
| import { AST_NODE_TYPES } from "@typescript-eslint/types"; | ||
| import * as ast from "@eslint-react/ast"; | ||
| import { P, match } from "ts-pattern"; | ||
| import * as astUtils from "@typescript-eslint/utils/ast-utils"; | ||
| import { getStaticValue } from "@typescript-eslint/utils/ast-utils"; | ||
| import * as ast from "@eslint-react/ast"; | ||
| import { DefinitionType } from "@typescript-eslint/scope-manager"; | ||
@@ -44,44 +43,2 @@ | ||
| //#endregion | ||
| //#region src/find-import-source.ts | ||
| /** | ||
| * Get the arguments of a require expression | ||
| * @param node The node to match | ||
| * @returns The require expression arguments or undefined if the node is not a require expression | ||
| */ | ||
| function getRequireExpressionArguments(node) { | ||
| return match(node).with({ | ||
| type: AST_NODE_TYPES.CallExpression, | ||
| arguments: P.select(), | ||
| callee: { | ||
| type: AST_NODE_TYPES.Identifier, | ||
| name: "require" | ||
| } | ||
| }, identity).with({ | ||
| type: AST_NODE_TYPES.MemberExpression, | ||
| object: P.select() | ||
| }, getRequireExpressionArguments).otherwise(() => null); | ||
| } | ||
| /** | ||
| * Find the import source of a variable | ||
| * @param name The variable name | ||
| * @param initialScope The initial scope to search | ||
| * @returns The import source or undefined if not found | ||
| */ | ||
| function findImportSource(name, initialScope) { | ||
| const latestDef = findVariable(name, initialScope)?.defs.at(-1); | ||
| if (latestDef == null) return unit; | ||
| const { node, parent } = latestDef; | ||
| if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) { | ||
| const { init } = node; | ||
| if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) return findImportSource(init.object.name, initialScope); | ||
| if (init.type === AST_NODE_TYPES.Identifier) return findImportSource(init.name, initialScope); | ||
| const arg0 = getRequireExpressionArguments(init)?.[0]; | ||
| if (arg0 == null || !ast.isLiteral(arg0, "string")) return unit; | ||
| return arg0.value; | ||
| } | ||
| if (parent?.type === AST_NODE_TYPES.ImportDeclaration) return parent.source.value; | ||
| return unit; | ||
| } | ||
| //#endregion | ||
| //#region src/get-variable-initializer.ts | ||
@@ -273,2 +230,2 @@ /** | ||
| //#endregion | ||
| export { findEnclosingAssignmentTarget, findImportSource, findVariable, getObjectType, getVariableInitializer, getVariableInitializerLoose, isAssignmentTargetEqual, isValueEqual }; | ||
| export { findEnclosingAssignmentTarget, findVariable, getObjectType, getVariableInitializer, getVariableInitializerLoose, isAssignmentTargetEqual, isValueEqual }; |
+4
-4
| { | ||
| "name": "@eslint-react/var", | ||
| "version": "3.0.0-beta.59", | ||
| "version": "3.0.0-beta.60", | ||
| "description": "ESLint React's TSESTree AST utility module for static analysis of variables.", | ||
@@ -37,5 +37,5 @@ "homepage": "https://github.com/Rel1cx/eslint-react", | ||
| "ts-pattern": "^5.9.0", | ||
| "@eslint-react/eff": "3.0.0-beta.59", | ||
| "@eslint-react/ast": "3.0.0-beta.59", | ||
| "@eslint-react/shared": "3.0.0-beta.59" | ||
| "@eslint-react/ast": "3.0.0-beta.60", | ||
| "@eslint-react/shared": "3.0.0-beta.60", | ||
| "@eslint-react/eff": "3.0.0-beta.60" | ||
| }, | ||
@@ -42,0 +42,0 @@ "devDependencies": { |
18406
-9.69%335
-13.21%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed