Interface TreeAdapter<T>

Tree adapter is a set of utility functions that provides minimal required abstraction layer beetween parser and a specific AST format. Note that TreeAdapter is not designed to be a general purpose AST manipulation library. You can build such library on top of existing TreeAdapter or use one of the existing libraries from npm.

See

Have a look at the default tree adapter for reference.

Type Parameters

Hierarchy

  • TreeAdapter

Properties

onItemPop?: ((item, newTop) => void)

Type declaration

    • (item, newTop): void
    • Optional callback for elements being popped from the stack of open elements.

      Parameters

      • item: T["element"]

        The element being popped.

      • newTop: T["parentNode"]

      Returns void

onItemPush?: ((item) => void)

Type declaration

    • (item): void
    • Optional callback for elements being pushed to the stack of open elements.

      Parameters

      • item: T["element"]

      Returns void

Methods

  • Copies attributes to the given element. Only attributes that are not yet present in the element are copied.

    Parameters

    • recipient: T["element"]

      Element to copy attributes into.

    • attrs: Attribute[]

      Attributes to copy.

    Returns void

  • Appends a child node to the given parent node.

    Parameters

    • parentNode: T["parentNode"]

      Parent node.

    • newNode: T["childNode"]

      Child node.

    Returns void

  • Creates a comment node.

    Parameters

    • data: string

      Comment text.

    Returns T["commentNode"]

  • Creates a document fragment node.

    Returns T["documentFragment"]

  • Creates an element node.

    Parameters

    • tagName: string

      Tag name of the element.

    • namespaceURI: NS

      Namespace of the element.

    • attrs: Attribute[]

      Attribute name-value pair array. Foreign attributes may contain namespace and prefix fields as well.

    Returns T["element"]

  • Removes a node from its parent.

    Parameters

    • node: T["childNode"]

      Node to remove.

    Returns void

  • Returns the given element's attributes in an array, in the form of name-value pairs. Foreign attributes may contain namespace and prefix fields as well.

    Parameters

    • element: T["element"]

      Element.

    Returns Attribute[]

  • Returns the given node's children in an array.

    Parameters

    • node: T["parentNode"]

      Node.

    Returns T["childNode"][]

  • Returns the given comment node's content.

    Parameters

    • commentNode: T["commentNode"]

      Comment node.

    Returns string

  • Returns the given document type node's name.

    Parameters

    • doctypeNode: T["documentType"]

      Document type node.

    Returns string

  • Returns the given document type node's public identifier.

    Parameters

    • doctypeNode: T["documentType"]

      Document type node.

    Returns string

  • Returns the given document type node's system identifier.

    Parameters

    • doctypeNode: T["documentType"]

      Document type node.

    Returns string

  • Returns the first child of the given node.

    Parameters

    • node: T["parentNode"]

      Node.

    Returns null | T["childNode"]

  • Returns the given node's parent.

    Parameters

    • node: T["node"]

      Node.

    Returns null | T["parentNode"]

  • Returns the given element's tag name.

    Parameters

    • element: T["element"]

      Element.

    Returns string

  • Returns the <template> element content element.

    Parameters

    • templateElement: T["template"]

      <template> element.

    Returns T["documentFragment"]

  • Returns the given text node's content.

    Parameters

    • textNode: T["textNode"]

      Text node.

    Returns string

  • Inserts a child node to the given parent node before the given reference node.

    Parameters

    • parentNode: T["parentNode"]

      Parent node.

    • newNode: T["childNode"]

      Child node.

    • referenceNode: T["childNode"]

      Reference node.

    Returns void

  • Inserts text into a node. If the last child of the node is a text node, the provided text will be appended to the text node content. Otherwise, inserts a new text node with the given text.

    Parameters

    • parentNode: T["parentNode"]

      Node to insert text into.

    • text: string

      Text to insert.

    Returns void

  • Inserts text into a sibling node that goes before the reference node. If this sibling node is the text node, the provided text will be appended to the text node content. Otherwise, inserts a new sibling text node with the given text before the reference node.

    Parameters

    • parentNode: T["parentNode"]

      Node to insert text into.

    • text: string

      Text to insert.

    • referenceNode: T["childNode"]

      Node to insert text before.

    Returns void

  • Determines if the given node is a comment node.

    Parameters

    • node: T["node"]

      Node.

    Returns node is T["commentNode"]

  • Determines if the given node is a document type node.

    Parameters

    • node: T["node"]

      Node.

    Returns node is T["documentType"]

  • Determines if the given node is an element.

    Parameters

    • node: T["node"]

      Node.

    Returns node is T["element"]

  • Determines if the given node is a text node.

    Parameters

    • node: T["node"]

      Node.

    Returns node is T["textNode"]

  • Sets the document type. If the document already contains a document type node, the name, publicId and systemId properties of this node will be updated with the provided values. Otherwise, creates a new document type node with the given properties and inserts it into the document.

    Parameters

    • document: T["document"]

      Document node.

    • name: string

      Document type name.

    • publicId: string

      Document type public identifier.

    • systemId: string

      Document type system identifier.

    Returns void

  • Sets the <template> element content element.

    Parameters

    • templateElement: T["template"]

      <template> element.

    • contentElement: T["documentFragment"]

      Content element.

    Returns void

  • Updates the source code location information of the node.

    Parameters

    Returns void

Generated using TypeDoc