Skip to content

Commit

Permalink
Fixed a critical issue
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaticWyrm467 committed Oct 31, 2024
1 parent f409f55 commit 6f3a866
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_tree_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node_tree_derive"
version = "0.6.0"
version = "0.6.1"
edition = "2018"

exclude = [
Expand Down
26 changes: 16 additions & 10 deletions node_tree_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ struct Signal {

struct Const {
attribs: Vec<syn::Attribute>,
public: bool,
declare: syn::ItemConst
}

Expand All @@ -337,6 +338,7 @@ struct Hook {

struct Func {
attribs: Vec<syn::Attribute>,
public: bool,
declare: syn::ItemFn
}

Expand Down Expand Up @@ -376,10 +378,17 @@ impl Parse for Class {
// Parse any item attributes.
let item_attribs: Vec<syn::Attribute> = input.call(syn::Attribute::parse_outer)?;

// Check if the following statement is publicly visible:
let mut is_public: Option<tok::Pub> = None;
if input.peek(Token![pub]) {
is_public = Some(input.parse::<tok::Pub>()?);
}

// Parse a constant:
if input.peek(Token![const]) {
consts.push(Const {
attribs: item_attribs,
public: is_public.is_some(),
declare: input.parse()?
});
}
Expand All @@ -388,19 +397,14 @@ impl Parse for Class {
else if input.peek(Token![fn]) {
funcs.push(Func {
attribs: item_attribs,
public: is_public.is_some(),
declare: input.parse()?
});
}

// Parse a custom statement:
else {

// Check if the following statement is publicly visible:
let mut is_public: Option<tok::Pub> = None;
if input.peek(Token![pub]) {
is_public = Some(input.parse::<tok::Pub>()?);
}

// Parse a let statement:
if input.peek(Token![let]) {
input.parse::<tok::Let>()?;
Expand Down Expand Up @@ -581,10 +585,11 @@ pub fn class(input: TokenStream) -> TokenStream {
let visibility: TokenStream2 = if public { quote! { pub } } else { TokenStream2::new() };

// Generate the constant fields.
let const_fields = consts.iter().map(|Const { attribs, declare }| {
let const_fields = consts.iter().map(|Const { attribs, public, declare }| {
let visibility: TokenStream2 = if *public { quote! { pub } } else { TokenStream2::new() };
quote! {
#(#attribs)*
#declare
#visibility #declare
}
});

Expand Down Expand Up @@ -677,10 +682,11 @@ pub fn class(input: TokenStream) -> TokenStream {
});

// Generate the functions.
let func_impls = funcs.iter().map(|Func { attribs, declare }| {
let func_impls = funcs.iter().map(|Func { attribs, public, declare }| {
let visibility: TokenStream2 = if *public { quote! { pub } } else { TokenStream2::new() };
quote! {
#(#attribs)*
#declare
#visibility #declare
}
});

Expand Down

0 comments on commit 6f3a866

Please sign in to comment.