Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
prisma avatar

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)
At a glance

ast-visitor-pattern capabilities & compatibility

Capabilities
ast visitor pattern quick start · ast visitor pattern when to use guidance · ast visitor pattern integration patterns
From the docs

What ast-visitor-pattern says it does

Use the frozen-class/visitor pattern for discriminated unions that have
SKILL.md
multiple dispatch sites. Use when creating a new set of variants
SKILL.md
npx skills add https://github.com/prisma/prisma-next --skill ast-visitor-pattern

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs2
repo stars418
Last updatedAugust 3, 2026
Repositoryprisma/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

SKILL.mdMarkdownGitHub ↗

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 / MongoDdlCommandVisitorpackages/2-mongo-family/4-query/query-ast/src/ddl-commands.ts
  • OpFactoryCall / OpFactoryCallVisitorpackages/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.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.