Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor #[wasm_bindgen] attribute parsing
This commit moves to having a struct per `syn::Item` type that the macro operates on, then uses `darling` to handle validation of the attribute. This implicitly fixes rustwasm#2874, since `darling` automatically generates errors for unexpected properties. It also makes the macro code easier to follow by hiding the complexity associated with parsing out of sight in a well-tested crate. This also precludes a class of bug where someone might have attempted to read a property that was not accepted for that syntax item, since each syntax item now has its own options receiver. `darling` operates on `syn::Meta`, which only allows a literal to the right side of `=` signs in attributes. This is a problem for wasm_bindgen, which does not use them. To maintain API compatibility while using `darling`, this commit adds `macro_support::meta::Meta<T>`, a replica of `syn::Meta` where `Lit` is replaced by a type parameter. This may be useful enough beyond `wasm_bindgen` for it to move upstream to `darling`, which would mean this change would reduce the overall amount of code in `macro-support`.
- Loading branch information