import { Abbreviation , AbbreviationNode , Value , AbbreviationAttribute } from '@emmetio/abbreviation' ; export default function stringify ( abbr ) { return abbr . children . map ( elem ) . join ( '' ) ; } function elem ( node ) { const name = node . name || '?' ; const attributes = node . attributes ? node . attributes . map ( attr => ' ' + attribute ( attr ) ) . join ( '' ) : '' ; const value = node . value ? stringifyValue ( node . value ) : '' ; const repeat = node . repeat ? `*${ node . repeat . count }@${ node . repeat . value }` : '' ; if ( ! node . name && ! node . attributes ) { return value ; } return node . selfClosing && ! node . value && ! node . children . length ? `<${ name }${ repeat }${ attributes } />` : `<${ name }${ repeat }${ attributes }>${ value }${ node . children . map ( elem ) . join ( '' ) }</${ name }>` ; } function attribute ( attr ) { const name = attr . name || '?' ; let before = '"' ; let after = '"' ; if ( attr . valueType === 'expression' ) { before = '{' ; after = '}' ; } const value = before + ( attr . value ? `${ stringifyValue ( attr . value ) }` : '' ) + after ; return `${ name }=${ value }` ; } function stringifyValue ( items ) { return items . map ( item => typeof item === 'string' ? item : ( item . name ? `\${${ item . index ! }:${ item . name }}` : `\${${ item . index ! }}` ) ) . join ( '' ) ; }