Skip to content
Open
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: 6 additions & 2 deletions crates/ast_node/src/encoding/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
syn::parse_quote! { #ident ( #(#names),* ) }
};

let count = data.fields.len();
let count = data
.fields
.iter()
.filter(|field| !is_ignore(&field.attrs))
.count();
let head: Option<syn::Stmt> = (count != 1).then(|| {
syn::parse_quote! {
let len = <cbor4ii::core::types::Array<()>>::len(reader)?.unwrap();
Expand Down Expand Up @@ -193,7 +197,7 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
}
})
.collect::<Vec<_>>();
let count = field.fields.len();
let count = names.len();

let stmt = field.fields.iter()
.zip(names.iter())
Expand Down
5 changes: 3 additions & 2 deletions crates/ast_node/src/encoding/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
cbor4ii::core::enc::Encode::encode(&#fieldpath, writer)?;
},
}
});
let count = data.fields.len();
})
.collect::<Vec<_>>();
let count = fields.len();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a changeset for the breaking encoding format

When this is released, this line changes the wire format for any derived struct with #[encoding(ignore)] fields, for example a struct with one serialized field now emits the field bare instead of an array. The commit also marks this as a breaking change, but there is no .changeset entry; tools/swc-releaser returns without bumping anything when the changeset is empty, so ast_node/exposed downstream crates could ship incompatible Encode/Decode behavior under the old versions.

Useful? React with 👍 / 👎.

let head: Option<syn::Stmt> = (count != 1).then(|| {
syn::parse_quote! {
<cbor4ii::core::types::Array<()>>::bounded(#count, writer)?;
Expand Down
Loading