From c124b052bf12b8e4c94c1eedb1487313cabf82d1 Mon Sep 17 00:00:00 2001 From: oxura Date: Tue, 20 Oct 2026 11:28:31 -0300 Subject: [PATCH] Classify inline modules using HTML character and whitespace rules HTMLRewriter keeps character references in attributes, so an encoded "module" was skipped, and trim() strips NBSP, so a non-module type ran. Decode the ASCII references that can spell "module" and trim only HTML whitespace. Closes #1767 Co-Authored-By: Claude Opus 5.5 (1M context) --- bend2/main.ts | 10 ++++++- tests/io/html_script_types.bend | 12 +++++++++ tests/io/html_script_types.js | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/io/html_script_types.bend create mode 100644 tests/io/html_script_types.js diff --git a/bend2/main.ts b/bend2/main.ts index 5419cdfa3..ab83c5ad9 100755 --- a/bend2/main.ts +++ b/bend2/main.ts @@ -505,9 +505,17 @@ function cli_base(what?: string): void { } // An inline module script; an empty svg `); + const built = child.spawnSync(process.execPath, + [path.resolve("bend2/main.ts"), page, "-o", out], options); + if (built.status !== 0) return 1; + const entries = []; + new HTMLRewriter().on("script", { element(el) { + const src = el.getAttribute("src"); + if (src !== null) entries.push(path.resolve(out, src)); + }}).transform(fs.readFileSync(path.join(out, "index.html"), "utf8")); + let output = ""; + for (const entry of entries) { + const run = child.spawnSync(process.execPath, [entry], options); + if (run.status !== 0) return 2; + output += run.stdout; + } + if (output !== expected) return 3 + i; + } + return 0; + } finally { + fs.rmSync(dir, { recursive: true, force: true }); + } +} + +io_eff(CID(HTML.script_types), html_script_types);