# JavaScript/TypeScript AST Extractor

This is a **TypeScript project** that extracts AST information from JavaScript and TypeScript files using the TypeScript Compiler API.

## Architecture

```
src/                    # TypeScript source files
  ├── main.ts           # Entry point - orchestrates all extractors
  ├── schema.ts         # Zod schemas for validation
  └── extractors/       # Individual extraction modules
      ├── core_language.ts
      ├── data_flow.ts
      ├── module_framework.ts
      ├── security_extractors.ts
      ├── framework_extractors.ts
      ├── sequelize_extractors.ts
      ├── bullmq_extractors.ts
      ├── angular_extractors.ts
      └── cfg_extractor.ts

dist/                   # Compiled output (DO NOT EDIT)
  └── extractor.cjs     # Single bundled file (~10MB)
```

## Build Instructions

```bash
# Install dependencies
npm install

# Type check (no output, just validates)
npm run typecheck

# Build bundle
npm run build
```

## Important Notes

1. **DO NOT EDIT `dist/extractor.cjs` DIRECTLY**
   - This file is auto-generated by esbuild
   - All changes will be overwritten on next build

2. **After making changes to `src/`:**
   ```bash
   npm run build
   ```

3. **Python Integration:**
   - `js_helper_templates.py` reads `dist/extractor.cjs` directly
   - No runtime JavaScript concatenation
   - Bundle must exist before running `aud full`

## Development Workflow

1. Edit TypeScript files in `src/`
2. Run `npm run typecheck` to validate types
3. Run `npm run build` to produce bundle
4. Test with `aud full --index`

## Key Features

- **Semantic Extraction**: Uses TypeScript's TypeChecker API for accurate symbol resolution
- **Zod Validation**: All output validated against schemas before JSON serialization
- **Vue SFC Support**: Handles `.vue` single-file components with `@vue/compiler-sfc`
- **CFG Optimization**: Skips non-executable code, flattens JSX trees

## Troubleshooting

**Bundle not found error:**
```
FileNotFoundError: Extractor bundle not found at .../dist/extractor.cjs
```
Solution: Run `npm run build` in this directory.

**Type errors:**
```
npm run typecheck
```
Fix any errors before building.
