async function injectPolyfillsLoader(htmlString, cfg) {
    const documentAst = parse5_1.parse(htmlString);
    const headAst = parse5_utils_1.findElement(documentAst, e => parse5_utils_1.getTagName(e) === 'head');
    const bodyAst = parse5_utils_1.findElement(documentAst, e => parse5_utils_1.getTagName(e) === 'body');
    if (!headAst || !bodyAst) {
        throw new Error(`Invalid index.html: missing <head> or <body>`);
    }
    const polyfillsLoader = await createPolyfillsLoader_1.createPolyfillsLoader(cfg);
    if (polyfillsLoader === null) {
        return { htmlString, polyfillFiles: [] };
    }
    if (cfg.preload) {
        injectPrefetchLinks(headAst, cfg);
    }
    injectImportMapPolyfills(documentAst, headAst, cfg);
    injectLoaderScript(bodyAst, polyfillsLoader);
    return {
        htmlString: parse5_1.serialize(documentAst),
        polyfillFiles: polyfillsLoader.polyfillFiles,
    };
}
/**
 * Transforms an index.html file, injecting a polyfills loader for
 * compatibility with older browsers.
 */
Transforms an index.html file, injecting a polyfills loader for
compatibility with older browsers.
Transforms an index . html file injecting a polyfills loader for compatibility with older browsers .
async function injectPolyfillsLoader(htmlString, cfg) {
    const documentAst = parse5_1.parse(htmlString);
    const headAst = parse5_utils_1.findElement(documentAst, e => parse5_utils_1.getTagName(e) === 'head');
    const bodyAst = parse5_utils_1.findElement(documentAst, e => parse5_utils_1.getTagName(e) === 'body');
    if (!headAst || !bodyAst) {
        throw new Error(`Invalid index.html: missing <head> or <body>`);
    }
    const polyfillsLoader = await createPolyfillsLoader_1.createPolyfillsLoader(cfg);
    if (polyfillsLoader === null) {
        return { htmlString, polyfillFiles: [] };
    }
    if (cfg.preload) {
        injectPrefetchLinks(headAst, cfg);
    }
    injectImportMapPolyfills(documentAst, headAst, cfg);
    injectLoaderScript(bodyAst, polyfillsLoader);
    return {
        htmlString: parse5_1.serialize(documentAst),
        polyfillFiles: polyfillsLoader.polyfillFiles,
    };
}
async function injectPolyfillsLoader ( htmlString , cfg ) { const documentAst = parse5_1 . parse ( htmlString ) ; const headAst = parse5_utils_1 . findElement ( documentAst , e => parse5_utils_1 . getTagName ( e ) === 'head' ) ; const bodyAst = parse5_utils_1 . findElement ( documentAst , e => parse5_utils_1 . getTagName ( e ) === 'body' ) ; if ( ! headAst || ! bodyAst ) { throw new Error ( ` ` ) ; } const polyfillsLoader = await createPolyfillsLoader_1 . createPolyfillsLoader ( cfg ) ; if ( polyfillsLoader === null ) { return { htmlString , polyfillFiles : [ ] } ; } if ( cfg . preload ) { injectPrefetchLinks ( headAst , cfg ) ; } injectImportMapPolyfills ( documentAst , headAst , cfg ) ; injectLoaderScript ( bodyAst , polyfillsLoader ) ; return { htmlString : parse5_1 . serialize ( documentAst ) , polyfillFiles : polyfillsLoader . polyfillFiles , } ; }
Transforms an index.html file, injecting a polyfills loader for
 compatibility with older browsers.
Transforms an index . html file injecting a polyfills loader for compatibility with older browsers .