"use strict"
const htmlparser = require("htmlparser2")
const TransformableString = require("./TransformableString")
function iterateScripts(code, options, onChunk) {
if (!code) return
const xmlMode = options.xmlMode
const isJavaScriptMIMEType = options.isJavaScriptMIMEType || (() => true)
let index = 0
let inScript = false
let nextType = null
let nextEnd = null
function emitChunk(type, end, lastChunk) {
// Ignore empty chunks
if (index !== end) {
// Keep concatenating same type chunks
if (nextType !== null && nextType !== type) {
onChunk({
type: nextType,
start: index,
end: nextEnd,
})
index = nextEnd
}
nextType = type
nextEnd = end
if (lastChunk) {
onChunk({
type: nextType,
start: index,
end: nextEnd,
})
}
}
}
const parser = new htmlparser.Parser({
onopentag (name, attrs) {
// Test if current tag is a valid