refactor: parse import.meta context options with a serde AST deserializer#14825
refactor: parse import.meta context options with a serde AST deserializer#14825intellild wants to merge 6 commits into
Conversation
📦 Binary Size-limit
❌ Size increased by 36.00KB from 66.59MB to 66.63MB (⬆️0.05%) |
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
Merging this PR will degrade performance by 2.21%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | rust@create_module_hashes |
8.3 ms | 8.5 ms | -2.21% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing poc/ast-serde-context-options (8f976d9) with main (25274d8)
Footnotes
-
47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Summary
Replaces the hand-rolled object-literal options parsing in the import.meta
context dependency parser (
import.meta.glob()andimport.meta.webpackContext()) with a serdeDeserializerover the swc AST,similar to declaring a zod schema in TypeScript.
utils/ast_deserializer.rs: a serdeDeserializerfor ASTexpressions. Options objects are now declared as plain
#[derive(Deserialize)]structs mirroring the TypeScript declarations inpackages/rspack/module.d.ts, instead of per-propertyget_*_by_obj_proplookups.substitutions, nested objects, regex literals (with span preserved for
diagnostics),
undefined/nullas absent, and statically resolved(computed) property names. Records deserialize into
IndexMap/HashMap,which the future partially-known
import(..., { with })attributes canalso build on (struct +
#[serde(flatten)]).lenientfield attribute falls back to the field default onunrecognized values, preserving the previous "ignore invalid values"
semantics.
caseSensitivestays manual because it needs expressionevaluation and a per-field warning.
create_import_meta_context_dependencyinto a single parse.Behavior notes (edge cases only, all aligned with JS runtime semantics):
no-substitution template strings are now accepted for all string options,
statically resolvable computed keys can match known options, unresolvable
keys in
queryrecords are skipped instead of poisoning the whole query,and duplicate keys are now last-wins.
Related links
Checklist