summaryrefslogtreecommitdiff
path: root/ops/lib.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2022-06-16 19:40:26 +0200
committerGitHub <noreply@github.com>2022-06-16 19:40:26 +0200
commitfa6274cffe43a35fa14a0de75a4614e19d2d3013 (patch)
tree96c3af172ef33e3fd84c8e2b9f78636969925d01 /ops/lib.rs
parent231b8fe27a63e3011c94bff7c2169b7ebd1612a5 (diff)
cleanup(ops): match variations with regexes (#14888)
Diffstat (limited to 'ops/lib.rs')
-rw-r--r--ops/lib.rs25
1 files changed, 14 insertions, 11 deletions
diff --git a/ops/lib.rs b/ops/lib.rs
index f5af772fe..44ea1c677 100644
--- a/ops/lib.rs
+++ b/ops/lib.rs
@@ -1,4 +1,5 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+use once_cell::sync::Lazy;
use proc_macro::TokenStream;
use proc_macro2::Span;
use proc_macro2::TokenStream as TokenStream2;
@@ -6,6 +7,7 @@ use proc_macro_crate::crate_name;
use proc_macro_crate::FoundCrate;
use quote::quote;
use quote::ToTokens;
+use regex::Regex;
use syn::punctuated::Punctuated;
use syn::token::Comma;
use syn::FnArg;
@@ -412,23 +414,24 @@ fn is_unit_result(ty: impl ToTokens) -> bool {
}
fn is_mut_ref_opstate(arg: &syn::FnArg) -> bool {
- tokens(arg).ends_with(": & mut OpState")
- || tokens(arg).ends_with(": & mut deno_core :: OpState")
- || tokens(arg).ends_with("mut OpState")
+ static RE: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r#": & mut (?:deno_core :: )?OpState$"#).unwrap());
+ RE.is_match(&tokens(arg))
}
fn is_rc_refcell_opstate(arg: &syn::FnArg) -> bool {
- tokens(arg).ends_with(": Rc < RefCell < OpState > >")
- || tokens(arg).ends_with(": Rc < RefCell < deno_core :: OpState > >")
+ static RE: Lazy<Regex> = Lazy::new(|| {
+ Regex::new(r#": Rc < RefCell < (?:deno_core :: )?OpState > >$"#).unwrap()
+ });
+ RE.is_match(&tokens(arg))
}
fn is_handle_scope(arg: &syn::FnArg) -> bool {
- tokens(arg).ends_with(": & mut v8 :: HandleScope")
- || tokens(arg).ends_with(": & mut v8 :: HandleScope < 'a >")
- || tokens(arg).ends_with(": & mut deno_core :: v8 :: HandleScope")
- || tokens(arg).ends_with(": & mut deno_core :: v8 :: HandleScope < 'a >")
- || tokens(arg).contains("mut v8 :: HandleScope")
- || tokens(arg).ends_with(": & mut v8 :: HandeScope < 'scope >")
+ static RE: Lazy<Regex> = Lazy::new(|| {
+ Regex::new(r#": & mut (?:deno_core :: )?v8 :: HandleScope(?: < '\w+ >)?$"#)
+ .unwrap()
+ });
+ RE.is_match(&tokens(arg))
}
fn is_future(ty: impl ToTokens) -> bool {