interface TreeAdapter < T > { 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 on Item Pop ?: ( ( item : T [ "element" ] ,
newTop : T [ "parentNode" ] ) => void ) Type declaration ( item , newTop ) : void Parameters item : T [ "element" ] newTop : T [ "parentNode" ] Returns void Optional
on Item Push on Item Push ?: ( ( item : T [ "element" ] ) => void ) Methodsadopt Attributes adopt Attributes ( recipient , attrs ) : void Returns void append Child append Child ( parentNode , newNode ) : void Parameters parentNode : T [ "parentNode" ] newNode : T [ "childNode" ] Returns void create Comment Node create Comment Node ( data ) : T [ "commentNode" ] Returns T [ "commentNode" ] create Document create Document ( ) : T [ "document" ] Returns T [ "document" ] create Document Fragment create Document Fragment ( ) : T [ "documentFragment" ] Returns T [ "documentFragment" ] create Element create Element ( tagName , namespaceURI , attrs ) : T [ "element" ] Returns T [ "element" ] create Text Node create Text Node ( value ) : T [ "textNode" ] Returns T [ "textNode" ] detach Node detach Node ( node ) : void Returns void get Child Nodes get Child Nodes ( node ) : T [ "childNode" ] [] Returns T [ "childNode" ] [] get Comment Node Content get Comment Node Content ( commentNode ) : string Parameters commentNode : T [ "commentNode" ] Returns string get Document Type Node Name get Document Type Node Name ( doctypeNode ) : string Parameters doctypeNode : T [ "documentType" ] Returns string get Document Type Node Public Id get Document Type Node Public Id ( doctypeNode ) : string Parameters doctypeNode : T [ "documentType" ] Returns string get Document Type Node System Id get Document Type Node System Id ( doctypeNode ) : string Parameters doctypeNode : T [ "documentType" ] Returns string get First Child get First Child ( node ) : null | T [ "childNode" ] Returns null | T [ "childNode" ] get NamespaceURI get NamespaceURI ( element ) : NS Returns NS get Node Source Code Location get Parent Node get Parent Node ( node ) : null | T [ "parentNode" ] Returns null | T [ "parentNode" ] get Tag Name get Tag Name ( element ) : string Returns string get Template Content get Template Content ( templateElement ) : T [ "documentFragment" ] Parameters templateElement : T [ "template" ] Returns T [ "documentFragment" ] get Text Node Content get Text Node Content ( textNode ) : string Returns string insert Before insert Before ( parentNode , newNode , referenceNode ) : void Parameters parentNode : T [ "parentNode" ] newNode : T [ "childNode" ] referenceNode : T [ "childNode" ] Returns void insert Text insert Text ( parentNode , text ) : void Parameters parentNode : T [ "parentNode" ] text : string Returns void insert Text Before insert Text Before ( parentNode , text , referenceNode ) : void Parameters parentNode : T [ "parentNode" ] text : string referenceNode : T [ "childNode" ] Returns void is Comment Node is Comment Node ( node ) : node is T [ "commentNode" ] Returns node is T [ "commentNode" ] is Document Type Node is Document Type Node ( node ) : node is T [ "documentType" ] Returns node is T [ "documentType" ] is Element Node is Element Node ( node ) : node is T [ "element" ] Returns node is T [ "element" ] is Text Node is Text Node ( node ) : node is T [ "textNode" ] Returns node is T [ "textNode" ] set Document Mode set Document Mode ( document , mode ) : void Returns void set Document Type set Document Type ( document , name , publicId , systemId ) : void Parameters document : T [ "document" ] name : string publicId : string systemId : string Returns void set Node Source Code Location set Node Source Code Location ( node , location ) : void Returns void set Template Content set Template Content ( templateElement , contentElement ) : void Parameters templateElement : T [ "template" ] contentElement : T [ "documentFragment" ] Returns void update Node Source Code Location update Node Source Code Location ( node , location ) : 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.