
Ast Visitor Pattern
- 2 installs
- 418 repo stars
- Updated August 3, 2026
- prisma/prisma-next
ast-visitor-pattern skill documents >-.
About
ast-visitor-pattern skill documents >-. name: ast-visitor-pattern description: >- Covers installation, configuration, and when-to-use guidance from the upstream SKILL.md workflow.
- >-.
- Platform-specific setup patterns for ast-visitor-pattern.
- Evidence-backed steps from upstream SKILL.md.
- When-to-use criteria for ast-visitor-pattern versus alternatives.
Ast Visitor Pattern by the numbers
- 2 all-time installs (skills.sh)
- Ranked #1,839 of 2,715 Automation & Workflows skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
ast-visitor-pattern capabilities & compatibility
- Capabilities
- ast visitor pattern quick start · ast visitor pattern when to use guidance · ast visitor pattern integration patterns
What ast-visitor-pattern says it does
Use the frozen-class/visitor pattern for discriminated unions that have
multiple dispatch sites. Use when creating a new set of variants
npx skills add https://github.com/prisma/prisma-next --skill ast-visitor-patternAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 2 |
|---|---|
| repo stars | ★ 418 |
| Last updated | August 3, 2026 |
| Repository | prisma/prisma-next ↗ |
How do I use ast-visitor-pattern correctly?
>-
Who is it for?
Teams implementing ast-visitor-pattern workflows from the catalog.
Skip if: Skip when requirements clearly match a different specialized stack.
When should I use this skill?
User asks about ast-visitor-pattern, >-.
What you get
Working ast-visitor-pattern setup with validated configuration and next steps.
Files
AST Class/Visitor Pattern
When a discriminated union has 3+ variants and 2+ dispatch sites (renderers, serializers, classifiers, etc.), replace plain union + switch with frozen subclasses and a visitor interface. This makes adding a new variant a compiler error at every consumer, instead of a silent omission.
Structure
Four pieces, always in the same file:
// 1. Abstract base (not exported — consumers use the union type)
abstract class FooNode {
abstract readonly kind: string;
abstract accept<R>(visitor: FooVisitor<R>): R;
protected freeze(): void { Object.freeze(this); }
}
// 2. Visitor interface
export interface FooVisitor<R> {
bar(node: BarNode): R;
baz(node: BazNode): R;
}
// 3. Concrete subclasses — readonly fields, freeze() in constructor
export class BarNode extends FooNode {
readonly kind = 'bar' as const;
readonly value: string;
constructor(value: string) {
super();
this.value = value;
this.freeze();
}
accept<R>(visitor: FooVisitor<R>): R { return visitor.bar(this); }
}
export class BazNode extends FooNode {
readonly kind = 'baz' as const;
readonly count: number;
constructor(count: number) {
super();
this.count = count;
this.freeze();
}
accept<R>(visitor: FooVisitor<R>): R { return visitor.baz(this); }
}
// 4. Union type
export type Foo = BarNode | BazNode;Consuming
Define a visitor object (or class) per concern:
const renderVisitor: FooVisitor<string> = {
bar(node) { return node.value; },
baz(node) { return String(node.count); },
};
function render(node: Foo): string {
return node.accept(renderVisitor);
}In tests
Always construct subclass instances, never plain objects:
// ✅
const call = new BarNode('x');
// ❌
const call: Foo = { kind: 'bar', value: 'x' };When NOT to use
- Single dispatch site → plain union + switch is simpler
- Fewer than 3 variants with no expected growth → not worth the boilerplate
Codebase examples
MongoAstNode/MongoDdlCommandVisitor—packages/2-mongo-family/4-query/query-ast/src/ddl-commands.tsOpFactoryCall/OpFactoryCallVisitor—packages/3-mongo-target/1-mongo-target/src/core/op-factory-call.ts
Related skills
FAQ
What does ast-visitor-pattern do?
ast-visitor-pattern skill documents >-.
When should I use ast-visitor-pattern?
User asks about ast-visitor-pattern, >-.
Is this skill safe to install?
Review the Security Audits panel on this page before installing in production.