Interface NodeFormatter<T>

Represents an object that allows to format certain parts of a specific node, like its keywords or properties.

interface NodeFormatter<T> {
    cst(nodes: CstNode[]): FormattingRegion;
    interior(start: FormattingRegion, end: FormattingRegion): FormattingRegion;
    keyword(keyword: string, index?: number): FormattingRegion;
    keywords(...keywords: string[]): FormattingRegion;
    node(node: AstNode): FormattingRegion;
    nodes(...nodes: AstNode[]): FormattingRegion;
    properties(...properties: Properties<T>[]): FormattingRegion;
    property(property: Properties<T>, index?: number): FormattingRegion;
}

Type Parameters

Implemented by

Methods

  • Creates a new formatting region that contains all nodes between the given formatting regions.

    For example, can be used to retrieve a formatting region that contains all nodes between two curly braces:

    const formatter = this.getNodeFormatter(node);
    const bracesOpen = formatter.keyword('{');
    const bracesClose = formatter.keyword('}');
    formatter.interior(bracesOpen, bracesClose).prepend(Formatting.indent());

    Parameters

    • start: FormattingRegion

      Determines where the search for interior nodes should start

    • end: FormattingRegion

      Determines where the search for interior nodes should end

    Returns FormattingRegion

  • Creates a new formatting region that contains the specified keyword of the supplied node.

    Parameters

    • keyword: string

      The keyword to format. Scoped to the supplied node.

    • Optionalindex: number

      The index of the keyword, necessary if the keyword appears multiple times. 0 by default. To retrieve all keywords, use the keywords method instead.

    Returns FormattingRegion

  • Creates a new formatting region that contains the specified property of the supplied node.

    Parameters

    • property: Properties<T>

      The name of the property to format. Scoped to the supplied node.

    • Optionalindex: number

      The index of the property, if the property is an array. 0 by default. To retrieve all elements of this array, use the properties method instead.

    Returns FormattingRegion