mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor(cli,ext,ops): cleanup regex
with lazy-regex
(#17296)
- bump deps: the newest `lazy-regex` need newer `oncecell` and `regex` - reduce `unwrap` - remove dep `lazy_static` - make more regex cached --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
19c3e4f6dc
commit
d790ea7d53
23 changed files with 96 additions and 91 deletions
|
@ -53,7 +53,7 @@ static PREFERRED_FIXES: Lazy<HashMap<&'static str, (u32, bool)>> =
|
|||
});
|
||||
|
||||
static IMPORT_SPECIFIER_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r#"\sfrom\s+["']([^"']*)["']"#).unwrap());
|
||||
lazy_regex::lazy_regex!(r#"\sfrom\s+["']([^"']*)["']"#);
|
||||
|
||||
const SUPPORTED_EXTENSIONS: &[&str] = &[".ts", ".tsx", ".js", ".jsx", ".mjs"];
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ use deno_core::serde::Serialize;
|
|||
use deno_core::serde_json;
|
||||
use deno_core::serde_json::json;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use lazy_regex::lazy_regex;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::cell::RefCell;
|
||||
|
@ -29,11 +30,9 @@ use std::rc::Rc;
|
|||
use std::sync::Arc;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
static ABSTRACT_MODIFIER: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"\babstract\b").unwrap());
|
||||
static ABSTRACT_MODIFIER: Lazy<Regex> = lazy_regex!(r"\babstract\b");
|
||||
|
||||
static EXPORT_MODIFIER: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"\bexport\b").unwrap());
|
||||
static EXPORT_MODIFIER: Lazy<Regex> = lazy_regex!(r"\bexport\b");
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum CodeLensSource {
|
||||
|
|
|
@ -28,7 +28,7 @@ use std::sync::Arc;
|
|||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
static FILE_PROTO_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r#"^file:/{2}(?:/[A-Za-z]:)?"#).unwrap());
|
||||
lazy_regex::lazy_regex!(r#"^file:/{2}(?:/[A-Za-z]:)?"#);
|
||||
|
||||
const CURRENT_PATH: &str = ".";
|
||||
const PARENT_PATH: &str = "..";
|
||||
|
|
|
@ -37,7 +37,7 @@ use std::fmt::Write as _;
|
|||
use std::iter::Peekable;
|
||||
|
||||
static ESCAPE_STRING_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"([.+*?=^!:${}()\[\]|/\\])").unwrap());
|
||||
lazy_regex::lazy_regex!(r"([.+*?=^!:${}()\[\]|/\\])");
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum TokenType {
|
||||
|
|
|
@ -33,7 +33,6 @@ use deno_runtime::deno_web::BlobStore;
|
|||
use deno_runtime::permissions::PermissionsContainer;
|
||||
use log::error;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use tower_lsp::lsp_types as lsp;
|
||||
|
@ -66,8 +65,8 @@ const COMPONENT: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS
|
|||
|
||||
const REGISTRY_IMPORT_COMMIT_CHARS: &[&str] = &["\"", "'", "/"];
|
||||
|
||||
static REPLACEMENT_VARIABLE_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"\$\{\{?(\w+)\}?\}").unwrap());
|
||||
static REPLACEMENT_VARIABLE_RE: Lazy<regex::Regex> =
|
||||
lazy_regex::lazy_regex!(r"\$\{\{?(\w+)\}?\}");
|
||||
|
||||
fn base_url(url: &Url) -> String {
|
||||
url.origin().ascii_serialization()
|
||||
|
|
|
@ -44,6 +44,7 @@ use deno_core::ModuleSpecifier;
|
|||
use deno_core::OpState;
|
||||
use deno_core::RuntimeOptions;
|
||||
use deno_runtime::tokio_util::create_basic_runtime;
|
||||
use lazy_regex::lazy_regex;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Captures;
|
||||
use regex::Regex;
|
||||
|
@ -65,24 +66,18 @@ use tower_lsp::jsonrpc::Result as LspResult;
|
|||
use tower_lsp::lsp_types as lsp;
|
||||
|
||||
static BRACKET_ACCESSOR_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r#"^\[['"](.+)[\['"]\]$"#).unwrap());
|
||||
static CAPTION_RE: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(r"<caption>(.*?)</caption>\s*\r?\n((?:\s|\S)*)").unwrap()
|
||||
});
|
||||
static CODEBLOCK_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^\s*[~`]{3}").unwrap());
|
||||
static EMAIL_MATCH_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"(.+)\s<([-.\w]+@[-.\w]+)>").unwrap());
|
||||
static HTTP_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r#"(?i)^https?:"#).unwrap());
|
||||
static JSDOC_LINKS_RE: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(r"(?i)\{@(link|linkplain|linkcode) (https?://[^ |}]+?)(?:[| ]([^{}\n]+?))?\}").unwrap()
|
||||
});
|
||||
static PART_KIND_MODIFIER_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r",|\s+").unwrap());
|
||||
static PART_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^(\S+)\s*-?\s*").unwrap());
|
||||
static SCOPE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"scope_(\d)").unwrap());
|
||||
lazy_regex!(r#"^\[['"](.+)[\['"]\]$"#);
|
||||
static CAPTION_RE: Lazy<Regex> =
|
||||
lazy_regex!(r"<caption>(.*?)</caption>\s*\r?\n((?:\s|\S)*)");
|
||||
static CODEBLOCK_RE: Lazy<Regex> = lazy_regex!(r"^\s*[~`]{3}");
|
||||
static EMAIL_MATCH_RE: Lazy<Regex> = lazy_regex!(r"(.+)\s<([-.\w]+@[-.\w]+)>");
|
||||
static HTTP_RE: Lazy<Regex> = lazy_regex!(r#"(?i)^https?:"#);
|
||||
static JSDOC_LINKS_RE: Lazy<Regex> = lazy_regex!(
|
||||
r"(?i)\{@(link|linkplain|linkcode) (https?://[^ |}]+?)(?:[| ]([^{}\n]+?))?\}"
|
||||
);
|
||||
static PART_KIND_MODIFIER_RE: Lazy<Regex> = lazy_regex!(r",|\s+");
|
||||
static PART_RE: Lazy<Regex> = lazy_regex!(r"^(\S+)\s*-?\s*");
|
||||
static SCOPE_RE: Lazy<Regex> = lazy_regex!(r"scope_(\d)");
|
||||
|
||||
const FILE_EXTENSION_KIND_MODIFIERS: &[&str] =
|
||||
&[".d.ts", ".ts", ".tsx", ".js", ".jsx", ".json"];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue