interface TreeAdapter < T extends TreeAdapterTypeMap = TreeAdapterTypeMap > { onItemPop ?: ( item : T [ "element" ] , newTop : T [ "parentNode" ] ) => void ; onItemPush ?: ( item : T [ "element" ] ) => void ; adoptAttributes ( recipient : T [ "element" ] , attrs : Attribute [] ) : void ; appendChild ( parentNode : T [ "parentNode" ] , newNode : T [ "childNode" ] ) : void ; createCommentNode ( data : string ) : T [ "commentNode" ] ; createDocument () : T [ "document" ] ; createDocumentFragment () : T [ "documentFragment" ] ; createElement ( tagName : string , namespaceURI : NS , attrs : Attribute [] , ) : T [ "element" ] ; createTextNode ( value : string ) : T [ "textNode" ] ; detachNode ( node : T [ "childNode" ] ) : void ; getAttrList ( element : T [ "element" ] ) : Attribute [] ; getChildNodes ( node : T [ "parentNode" ] ) : T [ "childNode" ] [] ; getCommentNodeContent ( commentNode : T [ "commentNode" ] ) : string ; getDocumentMode ( document : T [ "document" ] ) : DOCUMENT_MODE ; getDocumentTypeNodeName ( doctypeNode : T [ "documentType" ] ) : string ; getDocumentTypeNodePublicId ( doctypeNode : T [ "documentType" ] ) : string ; getDocumentTypeNodeSystemId ( doctypeNode : T [ "documentType" ] ) : string ; getFirstChild ( node : T [ "parentNode" ] ) : null | T [ "childNode" ] ; getNamespaceURI ( element : T [ "element" ] ) : NS ; getNodeSourceCodeLocation ( node : T [ "node" ] , ) : undefined | null | ElementLocation ; getParentNode ( node : T [ "node" ] ) : null | T [ "parentNode" ] ; getTagName ( element : T [ "element" ] ) : string ; getTemplateContent ( templateElement : T [ "template" ] ) : T [ "documentFragment" ] ; getTextNodeContent ( textNode : T [ "textNode" ] ) : string ; insertBefore ( parentNode : T [ "parentNode" ] , newNode : T [ "childNode" ] , referenceNode : T [ "childNode" ] , ) : void ; insertText ( parentNode : T [ "parentNode" ] , text : string ) : void ; insertTextBefore ( parentNode : T [ "parentNode" ] , text : string , referenceNode : T [ "childNode" ] , ) : void ; isCommentNode ( node : T [ "node" ] ) : node is T [ "commentNode" ] ; isDocumentTypeNode ( node : T [ "node" ] ) : node is T [ "documentType" ] ; isElementNode ( node : T [ "node" ] ) : node is T [ "element" ] ; isTextNode ( node : T [ "node" ] ) : node is T [ "textNode" ] ; setDocumentMode ( document : T [ "document" ] , mode : DOCUMENT_MODE ) : void ; setDocumentType ( document : T [ "document" ] , name : string , publicId : string , systemId : string , ) : void ; setNodeSourceCodeLocation ( node : T [ "node" ] , location : null | ElementLocation , ) : void ; setTemplateContent ( templateElement : T [ "template" ] , contentElement : T [ "documentFragment" ] , ) : void ; updateNodeSourceCodeLocation ( node : T [ "node" ] , location : Partial < ElementLocation > , ) : void ; } PropertiesOptional
on Item Pop onItemPop ?: ( item : T [ "element" ] , newTop : T [ "parentNode" ] ) => void Type declaration ( item : T [ "element" ] , newTop : T [ "parentNode" ] ) : void Parameters item : T [ "element" ] newTop : T [ "parentNode" ] Returns void Optional
on Item Push onItemPush ?: ( item : T [ "element" ] ) => void Methodsadopt Attributes adoptAttributes ( recipient : T [ "element" ] , attrs : Attribute [] ) : void Returns void append Child appendChild ( parentNode : T [ "parentNode" ] , newNode : T [ "childNode" ] ) : void Parameters parentNode : T [ "parentNode" ] newNode : T [ "childNode" ] Returns void create Comment Node createCommentNode ( data : string ) : T [ "commentNode" ] Returns T [ "commentNode" ] create Document createDocument () : T [ "document" ] Returns T [ "document" ] create Document Fragment createDocumentFragment () : T [ "documentFragment" ] Returns T [ "documentFragment" ] create Element createElement ( tagName : string , namespaceURI : NS , attrs : Attribute [] , ) : T [ "element" ] Returns T [ "element" ] create Text Node createTextNode ( value : string ) : T [ "textNode" ] Returns T [ "textNode" ] detach Node detachNode ( node : T [ "childNode" ] ) : void Returns void get Child Nodes getChildNodes ( node : T [ "parentNode" ] ) : T [ "childNode" ] [] Returns T [ "childNode" ] [] get Comment Node Content getCommentNodeContent ( commentNode : T [ "commentNode" ] ) : string Parameters commentNode : T [ "commentNode" ] Returns string get Document Type Node Name getDocumentTypeNodeName ( doctypeNode : T [ "documentType" ] ) : string Parameters doctypeNode : T [ "documentType" ] Returns string get Document Type Node Public Id getDocumentTypeNodePublicId ( doctypeNode : T [ "documentType" ] ) : string Parameters doctypeNode : T [ "documentType" ] Returns string get Document Type Node System Id getDocumentTypeNodeSystemId ( doctypeNode : T [ "documentType" ] ) : string Parameters doctypeNode : T [ "documentType" ] Returns string get First Child getFirstChild ( node : T [ "parentNode" ] ) : null | T [ "childNode" ] Returns null | T [ "childNode" ] get NamespaceURI getNamespaceURI ( element : T [ "element" ] ) : NS Returns NS get Node Source Code Location get Parent Node getParentNode ( node : T [ "node" ] ) : null | T [ "parentNode" ] Returns null | T [ "parentNode" ] get Tag Name getTagName ( element : T [ "element" ] ) : string Returns string get Template Content getTemplateContent ( templateElement : T [ "template" ] ) : T [ "documentFragment" ] Parameters templateElement : T [ "template" ] Returns T [ "documentFragment" ] get Text Node Content getTextNodeContent ( textNode : T [ "textNode" ] ) : string Returns string insert Before insertBefore ( parentNode : T [ "parentNode" ] , newNode : T [ "childNode" ] , referenceNode : T [ "childNode" ] , ) : void Parameters parentNode : T [ "parentNode" ] newNode : T [ "childNode" ] referenceNode : T [ "childNode" ] Returns void insert Text insertText ( parentNode : T [ "parentNode" ] , text : string ) : void Parameters parentNode : T [ "parentNode" ] text : string Returns void insert Text Before insertTextBefore ( parentNode : T [ "parentNode" ] , text : string , referenceNode : T [ "childNode" ] , ) : void Parameters parentNode : T [ "parentNode" ] text : string referenceNode : T [ "childNode" ] Returns void is Comment Node isCommentNode ( node : T [ "node" ] ) : node is T [ "commentNode" ] Returns node is T [ "commentNode" ] is Document Type Node isDocumentTypeNode ( node : T [ "node" ] ) : node is T [ "documentType" ] Returns node is T [ "documentType" ] is Element Node isElementNode ( node : T [ "node" ] ) : node is T [ "element" ] Returns node is T [ "element" ] is Text Node isTextNode ( node : T [ "node" ] ) : node is T [ "textNode" ] Returns node is T [ "textNode" ] set Document Mode setDocumentMode ( document : T [ "document" ] , mode : DOCUMENT_MODE ) : void Returns void set Document Type setDocumentType ( document : T [ "document" ] , name : string , publicId : string , systemId : string , ) : void Parameters document : T [ "document" ] name : string publicId : string systemId : string Returns void set Node Source Code Location setNodeSourceCodeLocation ( node : T [ "node" ] , location : null | ElementLocation , ) : void Returns void set Template Content setTemplateContent ( templateElement : T [ "template" ] , contentElement : T [ "documentFragment" ] , ) : void Parameters templateElement : T [ "template" ] contentElement : T [ "documentFragment" ] Returns void update Node Source Code Location updateNodeSourceCodeLocation ( node : T [ "node" ] , location : Partial < ElementLocation > , ) : void Returns void
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 existingTreeAdapter
or use one of the existing libraries from npm.See
Have a look at the default tree adapter for reference.