Skip to content

Commit 185d6f5

Browse files
authored
fix(ast): Add archive(check_bytes) to all relevant AST types (#9574)
**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
1 parent 04016e9 commit 185d6f5

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

.changeset/tough-cooks-stare.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
swc_core: patch
3+
swc_common: patch
4+
swc_ecma_ast: patch
5+
swc_html_ast: patch
6+
---
7+
8+
fix: all struct that support rkyv add `archive(check_bytes)`

crates/swc_common/tests/attr_interop.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ pub struct Tuple(#[span] HasSpan, usize, usize);
2323
archive(bound(serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace"))
2424
)]
2525
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
26+
#[cfg_attr(
27+
feature = "rkyv-impl",
28+
archive_attr(check_bytes(bound = "__C: rkyv::validation::ArchiveContext, <__C as \
29+
rkyv::Fallible>::Error: std::error::Error"))
30+
)]
2631
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
2732
pub struct HasSpan {
2833
#[cfg_attr(feature = "__rkyv", omit_bounds)]
34+
#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))]
2935
pub span: Span,
3036
}
3137

crates/swc_ecma_ast/src/expr.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,15 +1277,22 @@ impl Take for Import {
12771277
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
12781278
)]
12791279
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
1280+
#[cfg_attr(
1281+
feature = "rkyv-impl",
1282+
archive_attr(check_bytes(bound = "__C: rkyv::validation::ArchiveContext, <__C as \
1283+
rkyv::Fallible>::Error: std::error::Error"))
1284+
)]
12801285
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
12811286
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
12821287
pub struct ExprOrSpread {
12831288
#[cfg_attr(feature = "serde-impl", serde(default))]
12841289
#[cfg_attr(feature = "__rkyv", omit_bounds)]
1290+
#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))]
12851291
pub spread: Option<Span>,
12861292

12871293
#[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
12881294
#[cfg_attr(feature = "__rkyv", omit_bounds)]
1295+
#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))]
12891296
pub expr: Box<Expr>,
12901297
}
12911298

crates/swc_ecma_ast/src/ident.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,22 @@ use crate::{typescript::TsTypeAnn, Expr};
2424
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
2525
)]
2626
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
27+
#[cfg_attr(
28+
feature = "rkyv-impl",
29+
archive_attr(check_bytes(bound = "__C: rkyv::validation::ArchiveContext, <__C as \
30+
rkyv::Fallible>::Error: std::error::Error"))
31+
)]
2732
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
2833
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
2934
pub struct BindingIdent {
3035
#[cfg_attr(feature = "serde-impl", serde(flatten))]
3136
#[cfg_attr(feature = "__rkyv", omit_bounds)]
37+
#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))]
3238
pub id: Ident,
3339

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

crates/swc_html_ast/src/base.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct DocumentFragment {
2323
feature = "rkyv",
2424
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
2525
)]
26+
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
2627
#[cfg_attr(
2728
feature = "rkyv",
2829
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
@@ -75,6 +76,7 @@ impl EqIgnoreSpan for DocumentType {
7576
feature = "rkyv",
7677
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
7778
)]
79+
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
7880
#[cfg_attr(
7981
feature = "rkyv",
8082
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))

crates/swc_html_ast/src/token.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct AttributeToken {
2929
feature = "rkyv",
3030
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
3131
)]
32+
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
3233
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
3334
pub enum Raw {
3435
Same,
@@ -44,6 +45,7 @@ pub enum Raw {
4445
feature = "rkyv",
4546
archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))
4647
)]
48+
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
4749
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
4850
pub enum Token {
4951
Doctype {

0 commit comments

Comments
 (0)