Skip to content

refactor(cache): replace regex resource extraction with HTML parser + JS AST - #17

Merged
vshengbro merged 1 commit into
masterfrom
fix/iife-wasm-fetch
Sep 21, 2026
Merged

vshengbro merged 1 commit into
masterfrom
fix/iife-wasm-fetch

Conversation

@vshengbro

Copy link
Copy Markdown
Collaborator

Replace fragile regex-based resource discovery with scraper HTML parser and swc_ecma_parser JS AST walker. Fully generic: handles IIFE inline-bridge, ES module imports, new URL(), dynamic import(), and any future string-literal resource pattern without hardcoded variable names. New deps: scraper, swc_ecma_ast, swc_ecma_parser, swc_common. Fixes white-screen regression from euv-dev/euv#250.

… JS AST

Replace the fragile regex-based resource discovery with two robust
parser-based extractors:

1. scraper::Html parses the DOM and extracts <script src>, <link href>,
   <img src>, and inline <script> bodies.

2. swc_ecma_parser::parse_file_as_program parses inline JS and walks
   the AST to find all string literals ending in known resource
   extensions (.wasm, .js, .css, .png, .jpg, .svg, .woff, etc.).

This is fully generic: it handles the IIFE inline-bridge format
(var __euv_wasm_url = "pkg/euv_bg.wasm") without any hardcoded
variable names, and it also handles standard ES module imports,
new URL(...), dynamic import(), and any other string-literal resource
reference pattern that euv-cli may emit in the future.

New dependencies:
- scraper = "0.27.0"
- swc_ecma_ast = "29.0.2"
- swc_ecma_parser = "45.1.4"
- swc_common = "26.0.0"

Fixes the white-screen regression introduced by euv-dev/euv#250.
@vshengbro
vshengbro merged commit d61542e into master Sep 21, 2026
1 check failed
@vshengbro
vshengbro deleted the fix/iife-wasm-fetch branch September 21, 2026 08:09
vshengbro added a commit that referenced this pull request Sep 21, 2026
…wc paths via lib.rs

PR #17 introduced scraper HTML parsing + swc_ecma_parser AST walking as the
replacement for the regex-based resource extraction, but the diff had three
rust-standards violations that block reviewer approval:

1. Four Selector::parse(...).unwrap() calls (R11.4 - no unwrap in production).
   The selector strings are compile-time constants, so the panic is
   theoretical, but rust-standards bans unwrap/expect/panic unconditionally
   and forbids #[allow] macros for silencing lint. Fix: lazy-init a
   OnceLock<Result<[Selector; 4], String>> in cache/static.rs, surface the
   (impossible) parse error via euv_log! + early return.

2. fn.rs hardcoded byte/string literals (R1.3c literal purity). Move CSS
   selector strings (script[src], link[href], img[src], script:not([src])),
   URL scheme prefixes (http://, https://, data:, //, ://), and the 16
   resource-extension suffixes (.wasm, .js, .mjs, .css, ...) to const.rs.
   Replace the long if/else chain in is_resource_path() with a
   RESOURCE_EXTENSIONS.iter().any(|s| value.ends_with(*s)) loop.

3. swc_ecma_ast::Expr / Lit / Callee / MemberProp / etc. long-path calls in
   sub-file fn.rs bodies (R6.4-pitfall-b). The sub-file already has
   use super::*; and the lib.rs already re-exports swc_ecma_ast::{EsVersion,
   Program} - extend that block to also expose ArrowFunctionBody, Callee, Decl,
   Expr, Lit, MemberProp, ModuleDecl, ModuleItem, Prop, PropOrSpread, Stmt,
   VarDeclOrExpr, and the corresponding swc_common::FileName +
   scraper::selector::SelectorErrorKind. Replace every swc_ecma_ast::xxx
   reference with the short name (Expr, Stmt, ...).

Resulting audit: 19/19 PASS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant