import * as ast from "../../ast" ; import * as files from "../../filesystem/index" ; import { TagMapper } from "../tag-mapper" ; /** ClosingTagParser parses HTML blocks containing just a closing tag. */ export class ClosingTagParser { private readonly closingTagRE : RegExp ; private readonly tagMapper : TagMapper ; constructor ( tagMapper ) { this . closingTagRE = /^\s*<[ ]*(\/[ ]*\w+)[ ]*>\s*$/ ; this . tagMapper = tagMapper ; } /** Returns whether the given tag is a closing tag */ isClosingTag ( tag ) { return this . closingTagRE . test ( tag ) ; } parse ( tag , location ) { const match = this . closingTagRE . exec ( tag ) ; if ( ! match ) { throw new Error ( `no tag parsed in ${ tag }` ) ; } const tagName = match [ 1 ] . replace ( / /g , "" ) as ast . NodeTag ; const result = new ast . NodeList ( ) ; result . push ( new ast . Node ( { attributes : { } , content : "" , location , tag : tagName , type : this . tagMapper . typeForTag ( tagName , { } ) , } ) ) ; return result ; } }