Class NodeAbstract

The Abstract Syntax Tree will be constituted by instances of Node.

It implements Origin as it could be the source of a AST-to-AST transformation, so the node itself can be the Origin of another node.

Hierarchy (view full)

Implements

Constructors

Properties

destination?: Destination
origin?: Origin
parent?: Node
parseTree?: ParseTree
positionOverride?: Position

Accessors

  • get sourceText(): undefined | string
  • Returns undefined | string

Methods

  • Parameters

    • name: string | symbol
    • child: Node

    Returns void

  • Tests whether the given position is contained in the interval represented by this object.

    Parameters

    • Optional position: Position

      the position

    Returns boolean

  • Parameters

    • name: string | symbol

    Returns any

  • Parameters

    • name: string | symbol

    Returns any

  • Parameters

    • name: string | symbol
    • value: any

    Returns void

  • Finds the first node that satisfies a condition among this node's descendants.

    Parameters

    • predicate: ((n, index) => boolean)

      the function expressing the condition that the node must satisfy.

        • (n, index): boolean
        • Parameters

          • n: Node
          • index: number

          Returns boolean

    • Optional walker: ((node) => Generator<Node>)

      the function that generates the nodes to operate on in the desired sequence. By default, this is a depth-first traversal that includes the node on which find() has been called.

        • (node): Generator<Node>
        • A generator that walks the whole AST starting from the provided node, depth-first.

          Parameters

          • node: Node

            the starting node.

          Returns Generator<Node>

    Returns undefined | Node

    the first node in the AST for which the predicate is true. Returns undefined if none are found.

  • Note that the type is not strictly forced to be a subclass of Node. This is intended to support interfaces like Statement or Expression. However, being an ancestor the returned value is guaranteed to be a Node, as only Node instances can be part of the hierarchy.

    Parameters

    • type: any

    Returns undefined | Node

    ancestor the nearest ancestor of this node that is of type type.

  • Parameters

    • position: Position

      the position where to search for nodes

    • Optional selfContained: boolean

      whether the starting node position contains the positions of all its children. If true no further search will be performed in subtrees where the root node falls outside the given position. If false (default) the research will cover all nodes from the starting node to the leaves.

    Returns undefined | Node

    the node most closely containing the given [position]. undefined if none is found.

    See

    searchByPosition

  • Parameters

    • name: string | symbol

    Returns any

  • Parameters

    • name: string | symbol
    • Optional index: number

    Returns undefined | Node

  • Parameters

    • name: string | symbol

    Returns Error

  • Tests whether the given position overlaps the interval represented by this object.

    Parameters

    • Optional position: Position

      the position

    Returns boolean

  • Parameters

    • position: Position

      the position where to search for nodes

    • Optional selfContained: boolean

      whether the starting node position contains the positions of all its children. If true: no further search will be performed in subtrees where the root node falls outside the given position.

      • If false (default): the search will cover all nodes from the starting node to the leaves. In any case, the search stops at the first subtree found to be containing the position.

    Returns Generator<Node, any, unknown>

    all nodes containing the given [position] using depth-first search. Empty list if none are found.

  • Parameters

    • name: string | symbol
    • value: any

    Returns void

  • Parameters

    • name: string | symbol
    • child: Node

    Returns void

  • A generator that walks over the whole AST starting from this node, depth-first.

    Returns Generator<Node, any, unknown>

  • Returns Generator<Node, any, unknown>

    nodes the sequence of nodes from the parent all the way up to the root node. For this to work, the nodes' parents must have been set.

  • A generator that walks over the whole AST starting from the children of this node.

    Parameters

    • Optional walker: ((node) => Generator<Node>)

      a function that generates a sequence of nodes. By default, this is the depth-first "walk" function. For post-order traversal, use "walkLeavesFirst".

        • (node): Generator<Node>
        • A generator that walks the whole AST starting from the provided node, depth-first.

          Parameters

          • node: Node

            the starting node.

          Returns Generator<Node>

    Returns Generator<Node, any, unknown>

  • Parameters

    • position: Position

      the position within which the walk should remain

    Returns Generator<Node, any, unknown>

    walks the AST within the given [position] starting from this node, depth-first.

  • Parameters

    • Optional parseTree: null | ParseTree
    • Optional source: Source

    Returns this

Generated using TypeDoc