Tree Hugger JS

Tree Hugger JS

qckfx

Provides JavaScript and TypeScript code analysis through AST parsing. Enables automated code transformations, refactoring, and dependency management with safety previews.

2459 views1Local (stdio)

What it does

  • Parse JavaScript/TypeScript/JSX/TSX code into AST
  • Find code patterns using CSS-like selectors
  • Extract functions, classes, and imports with metadata
  • Rename identifiers throughout codebase
  • Remove unused import statements
  • Transform code with preview capabilities

Best for

JavaScript/TypeScript developers doing refactoringCode review and architecture analysisAutomated dependency cleanupLarge-scale codebase transformations
No setup with npxCSS-like pattern matching syntaxSafe transformations with previews

Tools (12)

parse_code

Parse JavaScript/TypeScript code from file or string and load it into the AST state. Must be called before using other analysis tools. Examples: • Parse a React component: parse_code('./src/UserProfile.jsx') • Parse code string: parse_code('function hello() { return "world"; }') • Parse with explicit language: parse_code('./config.js', language='javascript') • Analyze legacy code: parse_code('./old-script.js') then use other tools to understand structure • Code review prep: parse_code('./feature.ts') then get_functions() to review all functions

find_pattern

Find first node matching the specified pattern using tree-hugger-js intuitive syntax. Use for targeted searches when you need one specific match. Examples: • Find main function: find_pattern('function[name="main"]') • Find React component: find_pattern('function[name="UserProfile"]') • Find async functions: find_pattern('function[async]') • Find specific class: find_pattern('class[name="UserManager"]') • Find error handling: find_pattern('call[text*="catch"]') • Find JSX with props: find_pattern('jsx:has(jsx-attribute[name="className"])') • Debug specific calls: find_pattern('call[text*="console.log"]')

find_all_pattern

Find all nodes matching the specified pattern. Use for comprehensive analysis when you need all matches. Examples: • Audit all functions: find_all_pattern('function') • Find all TODO comments: find_all_pattern('comment[text*="TODO"]') • Security audit: find_all_pattern('call[text*="eval"]') • Performance review: find_all_pattern('call[text*="console.log"]') to find debug logs • API usage: find_all_pattern('call[text*="fetch"]') to find all API calls • React hooks: find_all_pattern('call[text*="use"]') for hooks usage • Error patterns: find_all_pattern('string[text*="error"]') for error messages • Database queries: find_all_pattern('string[text*="SELECT"]') for SQL • Event handlers: find_all_pattern('function[text*="onClick"]')

get_functions

Get all functions with metadata including name, type, location, and async status. Includes class methods, arrow functions, and declarations. Examples: • Code review: get_functions() to see all functions in a file • Find async operations: get_functions({asyncOnly: true}) • API analysis: get_functions() then look for functions with 'fetch' or 'api' in names • Test coverage: get_functions() to identify functions needing tests • Refactoring prep: get_functions({includeAnonymous: false}) to focus on named functions • Performance audit: get_functions() to find large/complex functions by line count

get_classes

Get all classes with comprehensive method and property analysis. Perfect for OOP code review. Examples: • Architecture review: get_classes() to understand class structure • API design: get_classes() to see public method interfaces • Inheritance analysis: get_classes() to identify class hierarchies • Method-only view: get_classes({includeProperties: false}) to focus on behavior • Property audit: get_classes({includeMethods: false}) to review state management • Testing prep: get_classes() to identify methods needing unit tests

Alternatives