py-ast - v1.16.0
    Preparing search index...

    Function dump

    • Dump an AST node to a formatted string for debugging, similar to Python's ast.dump.

      Parameters

      • node: ASTNodeUnion

        The AST node to dump

      • options: {
            annotateFields?: boolean;
            includeAttributes?: boolean;
            indent?: string | number | null;
            showEmpty?: boolean;
        } = {}

        Formatting options

        • OptionalannotateFields?: boolean

          Whether to prefix each value with its field name (default: true)

        • OptionalincludeAttributes?: boolean

          Whether to include location attributes (lineno, col_offset, etc.) in the output (default: false)

        • Optionalindent?: string | number | null

          Indentation to use for multi-line output; a number of spaces or a literal string, or null for single-line output (default: null)

        • OptionalshowEmpty?: boolean

          Whether to include empty/null/undefined fields in the output (default: false)

      Returns string

      The formatted string representation of node

      import { dump, parseModule } from "py-ast";

      const tree = parseModule("x = 1");
      console.log(dump(tree, { indent: 2 }));