mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-26 19:21:35 +00:00
Assert all attributes are used by default
This commit implements a system that will assert that all `#[wasm_bindgen]` attributes are actually used during compilation. This should help ensure that we don't sneak in stray attributes that don't actually end up having any meaning, and hopefully make it a bit easier to learn `#[wasm_bindgen]`!
This commit is contained in:
@ -20,6 +20,7 @@ mod parser;
|
||||
|
||||
/// Takes the parsed input from a `#[wasm_bindgen]` macro and returns the generated bindings
|
||||
pub fn expand(attr: TokenStream, input: TokenStream) -> Result<TokenStream, Diagnostic> {
|
||||
parser::reset_attrs_used();
|
||||
let item = syn::parse2::<syn::Item>(input)?;
|
||||
let opts = syn::parse2(attr)?;
|
||||
|
||||
@ -27,5 +28,11 @@ pub fn expand(attr: TokenStream, input: TokenStream) -> Result<TokenStream, Diag
|
||||
let mut program = backend::ast::Program::default();
|
||||
item.macro_parse(&mut program, (Some(opts), &mut tokens))?;
|
||||
program.try_to_tokens(&mut tokens)?;
|
||||
|
||||
// If we successfully got here then we should have used up all attributes
|
||||
// and considered all of them to see if they were used. If one was forgotten
|
||||
// that's a bug on our end, so sanity check here.
|
||||
parser::assert_all_attrs_checked();
|
||||
|
||||
Ok(tokens)
|
||||
}
|
||||
|
Reference in New Issue
Block a user