license import * as babel from 'babel-types' ; import { ASTNode } from 'parse5' ; import { ResolvedUrl } from 'polymer-analyzer' ; export interface BundledBaseDocument < Node > { ast : Node ; content : string ; files : ResolvedUrl [ ] ; } export type BundledHtmlDocument = { language : 'html' ; } & BundledBaseDocument < ASTNode > ; export type BundledJsDocument = { language : 'js' ; } & BundledBaseDocument < babel . Node > ; export type BundledDocument = BundledHtmlDocument | BundledJsDocument ; export class DocumentCollection extends Map < ResolvedUrl , BundledDocument > { getHtmlDoc ( url ) { const result = this . get ( url ) ; if ( result === undefined ) { return undefined ; } if ( result . language !== 'html' ) { throw new Error ( `Expected url ${ url } to be html but it was ${ result . language }` ) ; } return result ; } getJsDoc ( url ) { const result = this . get ( url ) ; if ( result === undefined ) { return undefined ; } if ( result . language !== 'js' ) { throw new Error ( `Expected url ${ url } to be js but it was ${ result . language }` ) ; } return result ; } }