@amplication/ast-types

中文文档
0.0.2发布于 2025/03/20TypeScriptCommonJS零依赖近 30 天下载 80.9万

This package provides common interfaces for AST (Abstract Syntax Tree) nodes and code generation writers used across different language-specific AST packages in Amplication.

原始使用文档
文档目录8 节
  1. Interfaces
  2. IAstNode
  3. IWriter
  4. Usage
  5. Development
  6. Building
  7. Testing
  8. Linting

@amplication/ast-types

This package provides common interfaces for AST (Abstract Syntax Tree) nodes and code generation writers used across different language-specific AST packages in Amplication.

Interfaces

IAstNode

The base interface for all AST nodes in the Amplication AST system.

interface IAstNode {
  /**
   * Writes the AST node to the given writer.
   * @param writer The writer to write to
   */
  write(writer: IWriter): void;
}

IWriter

The interface for code generation writers that handle proper indentation and formatting.

interface IWriter {
  /**
   * Writes text to the output buffer with proper indentation
   * @param text The text to write
   */
  write(text: string): void;

  /**
   * Writes an AST node to the output buffer
   * @param node The AST node to write
   */
  writeNode(node: IAstNode): void;

  /**
   * Writes text followed by a newline if the last line wasn't a newline
   * @param text Optional text to write before the newline
   */
  writeLine(text?: string): void;

  /**
   * Writes a newline to the output buffer
   */
  newLine(): void;

  /**
   * Writes a newline if the last line wasn't a newline
   */
  writeNewLineIfLastLineNot(): void;

  /**
   * Increases the indentation level
   */
  indent(): void;

  /**
   * Decreases the indentation level
   */
  dedent(): void;

  /**
   * Returns the current contents of the output buffer
   */
  toString(): string;
}

Usage

This package is used by language-specific AST packages like @amplication/csharp-ast and @amplication/java-ast to ensure consistent AST node and writer implementations across different languages.

Example usage in a language-specific package:

import { IAstNode, IWriter } from '@amplication/ast-types';

export class MyAstNode implements IAstNode {
  write(writer: IWriter): void {
    writer.write('// My AST node implementation');
  }
}

Development

Building

nx build ast-types

Testing

nx test ast-types

Linting

nx lint ast-types

版本与发布记录

@amplication/ast-types 共发布 2 个版本,首次发布于 2025/03/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.2latest2025/03/201.6 年前
0.0.12025/03/201.6 年前

关于 @amplication/ast-types 的常见问题

@amplication/ast-types 是什么?

This package provides common interfaces for AST (Abstract Syntax Tree) nodes and code generation writers used across different language-specific AST packages in Amplication.

如何安装 @amplication/ast-types?

在项目目录运行 npm install @amplication/ast-types,或使用 pnpm add / yarn add / bun add。

@amplication/ast-types 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@amplication/ast-types 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@amplication/ast-types 可以商用吗?

@amplication/ast-types 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@amplication/ast-types 的下载量有多少?

根据 npm 官方下载统计,@amplication/ast-types 在 2026/10/06 – 2026/11/04 这 30 天内被下载 809,129 次,日均约 26,971 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amplication/ast-types 还在维护吗?

最新版本 0.0.2 发布于 2025/03/20(1.6 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/03/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。