Repository navigation
refactor: serialize CSS through PrinterTrait - #17
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6503a0d3a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fn state_mut(&mut self) -> &mut PrinterState<'_, '_> { | ||
| unsafe { std::mem::transmute::<&mut PrinterState<'a, 'c>, &mut PrinterState<'_, '_>>(&mut self.state) } |
There was a problem hiding this comment.
Prevent lifetime-erased printer state from escaping
A safe custom ToCss implementation can call std::mem::swap(dest.state_mut(), other.state_mut()) with another printer because both returned states have lifetimes shortened to the temporary borrows. This allows borrowed CSS-module data, or the stack-backed nesting context, to move into a printer that outlives the original serialization. Subsequent serialization through that printer can then dereference dangling references or context pointers. Sealing PrinterTrait does not prevent callers from using its public methods this way. Keep mutable state inaccessible to external implementations, or expose operations that preserve its actual lifetimes rather than transmuting a mutable reference.
Useful? React with 👍 / 👎.
c6503a0 to
88b1907
Compare
88b1907 to
2ed94ad
Compare
2ed94ad to
62d0547
Compare
Summary
PrinterTraitabstraction with scoped access to printer internals.ToCssand related serialization helpers to acceptPrinterTraitrather than one concretePrinter<W>type..map_err(Into::into)to?cleanup in the prerequisite printer PR, so this diff focuses on the trait migration.parcel_sourcemapAPI in this layer.@scope. Keep mapping feature gates and serializer state transitions aligned with the base branch.Example
The same serializer now works with any internal printer variant implementing
PrinterTrait:This is the prerequisite for adding a source-map-generic printer in the final PR without duplicating every
ToCssimplementation.Validation
cargo check --locked --workspace --all-featurescargo test --locked -p rspack-lightningcss --all-features(184 passed)cargo check --locked -p rspack-lightningcss --no-default-features --features visitor --example custom_at_rule --test test_custom_parserStack
by OpenAI Codex