Skip to content

refactor: parse import.meta context options with a serde AST deserializer#14825

Draft
intellild wants to merge 6 commits into
mainfrom
poc/ast-serde-context-options
Draft

refactor: parse import.meta context options with a serde AST deserializer#14825
intellild wants to merge 6 commits into
mainfrom
poc/ast-serde-context-options

Conversation

@intellild

Copy link
Copy Markdown
Contributor

Summary

Replaces the hand-rolled object-literal options parsing in the import.meta
context dependency parser (import.meta.glob() and
import.meta.webpackContext()) with a serde Deserializer over the swc AST,
similar to declaring a zod schema in TypeScript.

  • Adds utils/ast_deserializer.rs: a serde Deserializer for AST
    expressions. Options objects are now declared as plain
    #[derive(Deserialize)] structs mirroring the TypeScript declarations in
    packages/rspack/module.d.ts, instead of per-property
    get_*_by_obj_prop lookups.
  • Supports string/bool/number literals, template literals without
    substitutions, nested objects, regex literals (with span preserved for
    diagnostics), undefined/null as absent, and statically resolved
    (computed) property names. Records deserialize into IndexMap/HashMap,
    which the future partially-known import(..., { with }) attributes can
    also build on (struct + #[serde(flatten)]).
  • A lenient field attribute falls back to the field default on
    unrecognized values, preserving the previous "ignore invalid values"
    semantics. caseSensitive stays manual because it needs expression
    evaluation and a per-field warning.
  • Collapses the duplicated default branches of
    create_import_meta_context_dependency into 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 query records are skipped instead of poisoning the whole query,
and duplicate keys are now last-wins.

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 8f976d9 to refactor(core): improve referenced export data struct (#14796) by Cong-Cong Pan

❌ Size increased by 36.00KB from 66.59MB to 66.63MB (⬆️0.05%)

@github-actions

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 551.8 KB 0 0
react-10k 5.6 MB 1.3 MB 0 0
react-1k 823.1 KB 217.0 KB 0 0
ui-components 4.9 MB 1.4 MB 0 0
react-5k 2.7 MB 663.8 KB 0 0

Generated by Rsdoctor GitHub Action

@codspeed-hq

codspeed-hq Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 2.21%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 42 untouched benchmarks
⏩ 47 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

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)

Open in CodSpeed

Footnotes

  1. 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.

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