AST Types Library
The AST Types library is used by Blueprint and .NET engine plugins. Node.js plugins use different methods for code generation as detailed in the Node.js Plugin Events documentation.
Key Features
- Base interfaces for AST nodes
- Common type definitions
- Shared utilities and helpers
- Type system abstractions
Scope and Purpose
The AST Types library is not intended to cover all language functionality. It provides the core interfaces and types needed to create foundation and boilerplate code with Amplication plugins. The library focuses on essential abstractions that can be implemented by language-specific AST libraries. TheIAstNode
interface is a fundamental part of this design, allowing code to be represented as structured objects while also supporting generic code blocks when needed for more specialized implementations.
Installation
Usage
AST Types is typically used as a dependency by language-specific AST libraries. However, you can also use it directly in your projects if you need to access common AST interfaces and types.The IAstNode Interface
TheIAstNode
interface is a cornerstone of Amplication’s code generation system. It defines the common contract that all AST nodes must implement, regardless of the target language.
Key Aspects of IAstNode
- Acts as the base interface for all language-specific AST nodes
- Enables language-agnostic code transformations
- Facilitates integration between different AST implementations
- Allows plugins to use a common type when manipulating code
Using IAstNode in Plugins
In Amplication plugins, you’ll work extensively with theIAstNode
interface:
- Import
IAstNode
from “@amplication/ast-types” - Create language-specific AST nodes using a library like @amplication/java-ast or @amplication/csharp-ast
- Create an
IFile<IAstNode>
that references your AST node - Add the file to the generation context using
context.files.set()
Documentation
AST Types API Documentation
Complete reference for the AST Types library. Learn about the IAstNode interface, common types, and core abstractions that form the foundation of Amplication’s code generation system.