Repository navigation
refactor(cache): replace regex resource extraction with HTML parser + JS AST - #17
Merged
Merged
Conversation
… 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
force-pushed
the
fix/iife-wasm-fetch
branch
from
September 21, 2026 08:08
24aeae8 to
2bfcc1d
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.