swc-parser
/swc-parser
Parsuje kod JavaScript i TypeScript do drzewa AST przy pomocy SWC, by analizować i przekształcać strukturę kodu.
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 02.05.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Parsuje kod JavaScript i TypeScript do drzewa AST przy pomocy SWC, by analizować i przekształcać strukturę kodu.
Oryginalny opis (EN)
Parse JavaScript/TypeScript code into AST using SWC (Speedy Web Compiler). Use this for code analysis, transformation, or understanding JavaScript/TypeScript structure.
Jak działa
- Architecture
- SWC Tool Flow
- AST Structure
- Example Usage
- AST Node Types
- Use Cases
- Files
- Integration
- Benefits
- Testing
Podgląd SKILL.md
---
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
Wersje
W bazie nie ma innych skilli o nazwie swc-parser.
Migawka bazy z 28.10.2026 · wersja paczki e846e681b748 (skrót SHA-256 całej paczki)
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100swc
Obsługuje SWC, kompilator i minifikator JavaScript i TypeScript w Rust, jako szybszy zamiennik Babel i Terser: konfiguracja .swcrc, @swc/jest i API @swc/core. - 98swc
Pomaga używać SWC, kompilatora JavaScript i TypeScript w Rust: konfiguracja .swcrc, testy Jest przez @swc/jest, minifikacja oraz zastąpienie Babela dla szybszych buildów. - 100swc-plugin-compatibility
Diagnozuje i naprawia błędy wtyczki Lingui SWC w Next.js i Rspack, np. nieudane wywołanie wtyczki lub błędy pamięci Wasm. - 95migrate-swc-gen1-to-gen2
Migruje komponenty Spectrum 1, czyli elementy sp-* i pakiety @spectrum-web-components, na Spectrum 2. - 100swc-plugin-compatibility
Diagnozuje i naprawia błędy zgodności wtyczki Lingui SWC z Next.js, Vite, Rspack i innymi środowiskami SWC, w tym przypadki cichego braku transformacji makr. - 100ast-grep
Wyszukuje, analizuje i refaktoryzuje kod za pomocą ast-grep (sg): modyfikacje oparte na AST, wyszukiwanie strukturalne i linting.