fix(napi-derive): proc-macro crash on enum (#1870)

This commit is contained in:
LongYinan 2023-12-27 21:18:02 +08:00 committed by GitHub
parent 85807ad790
commit 84f3092d70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 14 deletions

View file

@ -273,10 +273,12 @@ fn extract_doc_comments(attrs: &[syn::Attribute]) -> Vec<String> {
.filter_map(|a| { .filter_map(|a| {
// if the path segments include an ident of "doc" we know this // if the path segments include an ident of "doc" we know this
// this is a doc comment // this is a doc comment
let name_value = a.meta.require_name_value();
if let Ok(name) = name_value {
if a.path().is_ident("doc") { if a.path().is_ident("doc") {
Some( Some(
// We want to filter out any Puncts so just grab the Literals // We want to filter out any Puncts so just grab the Literals
match &a.meta.require_name_value().unwrap().value { match &name.value {
syn::Expr::Lit(ExprLit { syn::Expr::Lit(ExprLit {
lit: syn::Lit::Str(str), lit: syn::Lit::Str(str),
.. ..
@ -290,6 +292,9 @@ fn extract_doc_comments(attrs: &[syn::Attribute]) -> Vec<String> {
} else { } else {
None None
} }
} else {
None
}
}) })
//Fold up the [[String]] iter we created into Vec<String> //Fold up the [[String]] iter we created into Vec<String>
.fold(vec![], |mut acc, a| { .fold(vec![], |mut acc, a| {

View file

@ -26,6 +26,7 @@ pub enum CustomNumEnum {
Two, Two,
Three = 3, Three = 3,
Four, Four,
#[doc(hidden)]
Six = 6, Six = 6,
Eight = 8, Eight = 8,
Nine, // would be 9 Nine, // would be 9