Skip to content
Skills Library
Programming · Analysis

swc-parser

/swc-parser

Parse JavaScript/TypeScript code into AST using SWC (Speedy Web Compiler). Use this for code analysis, transformation, or understanding JavaScript/TypeScript structure.

Repository
satibot ↗
Licence
MIT
Last repository change
02.05.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 02.05.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Parse JavaScript/TypeScript code into AST using SWC (Speedy Web Compiler). Use this for code analysis, transformation, or understanding JavaScript/TypeScript structure.

Original author description

Parse JavaScript/TypeScript code into AST using SWC (Speedy Web Compiler). Use this for code analysis, transformation, or understanding JavaScript/TypeScript structure.

How it works

  1. Architecture
  2. SWC Tool Flow
  3. AST Structure
  4. Example Usage
  5. AST Node Types
  6. Use Cases
  7. Files
  8. Integration
  9. Benefits
  10. Testing
Original SKILL.md headings · 172 lines, 470 words
SKILL.md preview
---
name: swc-parser
description: Parse JavaScript/TypeScript code into AST using SWC (Speedy Web Compiler). Use this for code analysis, transformation, or understanding JavaScript/TypeScript structure.
---

# SWC Parser Tool

SWC (Speedy Web Compiler) is a super-fast TypeScript/JavaScript compiler written in Rust. It can be used to parse JS/TS code into an Abstract Syntax Tree (AST).

## Architecture

```mermaid
graph TB
    subgraph Input["Input"]
        Code[TypeScript/JavaScript Code]
        Args[JSON Arguments]
    end

    subgraph Process["SWC Pipeline"]
        Write[Write to temp file]
        Parse[SWC Parser]
        Output[JSON AST Output]
    end

    Code --> Write
    Args --> Parse
    Write --> Parse
    Parse --> Output
```

## SWC Tool Flow

```mermaid
sequenceDiagram
    participant Agent
    participant SwcTool
    participant FileSystem
    participant SWC
    participant Node

    Agent->>SwcTool: execute(code, type)
    SwcTool->>FileSystem: Write temp file
    SwcTool->>Node: npx swc
    Node->>SWC: Parse with SWC
    SWC-->>Node: AST JSON
    Node-->>SwcTool: AST JSON
    SwcTool-->>Agent: Return AST
```

## AST Structure

```mermaid
graph TB
    Root["File (root)"]
    Prog["Program"]
    Body["Body[]"]
    Decl["VariableDeclaration"]
    Declr["VariableDeclarator"]
    Id["Identifier"]
    Init["NumericLiteral"]

    Root --> Prog
    Prog --> Body
    Body --> Decl
    Decl --> Declr
    Declr --> Id
    Declr --> Init

    style Root fill:#f9f,stroke:#333
    style Prog fill:#bbf,stroke:#333
    style Body fill:#bbf,stroke:#333
    style Decl fill:#dfd,stroke:#333
```

## Example Usage

### TypeScript

```
Thought: I need to analyze the TypeScript code structure.
Action: parse_typescript
Action Input: {"code": "function add(a: number, b: number): number { return a + b; }", "type": "ts"}
Observation: {"type":"File","span":{"start":0,"end":51,"ctxt":0},"body":[{"type":"FunctionDeclaration"...}
```

### JavaScript

```
Thought: I need to analyze the JavaScript code structure.
Action: parse_typescript
Action Input: {"code": "const x = (a, b) => a + b;", "type": "js"}
Observation: {"type":"File","span":{"start":0,"end":26,"ctxt":0},"body":[{"type":"VariableDeclaration"...}
```

## AST Node Types

```mermaid
graph LR
    Declaration[Declaration] --> FunctionDecl[FunctionDeclaration]
    Declaration --> VarDecl[VariableDeclaration]
    Declaration --> ClassDecl[ClassDeclaration]
    
    Expression[Expression] --> Identifier[Identifier]
    Expression --> Literal[Literal]
    Expression --> BinaryOp[BinaryExpression]
    Expression --> ArrowFn[ArrowFunctionExpression]
    
    Statement[Statement] --> IfStmt[IfStatement]
    Statement --> ForStmt[ForStatement]
    Statement --> ReturnStmt[ReturnStatement]
```

## Use Cases

```mermaid
graph LR
    Analysis[Code Analysis] --> FindFuncs[Find Functions]
    Analysis --> FindVars[Find Variables]
    Analysis --> FindImports[Find Imports]
    
    Transform[Code Transform] --> Rename[Rename Refactoring]
    Transform --> Extract[Extract Method]
    Transform --> Inline[Inline Variable]
    
    Generate[Code Generation] --> Minify[Minify]
    Generate --> Transpile[Transpile to ES5]
    Generate --> Bundle[Bundle]
```

- **Code Analysis**: Understand code structure
- **Refactoring**: Find all function calls, variables
- **Linting**: Analyze code patterns
- **Code Generation**: Transform AST to modify code
- **Documentation**: Extract function signatures

## Files

| File | Description |
|------|-------------|
| `libs/agent/src/agent/swc.zig` | SWC tool implementation |
| `.agents/skills/swc-parser/SKILL.md` | This documentation |

## Integration

The SWC tool is available in the agent's tool registry:

```zig
const swc = @import("swc.zig");
const tool = swc.SwcTool{};
try registry.register(.{
    .name = tool.name,
    .description = tool.description,
    .parameters = tool.parameters,
    .execute = tool.execute,
});
```

## Benefits

- **Fast**: Written in Rust, 20-70x faster than Babel
- **Accurate**: Produces correct ESTree-compatible AST
- **TypeScript**: Native TypeScript support
- **Transforms**: Can also minify, transpile, and transform code

## Testing

```bash
zig test libs/agent/src/agent/swc.zig
```

Tests:
- `SwcTool: tool metadata` - Verify tool name, description
- `SwcTool: parseAstNode with valid JSON` - Parse valid AST
- `SwcTool: parseAstNode with invalid JSON` - Handle errors
- `SwcTool: parseAstNode with missing type` - Handle missing fields

Versions

The database has no other skills named swc-parser.

Database snapshot: 13.11.2026 · package version e846e681b748 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100swc
    SWC (Speedy Web Compiler) is a Rust-based compiler and minifier for JavaScript and TypeScript, used as a faster replacement for Babel and Terser. Use when a user asks to compile TypeScript or JSX with swc, configure .swcrc, replace babel-jest with @swc/jest, minify code, use the…
  • 98swc
    Expert SWC assistance covering high-performance Rust-based JavaScript/TypeScript compilation, .swcrc configuration, Jest testing via @swc/jest, and minification. Use when replacing Babel with SWC for faster builds, accelerating test execution, or compiling modern ECMAScript features.
  • 100swc-plugin-compatibility
    Diagnose and fix Lingui SWC plugin compatibility errors with Next.js, Rspack, or other SWC runtimes. Use when seeing errors like "failed to invoke plugin", "failed to run Wasm plugin transform", "out of bounds memory access", or "LayoutError" during builds with @lingui/swc-plugin.
  • 95migrate-swc-gen1-to-gen2
    Upgrade Spectrum 1 (sp-* elements, @spectrum-web-components/*) to Spectrum 2 (swc-* elements, @adobe/spectrum-wc). Use when developers need to migrate from Spectrum 1 to Spectrum 2 web components, or when they mention @spectrum-web-components, sp-* elements, or Spectrum 1.
  • 100swc-plugin-compatibility
    Diagnose and fix Lingui SWC plugin compatibility errors with Next.js, Vite, Rspack, or other SWC runtimes. Use when seeing errors like "failed to invoke plugin", "failed to run Wasm plugin transform", "Failed to deserialize program received from host", "Failed to execute SWC…
  • 100ast-grep
    Code search, analysis, and refactoring using ast-grep (sg). Use for AST-based code modifications, structural search, and linting.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.