Skip to content

Commit

Permalink
Fix WebAssembly serialization for comments field in CDDL AST
Browse files Browse the repository at this point in the history
The `comments` field in the `CDDL` struct was skipped during serialization when compiling for WebAssembly. This was caused by the incorrect use of `#[cfg_attr(target_arch = "wasm32", serde(skip))]`. Instead of skipping the field, we now rely on the `ast-comments` feature flag to control whether the `comments` field is included. If the feature is disabled, the field will be excluded entirely.
  • Loading branch information
mirelon authored Jan 18, 2025
1 parent 83ce7e3 commit ed0d525
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ pub struct CDDL<'a> {
pub rules: Vec<Rule<'a>>,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments: Option<Comments<'a>>,
}
Expand Down Expand Up @@ -312,7 +311,6 @@ pub enum Rule<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_rule: Option<Comments<'a>>,
},
Expand All @@ -325,7 +323,6 @@ pub enum Rule<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_rule: Option<Comments<'a>>,
},
Expand Down Expand Up @@ -475,11 +472,9 @@ pub struct TypeRule<'a> {
pub value: Type<'a>,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_before_assignt: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_after_assignt: Option<Comments<'a>>,
}
Expand Down Expand Up @@ -533,11 +528,9 @@ pub struct GroupRule<'a> {
pub entry: GroupEntry<'a>,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_before_assigng: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_after_assigng: Option<Comments<'a>>,
}
Expand Down Expand Up @@ -595,11 +588,9 @@ pub struct GenericParam<'a> {
pub param: Identifier<'a>,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_before_ident: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_after_ident: Option<Comments<'a>>,
}
Expand Down Expand Up @@ -654,11 +645,9 @@ pub struct GenericArg<'a> {
pub arg: Box<Type1<'a>>,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_before_type: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_after_type: Option<Comments<'a>>,
}
Expand Down Expand Up @@ -763,11 +752,9 @@ pub struct TypeChoice<'a> {
/// Type choice
pub type1: Type1<'a>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_before_type: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_after_type: Option<Comments<'a>>,
}
Expand Down Expand Up @@ -873,7 +860,6 @@ pub struct Type1<'a> {
pub span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_after_type: Option<Comments<'a>>,
}
Expand Down Expand Up @@ -941,11 +927,9 @@ pub struct Operator<'a> {
pub type2: Type2<'a>,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_before_operator: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_after_operator: Option<Comments<'a>>,
}
Expand Down Expand Up @@ -1143,11 +1127,9 @@ pub enum Type2<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_before_type: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_type: Option<Comments<'a>>,
},
Expand All @@ -1161,11 +1143,9 @@ pub enum Type2<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_before_group: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_group: Option<Comments<'a>>,
},
Expand All @@ -1179,11 +1159,9 @@ pub enum Type2<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_before_group: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_group: Option<Comments<'a>>,
},
Expand All @@ -1199,7 +1177,6 @@ pub enum Type2<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments: Option<Comments<'a>>,
},
Expand All @@ -1213,15 +1190,12 @@ pub enum Type2<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_before_group: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_group: Option<Comments<'a>>,
},
Expand All @@ -1237,7 +1211,6 @@ pub enum Type2<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments: Option<Comments<'a>>,
},
Expand All @@ -1254,11 +1227,9 @@ pub enum Type2<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_before_type: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_type: Option<Comments<'a>>,
},
Expand Down Expand Up @@ -2031,7 +2002,6 @@ pub struct GroupChoice<'a> {
// No trailing comments since these will be captured by the S ["," S] matching
// rule
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments_before_grpchoice: Option<Comments<'a>>,
}
Expand Down Expand Up @@ -2273,11 +2243,9 @@ pub enum GroupEntry<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
leading_comments: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
trailing_comments: Option<Comments<'a>>,
},
Expand All @@ -2292,11 +2260,9 @@ pub enum GroupEntry<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
leading_comments: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
trailing_comments: Option<Comments<'a>>,
},
Expand All @@ -2312,11 +2278,9 @@ pub enum GroupEntry<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_before_group: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_group: Option<Comments<'a>>,
},
Expand Down Expand Up @@ -2346,7 +2310,6 @@ pub struct OptionalComma<'a> {
pub optional_comma: bool,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub trailing_comments: Option<Comments<'a>>,

Expand Down Expand Up @@ -2540,7 +2503,6 @@ pub struct Occurrence<'a> {
pub occur: Occur,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
pub comments: Option<Comments<'a>>,

Expand Down Expand Up @@ -2652,15 +2614,12 @@ pub enum MemberKey<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_before_cut: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_cut: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_arrowmap: Option<Comments<'a>>,
},
Expand All @@ -2675,11 +2634,9 @@ pub enum MemberKey<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_colon: Option<Comments<'a>>,
},
Expand All @@ -2694,16 +2651,13 @@ pub enum MemberKey<'a> {
span: Span,

#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments: Option<Comments<'a>>,
#[cfg(feature = "ast-comments")]
#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
comments_after_colon: Option<Comments<'a>>,
},

#[cfg_attr(target_arch = "wasm32", serde(skip))]
#[doc(hidden)]
NonMemberKey {
non_member_key: NonMemberKey<'a>,
Expand Down

0 comments on commit ed0d525

Please sign in to comment.