Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ast): Add archive(check_bytes) to all relevant AST types #9574

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/tough-cooks-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
swc_core: patch
swc_common: patch
swc_ecma_ast: patch
swc_html_ast: patch
---

fix: all struct that support rkyv add `archive(check_bytes)`
6 changes: 6 additions & 0 deletions crates/swc_common/tests/attr_interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ pub struct Tuple(#[span] HasSpan, usize, usize);
archive(bound(serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace"))
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(
feature = "rkyv-impl",
archive_attr(check_bytes(bound = "__C: rkyv::validation::ArchiveContext, <__C as \
rkyv::Fallible>::Error: std::error::Error"))
)]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct HasSpan {
#[cfg_attr(feature = "__rkyv", omit_bounds)]
#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))]
pub span: Span,
}

Expand Down
7 changes: 7 additions & 0 deletions crates/swc_ecma_ast/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,15 +1277,22 @@ impl Take for Import {
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(
feature = "rkyv-impl",
archive_attr(check_bytes(bound = "__C: rkyv::validation::ArchiveContext, <__C as \
rkyv::Fallible>::Error: std::error::Error"))
)]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub struct ExprOrSpread {
#[cfg_attr(feature = "serde-impl", serde(default))]
#[cfg_attr(feature = "__rkyv", omit_bounds)]
#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))]
pub spread: Option<Span>,

#[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
#[cfg_attr(feature = "__rkyv", omit_bounds)]
#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))]
pub expr: Box<Expr>,
}

Expand Down
7 changes: 7 additions & 0 deletions crates/swc_ecma_ast/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ use crate::{typescript::TsTypeAnn, Expr};
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(
feature = "rkyv-impl",
archive_attr(check_bytes(bound = "__C: rkyv::validation::ArchiveContext, <__C as \
rkyv::Fallible>::Error: std::error::Error"))
)]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub struct BindingIdent {
#[cfg_attr(feature = "serde-impl", serde(flatten))]
#[cfg_attr(feature = "__rkyv", omit_bounds)]
#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))]
pub id: Ident,

#[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
#[cfg_attr(feature = "__rkyv", omit_bounds)]
#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))]
pub type_ann: Option<Box<TsTypeAnn>>,
}

Expand Down
2 changes: 2 additions & 0 deletions crates/swc_html_ast/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct DocumentFragment {
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
#[cfg_attr(
feature = "rkyv",
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
Expand Down Expand Up @@ -75,6 +76,7 @@ impl EqIgnoreSpan for DocumentType {
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
#[cfg_attr(
feature = "rkyv",
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_html_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct AttributeToken {
feature = "rkyv",
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
)]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub enum Raw {
Same,
Expand All @@ -44,6 +45,7 @@ pub enum Raw {
feature = "rkyv",
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
)]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub enum Token {
Doctype {
Expand Down
Loading