import find from 'lodash/find' import type RewritingStream from 'parse5-html-rewriting-stream' import * as js from './js' export function install (url: string, rewriter: RewritingStream, deferSourceMapRewrite?: js.DeferSourceMapRewriteFn) { let currentlyInsideJsScriptTag = false let inlineJsIndex = 0 rewriter.on('startTag', (startTag, raw) => { if (startTag.tagName !== 'script') { currentlyInsideJsScriptTag = false return rewriter.emitRaw(raw) } const typeAttr = find(startTag.attrs, { name: 'type' }) if (typeAttr && typeAttr.value !== 'text/javascript' && typeAttr.value !== 'module') { // we don't care about intercepting non-JS