next.js
5070ad0d - [turbopack] Add #[derive(ValueToString)] and convert ~45 manual impls (#89788)

Commit
78 days ago
[turbopack] Add #[derive(ValueToString)] and convert ~45 manual impls (#89788) ## What Add a `#[derive(ValueToString)]` proc macro and convert ~45 manual `ValueToString` implementations across turbopack crates to use it (-660 lines of boilerplate, 49 files touched). ## Why Nearly every `ValueToString` impl follows the same pattern: format some fields into a string, possibly awaiting `Vc` values first. These hand-written impls are noisy boilerplate that obscure the actual format string. ## How The derive macro generates the `#[turbo_tasks::value_impl] impl ValueToString` block automatically. A helper trait `ValueToStringify` with a blanket impl for `Display` and specializations for `Vc<T>`/`ResolvedVc<T>` handles async resolution of fields. ### Supported forms - **No attribute** — delegates to `Display::to_string(&self)` - `#[value_to_string("constant")]` — emits `rcstr!` directly - `#[value_to_string("{field} text {other_field}")]` — auto-resolves named/positional fields via `ValueToStringify` - `#[value_to_string("fmt {}", expr1, expr2)]` — explicit expressions as format args - `#[value_to_string(expr)]` — single expression delegation Enums support per-variant attributes (defaulting to variant name) or a single top-level attribute.
Author
Parents
Loading