Browse Source

only add public enums to the IDL (#2310)

Co-authored-by: henrye <henry@notanemail>
Henry-E 2 years ago
parent
commit
03eff348db
2 changed files with 9 additions and 3 deletions
  1. 1 0
      CHANGELOG.md
  2. 8 3
      lang/syn/src/idl/file.rs

+ 1 - 0
CHANGELOG.md

@@ -46,6 +46,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 - lang: Prevent the payer account from being initialized as a program account ([#2284](https://github.com/coral-xyz/anchor/pull/2284)).
 - ts: Fixing breaking change where null or undefined wallet throws an error ([#2303](https://github.com/coral-xyz/anchor/pull/2303)).
 - ts: Fixed `.fetchNullable()` to be robust towards accounts only holding a balance ([#2301](https://github.com/coral-xyz/anchor/pull/2301)).
+- lang: Only add public enums to the IDL ([#2309](https://github.com/coral-xyz/anchor/pull/2309)).
 
 ### Breaking
 

+ 8 - 3
lang/syn/src/idl/file.rs

@@ -484,7 +484,12 @@ fn parse_ty_defs(ctx: &CrateContext, no_docs: bool) -> Result<Vec<IdlTypeDefinit
                 ty: IdlTypeDefinitionTy::Struct { fields },
             }))
         })
-        .chain(ctx.enums().map(|enm| {
+        .chain(ctx.enums().filter_map(|enm| {
+            // Only take public types
+            match &enm.vis {
+                syn::Visibility::Public(_) => (),
+                _ => return None,
+            }
             let name = enm.ident.to_string();
             let doc = if !no_docs {
                 docs::parse(&enm.attrs)
@@ -531,11 +536,11 @@ fn parse_ty_defs(ctx: &CrateContext, no_docs: bool) -> Result<Vec<IdlTypeDefinit
                     IdlEnumVariant { name, fields }
                 })
                 .collect::<Vec<IdlEnumVariant>>();
-            Ok(IdlTypeDefinition {
+            Some(Ok(IdlTypeDefinition {
                 name,
                 docs: doc,
                 ty: IdlTypeDefinitionTy::Enum { variants },
-            })
+            }))
         }))
         .collect()
 }