sicua
Version:
A tool for analyzing project structure and dependencies
98 lines (97 loc) • 3.7 kB
TypeScript
/**
* AST traversal utilities for security vulnerability detection
*/
import ts from "typescript";
import { ASTPattern, PatternMatch } from "../types/pattern.types";
export declare class ASTTraverser {
/**
* Find all nodes of a specific kind in a source file
*/
static findNodesByKind<T extends ts.Node>(sourceFile: ts.SourceFile, kind: ts.SyntaxKind, predicate?: (node: T) => boolean): T[];
static findNodesByKindInNode<T extends ts.Node>(node: ts.Node, kind: ts.SyntaxKind, predicate?: (node: T) => boolean): T[];
/**
* Find the nearest parent node that matches a given predicate
*/
static findNearestParent<T extends ts.Node>(node: ts.Node, predicate: (node: ts.Node) => node is T): T | undefined;
/**
* Find nodes matching AST pattern conditions
*/
static findNodesMatchingPattern(sourceFile: ts.SourceFile, pattern: ASTPattern): PatternMatch[];
/**
* Check if a node matches the specified conditions
*/
private static matchesConditions;
/**
* Get TypeScript SyntaxKind from string type
*/
private static getNodeKindFromType;
/**
* Get the line and column position of a node
*/
static getNodeLocation(node: ts.Node, sourceFile: ts.SourceFile): {
line: number;
column: number;
};
/**
* Get the text content of a node
*/
static getNodeText(node: ts.Node, sourceFile: ts.SourceFile): string;
/**
* Get surrounding context for a node
*/
static getNodeContext(node: ts.Node, sourceFile: ts.SourceFile, contextLines?: number): string;
/**
* Find all call expressions with a specific function name
*/
static findCallExpressions(sourceFile: ts.SourceFile, functionName: string): ts.CallExpression[];
/**
* Find all string literals containing a specific pattern
*/
static findStringLiteralsWithPattern(sourceFile: ts.SourceFile, pattern: RegExp): ts.StringLiteral[];
/**
* Find all property access expressions (e.g., obj.prop)
*/
static findPropertyAccess(sourceFile: ts.SourceFile, objectName?: string, propertyName?: string): ts.PropertyAccessExpression[];
/**
* Find all JSX elements with specific tag names
*/
static findJSXElements(sourceFile: ts.SourceFile, tagName?: string): (ts.JsxElement | ts.JsxSelfClosingElement)[];
/**
* Check if a node is inside a specific function
*/
static isNodeInFunction(node: ts.Node, functionName: string): boolean;
/**
* Extract string value from various node types
*/
static extractStringValue(node: ts.Node): string | null;
/**
* Check if a node is within a specific type of function context
*/
static isInFunctionWithPattern(node: ts.Node, patterns: RegExp[]): boolean;
/**
* Get variable assignment context for better analysis
*/
static getVariableAssignmentContext(node: ts.Node): {
variableName?: string;
isInFunction?: string;
assignmentType: "declaration" | "assignment" | "property" | "parameter" | "none";
};
/**
* Find the nearest function name for context
*/
private static findNearestFunctionName;
/**
* Check if a node is in a test or development context
*/
static isInTestOrDevContext(node: ts.Node, sourceFile: ts.SourceFile): boolean;
/**
* Enhanced context extraction with better semantic understanding
*/
static getSemanticContext(node: ts.Node, sourceFile: ts.SourceFile): {
isUIContext: boolean;
isSecurityContext: boolean;
isTestContext: boolean;
functionContext?: string;
variableContext?: string;
};
}