mcpField
A
ast-grep-typescript-react

ast-grep-typescript-react

github.com/pproencaDevelopment21863 installsUpdated 11w ago
Repository

About ast-grep-typescript-react

A skill for using ast-grep on TypeScript and React code, aimed at developers writing rules or codemods. It focuses on language selection, AST node details, JSX matching, and programmatic use with @ast-grep/napi.

Key features

  1. 01TSX language selection
  2. 02Fragment context and selectors
  3. 03JSX node and attribute matching
  4. 04TypeScript construct patterns
  5. 05JSX rewrite guidance
  6. 06@ast-grep/napi usage

Use cases

  1. 01Writing rules for TSX code
  2. 02Finding React components or hooks
  3. 03Building TypeScript codemods
  4. 04Diagnosing rules that match nothing

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/pproenca/dot-skills --skill ast-grep-typescript-react

After installing, type/ast-grep-typescript-reactin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

AGENTS.md
metadata.json
assets/templates/
_template.md
references/
_sections.md
ctx-fragment-context-selector.md
fix-jsx-rewrite-completeness.md
jsx-attribute-metavars.md
jsx-self-closing-vs-paired.md
lang-scan-ts-and-tsx.md
lang-tsx-for-jsx.md
napi-lang-tsx-findall.md
ts-as-expression-casts.md
ts-generic-react-fc.md
ts-type-only-imports.md

Details

From the project README

ast-grep for TypeScript & React

The wrong defaults a capable model hits when pointing ast-grep at .ts/.tsx code — mostly cases where a rule silently matches nothing because the language or a node kind was guessed wrong. This skill assumes you already know ast-grep's rule mechanics (patterns, meta-variables, all/any/has/inside, constraints); it corrects only what TypeScript and React add on top.

For general ast-grep rule-writing mechanics, use the companion ast-grep skill.

When to Apply

  • Writing an ast-grep pattern or YAML rule whose target is .ts or .tsx code
  • Searching for JSX elements, props, React hooks, imports, or TS type constructs
  • Building a codemod that rewrites JSX or TypeScript (rename a component, strip React.FC, migrate imports)
  • A rule "matches nothing" on TSX and you don't know why (usually the language or a node kind)
  • Driving ast-grep programmatically from a JS/TS script via @ast-grep/napi

First moves when a TS/React rule misbehaves

  1. Check the language. JSX-bearing files must run under tsx, never typescript. This is the single most common cause of silent no-match. See lang-tsx-for-jsx.
  2. Debug the pattern's AST. ast-grep run --pattern '<your pattern>' --lang tsx --debug-query=ast on a real snippet shows the node kinds and reveals ERROR nodes. Trust this over guessed kind names.
  3. Wrap fragments. If the pattern is an attribute, prop, or type annotation, it needs context + selector. See ctx-fragment-context-selector.

Rule Categories

#CategoryPrefixCovers
1Language Selectionlangtsx-vs-typescript split, scanning .ts + .tsx, languageGlobs
2Fragment Matchingctxcontext/selector for JSX attrs, props, type annotations
3JSX Node Kindsjsxself-closing vs paired elements, attribute-value metavariables
4TypeScript Constructststype-only imports, as casts, React.FC generics
5Rewrites & Codemodsfixre-emitting JSX metavars so children/props aren't dropped
6Programmatic Usenapi@ast-grep/napi Lang.Tsx, NapiConfig shape

Quick Reference

1. Language Selection (lang)
  • lang-tsx-for-jsx — Use tsx for any JSX; typescript parses JSX as ERROR and matches nothing
  • lang-scan-ts-and-tsx — Cover both .ts and .tsx; languageGlobs for reuse (+ the <T>-cast caveat)
2. Fragment Matching (ctx)
3. JSX Node Kinds (jsx)
4. TypeScript Constructs (ts)
5. Rewrites & Codemods (fix)
6. Programmatic Use (napi)

How to Use

Read the individual reference file for the decision you're making — each is self-contained with a canonical example. references/_sections.md defines the categories; AGENTS.md is the full compiled index.

Related Skills

  • ast-grep — general ast-grep rule-writing mechanics (patterns, composition, constraints, testing). This skill layers TS/React specifics on top of it.

Comments

Markdown supported