Skip to content

Commit

Permalink
fix(ast): Add archive(check_bytes) to all relevant AST types (#9574)
Browse files Browse the repository at this point in the history
**Description:**

1. all struct that support rkyv add `archive(check_bytes)`
2. all recursive struct that support rkyv add check_bytes bound

this PR will fix the error reported in #9562
  • Loading branch information
jerrykingxyz authored Sep 20, 2024
1 parent 04016e9 commit 185d6f5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
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

0 comments on commit 185d6f5

Please sign in to comment.