Repository: napi-rs/napi-rs
File: crates/backend/src/codegen/fn.rs (Rust)

Code before:
        if let syn::Type::Path(path) = &ty {
          // Detect cases where the type is `Vec<&S>`.
          // For example, in `async fn foo(v: Vec<&S>) {}`, we need to handle `v` as a reference.
          if let Some(syn::PathSegment { ident, arguments }) = path.path.segments.first() {
            // Check if the type is a `Vec`.
            if ident == "Vec" {
              is_array = true;
              if let syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
                args: angle_bracketed_args,
                ..
              }) = &arguments
              {
                // Check if the generic argument of `Vec` is a reference type (e.g., `&S`).
                if let Some(syn::GenericArgument::Type(syn::Type::Reference(
                  syn::TypeReference { .. },
                ))) = angle_bracketed_args.first()
                {
                  // If the type is `Vec<&S>`, set the argument type to `Ref`.
                  arg_type = NapiArgType::Ref;
                }
              }
            }
          }
        }
        // Array::validate only validate by the `Array.isArray`
        // For the elements of the Array, we need to return rather than throw if it's invalid when `return_if_invalid` is true
        let from_napi_value = if is_array && self.return_if_invalid {
          quote! {
            match <#ty as napi::bindgen_prelude::FromNapiValue>::from_napi_value(env, #arg_conversion) {
              Ok(value) => value,
              Err(err) => {
                // InvalidArg, ObjectExpected, StringExpected ...
                if err.status < napi::bindgen_prelude::Status::GenericFailure {
                  return Ok(std::ptr::null_mut());
                } else {
                  return Err(err);
                }
              }
            }
          }
        } else {
          quote! {
            <#ty as napi::bindgen_prelude::FromNapiValue>::from_napi_value(env, #arg_conversion)?
          }
        };
        let q = quote! {
          let #arg_name = {
            #type_check
            #from_napi_value
          };
        };

Review comment (suggestion):
The comment has a grammatical error. It should be "For the elements of the Array, we need to return rather than throw if they are invalid when `return_if_invalid` is true" (changing 'it's' to 'they are' for proper subject-verb agreement).
```suggestion
        // For the elements of the Array, we need to return rather than throw if they are invalid when `return_if_invalid` is true
```

Code after:
        if let syn::Type::Path(path) = &ty {
          // Detect cases where the type is `Vec<&S>`.
          // For example, in `async fn foo(v: Vec<&S>) {}`, we need to handle `v` as a reference.
          if let Some(syn::PathSegment { ident, arguments }) = path.path.segments.first() {
            // Check if the type is a `Vec`.
            if ident == "Vec" {
              is_array = true;
              if let syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
                args: angle_bracketed_args,
                ..
              }) = &arguments
              {
                // Check if the generic argument of `Vec` is a reference type (e.g., `&S`).
                if let Some(syn::GenericArgument::Type(syn::Type::Reference(
                  syn::TypeReference { .. },
                ))) = angle_bracketed_args.first()
                {
                  // If the type is `Vec<&S>`, set the argument type to `Ref`.
                  arg_type = NapiArgType::Ref;
                }
              }
            }
          }
        }
        // Array::validate only validates by the `Array.isArray`
        // For the elements of the Array, we need to return rather than throw if they are invalid when `return_if_invalid` is true
        let from_napi_value = if is_array && self.return_if_invalid {
          quote! {
            match <#ty as napi::bindgen_prelude::FromNapiValue>::from_napi_value(env, #arg_conversion) {
              Ok(value) => value,
              Err(err) => {
                // InvalidArg, ObjectExpected, StringExpected ...
                if err.status < napi::bindgen_prelude::Status::GenericFailure {
                  return Ok(std::ptr::null_mut());
                } else {
                  return Err(err);
                }
              }
            }
          }
        } else {
          quote! {
            <#ty as napi::bindgen_prelude::FromNapiValue>::from_napi_value(env, #arg_conversion)?
          }
        };
        let q = quote! {
          let #arg_name = {
            #type_check
            #from_napi_value
          };
        };