Skip to content

Types: Add discriminated union support across language bindings#1154

Merged
marcoroth merged 9 commits intomainfrom
union-node-types
Feb 13, 2026
Merged

Types: Add discriminated union support across language bindings#1154
marcoroth merged 9 commits intomainfrom
union-node-types

Conversation

@marcoroth
Copy link
Owner

@marcoroth marcoroth commented Feb 13, 2026

This pull request updates the type system to support discriminated unions for AST node fields instead of using the generic Node type as the common ancestor.

The config.yml schema definitions have been updated to specify exact union types for fields like:

  • HTMLElementNode.open_tag (now HTMLOpenTagNode | HTMLConditionalOpenTagNode) (see Parser: Introduce HTMLConditionalOpenTagNode #1153)
  • ERBIfNode.subsequent (now ERBIfNode | ERBElseNode)
  • HTMLAttributeValueNode.children (now LiteralNode | ERBContentNode)
  • HTMLCloseTagNode.children (now WhitespaceNode)

The code generation templates have been updated across all language bindings. TypeScript now generates proper union types and the is*Node type guard functions have been updated to accept null | undefined for easier chaining. Ruby generates union type signatures in RBS files. Rust adds a new union_types.rs file with enum types and conversion functions for each union.

With these type improvements the linter, formatter, and language server code has been simplified to use is*Node type guards instead of manual .type === "AST_*" string checks. This removes numerous as any and as *Node casts that were previously needed, making the code more type-safe and readable.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 13, 2026

npx https://pkg.pr.new/@herb-tools/formatter@1154
npx https://pkg.pr.new/@herb-tools/language-server@1154
npx https://pkg.pr.new/@herb-tools/linter@1154

commit: c635318

@github-actions
Copy link

github-actions bot commented Feb 13, 2026

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit c635318


✅ Preview deployment has been cleaned up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant