2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2023-01-14 23:18:58 -05:00
|
|
|
use syn::parse::Parse;
|
|
|
|
use syn::parse::ParseStream;
|
|
|
|
use syn::punctuated::Punctuated;
|
|
|
|
use syn::Error;
|
|
|
|
use syn::Ident;
|
|
|
|
use syn::Result;
|
|
|
|
use syn::Token;
|
2022-11-10 06:53:31 -05:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, Default)]
|
|
|
|
pub struct Attributes {
|
|
|
|
pub is_unstable: bool,
|
|
|
|
pub is_v8: bool,
|
|
|
|
pub must_be_fast: bool,
|
|
|
|
pub deferred: bool,
|
2022-11-27 08:54:28 -05:00
|
|
|
pub is_wasm: bool,
|
2022-11-10 06:53:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Parse for Attributes {
|
|
|
|
fn parse(input: ParseStream) -> Result<Self> {
|
|
|
|
let vars = Punctuated::<Ident, Token![,]>::parse_terminated(input)?;
|
|
|
|
|
|
|
|
let vars: Vec<_> = vars.iter().map(Ident::to_string).collect();
|
|
|
|
let vars: Vec<_> = vars.iter().map(String::as_str).collect();
|
|
|
|
for var in vars.iter() {
|
2022-11-27 08:54:28 -05:00
|
|
|
if !["unstable", "v8", "fast", "deferred", "wasm"].contains(var) {
|
2022-11-10 06:53:31 -05:00
|
|
|
return Err(Error::new(
|
|
|
|
input.span(),
|
2022-11-27 08:54:28 -05:00
|
|
|
"invalid attribute, expected one of: unstable, v8, fast, deferred, wasm",
|
2022-11-10 06:53:31 -05:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 08:54:28 -05:00
|
|
|
|
|
|
|
let is_wasm = vars.contains(&"wasm");
|
|
|
|
|
2022-11-10 06:53:31 -05:00
|
|
|
Ok(Self {
|
|
|
|
is_unstable: vars.contains(&"unstable"),
|
|
|
|
is_v8: vars.contains(&"v8"),
|
|
|
|
deferred: vars.contains(&"deferred"),
|
2022-11-27 08:54:28 -05:00
|
|
|
must_be_fast: is_wasm || vars.contains(&"fast"),
|
|
|
|
is_wasm,
|
2022-11-10 06:53:31 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|