#!/usr/bin/env node /* Minify the inline ` or a `` this missed would not merely leave one block unminified — * `[\s\S]*?` would run on to the NEXT block's `` and the replacement would swallow * every byte of template between the two. Our templates are all lower case today; the cost of * assuming they stay that way is a silently mangled page (CodeQL js/bad-tag-filter). */ const re = /(]*>)([\s\S]*?)(<\/script\b[^>]*>)/gi; let m; while ((m = re.exec(src)) !== null) { const [ whole, open, body, close ] = m; if (!body.trim() || UCODE.test(body)) continue; const min = await minify(body, { /* the pre-paint runs before anything else on the page and owns no module scope, so it * is a script, not a module; `toplevel` would rename the IIFEs' own bindings safely but * buys little here and is one more way to differ from what the gates read */ ecma: 2020, compress: { passes: 2 }, mangle: true, format: { comments: false }, }).catch((e) => { throw new Error(`${file}: ${e.message}`); }); if (!min.code) continue; out.push(src.slice(last, m.index), open, min.code, close); last = m.index + whole.length; before += body.length; after += min.code.length; blocks++; touched = true; } if (!touched) continue; out.push(src.slice(last)); writeFileSync(file, out.join('')); files++; } /* A run that minified nothing is a run that measured nothing — the same failure mode * tools/scroll-anchor.mjs was taught to report rather than exit 0 on. */ if (!blocks) { console.error('minify-prepaint: no inline