1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

cleanup(ops): match variations with regexes (#14888)

This commit is contained in:
Aaron O'Mullan 2022-06-16 19:40:26 +02:00 committed by GitHub
parent 231b8fe27a
commit fa6274cffe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 11 deletions

2
Cargo.lock generated
View file

@ -1056,9 +1056,11 @@ dependencies = [
name = "deno_ops" name = "deno_ops"
version = "0.17.0" version = "0.17.0"
dependencies = [ dependencies = [
"once_cell",
"proc-macro-crate", "proc-macro-crate",
"proc-macro2 1.0.38", "proc-macro2 1.0.38",
"quote 1.0.18", "quote 1.0.18",
"regex",
"syn 1.0.93", "syn 1.0.93",
] ]

View file

@ -11,7 +11,9 @@ path = "./lib.rs"
proc-macro = true proc-macro = true
[dependencies] [dependencies]
once_cell = "1.10.0"
proc-macro-crate = "1.1.3" proc-macro-crate = "1.1.3"
proc-macro2 = "1" proc-macro2 = "1"
quote = "1" quote = "1"
regex = "1.5.6"
syn = { version = "1", features = ["full", "extra-traits"] } syn = { version = "1", features = ["full", "extra-traits"] }

View file

@ -1,4 +1,5 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use once_cell::sync::Lazy;
use proc_macro::TokenStream; use proc_macro::TokenStream;
use proc_macro2::Span; use proc_macro2::Span;
use proc_macro2::TokenStream as TokenStream2; use proc_macro2::TokenStream as TokenStream2;
@ -6,6 +7,7 @@ use proc_macro_crate::crate_name;
use proc_macro_crate::FoundCrate; use proc_macro_crate::FoundCrate;
use quote::quote; use quote::quote;
use quote::ToTokens; use quote::ToTokens;
use regex::Regex;
use syn::punctuated::Punctuated; use syn::punctuated::Punctuated;
use syn::token::Comma; use syn::token::Comma;
use syn::FnArg; use syn::FnArg;
@ -412,23 +414,24 @@ fn is_unit_result(ty: impl ToTokens) -> bool {
} }
fn is_mut_ref_opstate(arg: &syn::FnArg) -> bool { fn is_mut_ref_opstate(arg: &syn::FnArg) -> bool {
tokens(arg).ends_with(": & mut OpState") static RE: Lazy<Regex> =
|| tokens(arg).ends_with(": & mut deno_core :: OpState") Lazy::new(|| Regex::new(r#": & mut (?:deno_core :: )?OpState$"#).unwrap());
|| tokens(arg).ends_with("mut OpState") RE.is_match(&tokens(arg))
} }
fn is_rc_refcell_opstate(arg: &syn::FnArg) -> bool { fn is_rc_refcell_opstate(arg: &syn::FnArg) -> bool {
tokens(arg).ends_with(": Rc < RefCell < OpState > >") static RE: Lazy<Regex> = Lazy::new(|| {
|| tokens(arg).ends_with(": Rc < RefCell < deno_core :: OpState > >") Regex::new(r#": Rc < RefCell < (?:deno_core :: )?OpState > >$"#).unwrap()
});
RE.is_match(&tokens(arg))
} }
fn is_handle_scope(arg: &syn::FnArg) -> bool { fn is_handle_scope(arg: &syn::FnArg) -> bool {
tokens(arg).ends_with(": & mut v8 :: HandleScope") static RE: Lazy<Regex> = Lazy::new(|| {
|| tokens(arg).ends_with(": & mut v8 :: HandleScope < 'a >") Regex::new(r#": & mut (?:deno_core :: )?v8 :: HandleScope(?: < '\w+ >)?$"#)
|| tokens(arg).ends_with(": & mut deno_core :: v8 :: HandleScope") .unwrap()
|| tokens(arg).ends_with(": & mut deno_core :: v8 :: HandleScope < 'a >") });
|| tokens(arg).contains("mut v8 :: HandleScope") RE.is_match(&tokens(arg))
|| tokens(arg).ends_with(": & mut v8 :: HandeScope < 'scope >")
} }
fn is_future(ty: impl ToTokens) -> bool { fn is_future(ty: impl ToTokens) -> bool {