summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/Cargo.toml3
-rw-r--r--cli/compat/mod.rs31
-rw-r--r--cli/diagnostics.rs15
-rw-r--r--cli/flags.rs9
-rw-r--r--cli/lsp/analysis.rs84
-rw-r--r--cli/lsp/code_lens.rs10
-rw-r--r--cli/lsp/documents.rs48
-rw-r--r--cli/lsp/path_to_regex.rs7
-rw-r--r--cli/lsp/refactor.rs167
-rw-r--r--cli/lsp/registries.rs7
-rw-r--r--cli/lsp/tsc.rs28
-rw-r--r--cli/lsp/urls.rs10
-rw-r--r--cli/tools/installer.rs21
-rw-r--r--cli/tools/upgrade.rs6
-rw-r--r--cli/tsc.rs57
15 files changed, 311 insertions, 192 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 096628ce7..4a9e31056 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -62,13 +62,12 @@ fancy-regex = "=0.7.1"
http = "=0.2.4"
import_map = "=0.4.0"
jsonc-parser = { version = "=0.17.0", features = ["serde"] }
-lazy_static = "=1.4.0"
libc = "=0.2.106"
log = { version = "=0.4.14", features = ["serde"] }
lspower = "=1.4.0"
notify = "=5.0.0-pre.12"
num_cpus = "=1.13.0"
-once_cell = "=1.8.0"
+once_cell = "=1.9.0"
percent-encoding = "=2.1.0"
pin-project = "=1.0.8"
rand = { version = "=0.8.4", features = ["small_rng"] }
diff --git a/cli/compat/mod.rs b/cli/compat/mod.rs
index 54f8b5fde..14e168764 100644
--- a/cli/compat/mod.rs
+++ b/cli/compat/mod.rs
@@ -7,6 +7,7 @@ use deno_core::error::AnyError;
use deno_core::located_script_name;
use deno_core::url::Url;
use deno_core::JsRuntime;
+use once_cell::sync::Lazy;
pub use esm_resolver::check_if_should_use_esm_loader;
pub(crate) use esm_resolver::NodeEsmResolver;
@@ -62,15 +63,27 @@ static SUPPORTED_MODULES: &[&str] = &[
"zlib",
];
-lazy_static::lazy_static! {
- static ref NODE_COMPAT_URL: String = std::env::var("DENO_NODE_COMPAT_URL").map(String::into).ok()
- .unwrap_or_else(|| STD_URL_STR.to_string());
- static ref GLOBAL_URL_STR: String = format!("{}node/global.ts", NODE_COMPAT_URL.as_str());
- pub(crate) static ref GLOBAL_URL: Url = Url::parse(&GLOBAL_URL_STR).unwrap();
- static ref MODULE_URL_STR: String = format!("{}node/module.ts", NODE_COMPAT_URL.as_str());
- pub(crate) static ref MODULE_URL: Url = Url::parse(&MODULE_URL_STR).unwrap();
- static ref COMPAT_IMPORT_URL: Url = Url::parse("flags:compat").unwrap();
-}
+static NODE_COMPAT_URL: Lazy<String> = Lazy::new(|| {
+ std::env::var("DENO_NODE_COMPAT_URL")
+ .map(String::into)
+ .ok()
+ .unwrap_or_else(|| STD_URL_STR.to_string())
+});
+
+static GLOBAL_URL_STR: Lazy<String> =
+ Lazy::new(|| format!("{}node/global.ts", NODE_COMPAT_URL.as_str()));
+
+pub(crate) static GLOBAL_URL: Lazy<Url> =
+ Lazy::new(|| Url::parse(&GLOBAL_URL_STR).unwrap());
+
+static MODULE_URL_STR: Lazy<String> =
+ Lazy::new(|| format!("{}node/module.ts", NODE_COMPAT_URL.as_str()));
+
+pub(crate) static MODULE_URL: Lazy<Url> =
+ Lazy::new(|| Url::parse(&MODULE_URL_STR).unwrap());
+
+static COMPAT_IMPORT_URL: Lazy<Url> =
+ Lazy::new(|| Url::parse("flags:compat").unwrap());
/// Provide imports into a module graph when the compat flag is true.
pub(crate) fn get_node_imports() -> Vec<(Url, Vec<String>)> {
diff --git a/cli/diagnostics.rs b/cli/diagnostics.rs
index 0671dc500..03255950b 100644
--- a/cli/diagnostics.rs
+++ b/cli/diagnostics.rs
@@ -7,6 +7,7 @@ use deno_core::serde::Deserializer;
use deno_core::serde::Serialize;
use deno_core::serde::Serializer;
use deno_graph::ModuleGraphError;
+use once_cell::sync::Lazy;
use regex::Regex;
use std::error::Error;
use std::fmt;
@@ -65,13 +66,13 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"utimeSync",
];
-lazy_static::lazy_static! {
- static ref MSG_MISSING_PROPERTY_DENO: Regex =
- Regex::new(r#"Property '([^']+)' does not exist on type 'typeof Deno'"#)
- .unwrap();
- static ref MSG_SUGGESTION: Regex =
- Regex::new(r#" Did you mean '([^']+)'\?"#).unwrap();
-}
+static MSG_MISSING_PROPERTY_DENO: Lazy<Regex> = Lazy::new(|| {
+ Regex::new(r#"Property '([^']+)' does not exist on type 'typeof Deno'"#)
+ .unwrap()
+});
+
+static MSG_SUGGESTION: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r#" Did you mean '([^']+)'\?"#).unwrap());
/// Potentially convert a "raw" diagnostic message from TSC to something that
/// provides a more sensible error message given a Deno runtime context.
diff --git a/cli/flags.rs b/cli/flags.rs
index 452c2fd9a..2cf79d44f 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -12,6 +12,7 @@ use deno_core::url::Url;
use deno_runtime::permissions::PermissionsOptions;
use log::debug;
use log::Level;
+use once_cell::sync::Lazy;
use std::net::SocketAddr;
use std::num::NonZeroU32;
use std::num::NonZeroU8;
@@ -19,8 +20,8 @@ use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::str::FromStr;
-lazy_static::lazy_static! {
- static ref LONG_VERSION: String = format!(
+static LONG_VERSION: Lazy<String> = Lazy::new(|| {
+ format!(
"{} ({}, {})\nv8 {}\ntypescript {}",
crate::version::deno(),
if crate::version::is_canary() {
@@ -31,8 +32,8 @@ lazy_static::lazy_static! {
env!("TARGET"),
deno_core::v8_version(),
crate::version::TYPESCRIPT
- );
-}
+ )
+});
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct BundleFlags {
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs
index d21abae87..560a84603 100644
--- a/cli/lsp/analysis.rs
+++ b/cli/lsp/analysis.rs
@@ -18,52 +18,58 @@ use deno_core::ModuleSpecifier;
use lspower::lsp;
use lspower::lsp::Position;
use lspower::lsp::Range;
+use once_cell::sync::Lazy;
use regex::Regex;
use std::cmp::Ordering;
use std::collections::HashMap;
-lazy_static::lazy_static! {
- /// Diagnostic error codes which actually are the same, and so when grouping
- /// fixes we treat them the same.
- static ref FIX_ALL_ERROR_CODES: HashMap<&'static str, &'static str> =
- (&[("2339", "2339"), ("2345", "2339"),])
+/// Diagnostic error codes which actually are the same, and so when grouping
+/// fixes we treat them the same.
+static FIX_ALL_ERROR_CODES: Lazy<HashMap<&'static str, &'static str>> =
+ Lazy::new(|| {
+ (&[("2339", "2339"), ("2345", "2339")])
.iter()
.cloned()
- .collect();
-
- /// Fixes which help determine if there is a preferred fix when there are
- /// multiple fixes available.
- static ref PREFERRED_FIXES: HashMap<&'static str, (u32, bool)> = (&[
- ("annotateWithTypeFromJSDoc", (1, false)),
- ("constructorForDerivedNeedSuperCall", (1, false)),
- ("extendsInterfaceBecomesImplements", (1, false)),
- ("awaitInSyncFunction", (1, false)),
- ("classIncorrectlyImplementsInterface", (3, false)),
- ("classDoesntImplementInheritedAbstractMember", (3, false)),
- ("unreachableCode", (1, false)),
- ("unusedIdentifier", (1, false)),
- ("forgottenThisPropertyAccess", (1, false)),
- ("spelling", (2, false)),
- ("addMissingAwait", (1, false)),
- ("fixImport", (0, true)),
- ])
- .iter()
- .cloned()
- .collect();
-
- static ref IMPORT_SPECIFIER_RE: Regex = Regex::new(r#"\sfrom\s+["']([^"']*)["']"#).unwrap();
-
- static ref DENO_TYPES_RE: Regex =
- Regex::new(r#"(?i)^\s*@deno-types\s*=\s*(?:["']([^"']+)["']|(\S+))"#)
- .unwrap();
- static ref TRIPLE_SLASH_REFERENCE_RE: Regex =
- Regex::new(r"(?i)^/\s*<reference\s.*?/>").unwrap();
- static ref PATH_REFERENCE_RE: Regex =
- Regex::new(r#"(?i)\spath\s*=\s*["']([^"']*)["']"#).unwrap();
- static ref TYPES_REFERENCE_RE: Regex =
- Regex::new(r#"(?i)\stypes\s*=\s*["']([^"']*)["']"#).unwrap();
+ .collect()
+ });
+
+/// Fixes which help determine if there is a preferred fix when there are
+/// multiple fixes available.
+static PREFERRED_FIXES: Lazy<HashMap<&'static str, (u32, bool)>> =
+ Lazy::new(|| {
+ (&[
+ ("annotateWithTypeFromJSDoc", (1, false)),
+ ("constructorForDerivedNeedSuperCall", (1, false)),
+ ("extendsInterfaceBecomesImplements", (1, false)),
+ ("awaitInSyncFunction", (1, false)),
+ ("classIncorrectlyImplementsInterface", (3, false)),
+ ("classDoesntImplementInheritedAbstractMember", (3, false)),
+ ("unreachableCode", (1, false)),
+ ("unusedIdentifier", (1, false)),
+ ("forgottenThisPropertyAccess", (1, false)),
+ ("spelling", (2, false)),
+ ("addMissingAwait", (1, false)),
+ ("fixImport", (0, true)),
+ ])
+ .iter()
+ .cloned()
+ .collect()
+ });
-}
+static IMPORT_SPECIFIER_RE: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r#"\sfrom\s+["']([^"']*)["']"#).unwrap());
+
+static DENO_TYPES_RE: Lazy<Regex> = Lazy::new(|| {
+ Regex::new(r#"(?i)^\s*@deno-types\s*=\s*(?:["']([^"']+)["']|(\S+))"#).unwrap()
+});
+
+static TRIPLE_SLASH_REFERENCE_RE: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r"(?i)^/\s*<reference\s.*?/>").unwrap());
+
+static PATH_REFERENCE_RE: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r#"(?i)\spath\s*=\s*["']([^"']*)["']"#).unwrap());
+static TYPES_REFERENCE_RE: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r#"(?i)\stypes\s*=\s*["']([^"']*)["']"#).unwrap());
const SUPPORTED_EXTENSIONS: &[&str] = &[".ts", ".tsx", ".js", ".jsx", ".mjs"];
diff --git a/cli/lsp/code_lens.rs b/cli/lsp/code_lens.rs
index 852f286ab..635f34916 100644
--- a/cli/lsp/code_lens.rs
+++ b/cli/lsp/code_lens.rs
@@ -20,16 +20,18 @@ use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::ModuleSpecifier;
use lspower::lsp;
+use once_cell::sync::Lazy;
use regex::Regex;
use std::cell::RefCell;
use std::collections::HashSet;
use std::rc::Rc;
use std::sync::Arc;
-lazy_static::lazy_static! {
- static ref ABSTRACT_MODIFIER: Regex = Regex::new(r"\babstract\b").unwrap();
- static ref EXPORT_MODIFIER: Regex = Regex::new(r"\bexport\b").unwrap();
-}
+static ABSTRACT_MODIFIER: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r"\babstract\b").unwrap());
+
+static EXPORT_MODIFIER: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r"\bexport\b").unwrap());
#[derive(Debug, Deserialize, Serialize)]
pub enum CodeLensSource {
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index 9e4a74ff2..1125d381f 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -24,6 +24,7 @@ use deno_core::url;
use deno_core::ModuleSpecifier;
use deno_graph::Module;
use lspower::lsp;
+use once_cell::sync::Lazy;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::HashSet;
@@ -35,20 +36,39 @@ use std::str::FromStr;
use std::sync::Arc;
use std::time::SystemTime;
-lazy_static::lazy_static! {
- static ref JS_HEADERS: HashMap<String, String> = ([
- ("content-type".to_string(), "application/javascript".to_string())
- ]).iter().cloned().collect();
- static ref JSX_HEADERS: HashMap<String, String> = ([
- ("content-type".to_string(), "text/jsx".to_string())
- ]).iter().cloned().collect();
- static ref TS_HEADERS: HashMap<String, String> = ([
- ("content-type".to_string(), "application/typescript".to_string())
- ]).iter().cloned().collect();
- static ref TSX_HEADERS: HashMap<String, String> = ([
- ("content-type".to_string(), "text/tsx".to_string())
- ]).iter().cloned().collect();
-}
+static JS_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
+ ([(
+ "content-type".to_string(),
+ "application/javascript".to_string(),
+ )])
+ .iter()
+ .cloned()
+ .collect()
+});
+
+static JSX_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
+ ([("content-type".to_string(), "text/jsx".to_string())])
+ .iter()
+ .cloned()
+ .collect()
+});
+
+static TS_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
+ ([(
+ "content-type".to_string(),
+ "application/typescript".to_string(),
+ )])
+ .iter()
+ .cloned()
+ .collect()
+});
+
+static TSX_HEADERS: Lazy<HashMap<String, String>> = Lazy::new(|| {
+ ([("content-type".to_string(), "text/tsx".to_string())])
+ .iter()
+ .cloned()
+ .collect()
+});
/// The default parser from `deno_graph` does not include the configuration
/// options we require here, and so implementing an empty struct that provides
diff --git a/cli/lsp/path_to_regex.rs b/cli/lsp/path_to_regex.rs
index ce935ee27..393591785 100644
--- a/cli/lsp/path_to_regex.rs
+++ b/cli/lsp/path_to_regex.rs
@@ -29,15 +29,14 @@
use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use fancy_regex::Regex as FancyRegex;
+use once_cell::sync::Lazy;
use regex::Regex;
use std::collections::HashMap;
use std::fmt;
use std::iter::Peekable;
-lazy_static::lazy_static! {
- static ref ESCAPE_STRING_RE: Regex =
- Regex::new(r"([.+*?=^!:${}()\[\]|/\\])").unwrap();
-}
+static ESCAPE_STRING_RE: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r"([.+*?=^!:${}()\[\]|/\\])").unwrap());
#[derive(Debug, PartialEq, Eq)]
enum TokenType {
diff --git a/cli/lsp/refactor.rs b/cli/lsp/refactor.rs
index 17ab4d5de..2694b7c5a 100644
--- a/cli/lsp/refactor.rs
+++ b/cli/lsp/refactor.rs
@@ -7,6 +7,7 @@ use deno_core::serde::Deserialize;
use deno_core::serde::Serialize;
use deno_core::ModuleSpecifier;
use lspower::lsp;
+use once_cell::sync::Lazy;
pub struct RefactorCodeActionKind {
pub kind: lsp::CodeActionKind,
@@ -19,58 +20,120 @@ impl RefactorCodeActionKind {
}
}
-lazy_static::lazy_static! {
- pub static ref EXTRACT_FUNCTION: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "function"].join(".").into(),
+pub static EXTRACT_FUNCTION: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "function"]
+ .join(".")
+ .into(),
matches_callback: Box::new(|tag: &str| tag.starts_with("function_")),
- };
+ });
- pub static ref EXTRACT_CONSTANT: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "constant"].join(".").into(),
+pub static EXTRACT_CONSTANT: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "constant"]
+ .join(".")
+ .into(),
matches_callback: Box::new(|tag: &str| tag.starts_with("constant_")),
- };
-
- pub static ref EXTRACT_TYPE: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "type"].join(".").into(),
- matches_callback: Box::new(|tag: &str| tag.starts_with("Extract to type alias")),
- };
-
- pub static ref EXTRACT_INTERFACE: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "interface"].join(".").into(),
- matches_callback: Box::new(|tag: &str| tag.starts_with("Extract to interface")),
- };
-
- pub static ref MOVE_NEWFILE: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR.as_str(), "move", "newFile"].join(".").into(),
- matches_callback: Box::new(|tag: &str| tag.starts_with("Move to a new file")),
- };
-
- pub static ref REWRITE_IMPORT: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "import"].join(".").into(),
- matches_callback: Box::new(|tag: &str| tag.starts_with("Convert namespace import") || tag.starts_with("Convert named imports")),
- };
-
- pub static ref REWRITE_EXPORT: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "export"].join(".").into(),
- matches_callback: Box::new(|tag: &str| tag.starts_with("Convert default export") || tag.starts_with("Convert named export")),
- };
-
- pub static ref REWRITE_ARROW_BRACES: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "arrow", "braces"].join(".").into(),
- matches_callback: Box::new(|tag: &str| tag.starts_with("Add or remove braces in an arrow function")),
- };
-
- pub static ref REWRITE_PARAMETERS_TO_DESTRUCTURED: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "parameters", "toDestructured"].join(".").into(),
- matches_callback: Box::new(|tag: &str| tag.starts_with("Convert parameters to destructured object")),
- };
-
- pub static ref REWRITE_PROPERTY_GENERATEACCESSORS: RefactorCodeActionKind = RefactorCodeActionKind {
- kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "property", "generateAccessors"].join(".").into(),
- matches_callback: Box::new(|tag: &str| tag.starts_with("Generate 'get' and 'set' accessors")),
- };
-
- pub static ref ALL_KNOWN_REFACTOR_ACTION_KINDS: Vec<&'static RefactorCodeActionKind> = vec![
+ });
+
+pub static EXTRACT_TYPE: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "type"]
+ .join(".")
+ .into(),
+ matches_callback: Box::new(|tag: &str| {
+ tag.starts_with("Extract to type alias")
+ }),
+ });
+
+pub static EXTRACT_INTERFACE: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "interface"]
+ .join(".")
+ .into(),
+ matches_callback: Box::new(|tag: &str| {
+ tag.starts_with("Extract to interface")
+ }),
+ });
+
+pub static MOVE_NEWFILE: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [lsp::CodeActionKind::REFACTOR.as_str(), "move", "newFile"]
+ .join(".")
+ .into(),
+ matches_callback: Box::new(|tag: &str| {
+ tag.starts_with("Move to a new file")
+ }),
+ });
+
+pub static REWRITE_IMPORT: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "import"]
+ .join(".")
+ .into(),
+ matches_callback: Box::new(|tag: &str| {
+ tag.starts_with("Convert namespace import")
+ || tag.starts_with("Convert named imports")
+ }),
+ });
+
+pub static REWRITE_EXPORT: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "export"]
+ .join(".")
+ .into(),
+ matches_callback: Box::new(|tag: &str| {
+ tag.starts_with("Convert default export")
+ || tag.starts_with("Convert named export")
+ }),
+ });
+
+pub static REWRITE_ARROW_BRACES: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [
+ lsp::CodeActionKind::REFACTOR_REWRITE.as_str(),
+ "arrow",
+ "braces",
+ ]
+ .join(".")
+ .into(),
+ matches_callback: Box::new(|tag: &str| {
+ tag.starts_with("Add or remove braces in an arrow function")
+ }),
+ });
+
+pub static REWRITE_PARAMETERS_TO_DESTRUCTURED: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [
+ lsp::CodeActionKind::REFACTOR_REWRITE.as_str(),
+ "parameters",
+ "toDestructured",
+ ]
+ .join(".")
+ .into(),
+ matches_callback: Box::new(|tag: &str| {
+ tag.starts_with("Convert parameters to destructured object")
+ }),
+ });
+
+pub static REWRITE_PROPERTY_GENERATEACCESSORS: Lazy<RefactorCodeActionKind> =
+ Lazy::new(|| RefactorCodeActionKind {
+ kind: [
+ lsp::CodeActionKind::REFACTOR_REWRITE.as_str(),
+ "property",
+ "generateAccessors",
+ ]
+ .join(".")
+ .into(),
+ matches_callback: Box::new(|tag: &str| {
+ tag.starts_with("Generate 'get' and 'set' accessors")
+ }),
+ });
+
+pub static ALL_KNOWN_REFACTOR_ACTION_KINDS: Lazy<
+ Vec<&'static RefactorCodeActionKind>,
+> = Lazy::new(|| {
+ vec![
&EXTRACT_FUNCTION,
&EXTRACT_CONSTANT,
&EXTRACT_TYPE,
@@ -80,9 +143,9 @@ lazy_static::lazy_static! {
&REWRITE_EXPORT,
&REWRITE_ARROW_BRACES,
&REWRITE_PARAMETERS_TO_DESTRUCTURED,
- &REWRITE_PROPERTY_GENERATEACCESSORS
- ];
-}
+ &REWRITE_PROPERTY_GENERATEACCESSORS,
+ ]
+});
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs
index afaefffd8..fc7e13fb7 100644
--- a/cli/lsp/registries.rs
+++ b/cli/lsp/registries.rs
@@ -31,6 +31,7 @@ use deno_runtime::deno_web::BlobStore;
use deno_runtime::permissions::Permissions;
use log::error;
use lspower::lsp;
+use once_cell::sync::Lazy;
use regex::Regex;
use std::collections::HashMap;
use std::path::Path;
@@ -61,10 +62,8 @@ const COMPONENT: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS
.add(b'+')
.add(b',');
-lazy_static::lazy_static! {
- static ref REPLACEMENT_VARIABLE_RE: Regex =
- Regex::new(r"\$\{\{?(\w+)\}?\}").unwrap();
-}
+static REPLACEMENT_VARIABLE_RE: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r"\$\{\{?(\w+)\}?\}").unwrap());
fn base_url(url: &Url) -> String {
url.origin().ascii_serialization()
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index a0b201bc0..d7cf47003 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -42,6 +42,7 @@ use log::warn;
use lspower::jsonrpc::Error as LspError;
use lspower::jsonrpc::Result as LspResult;
use lspower::lsp;
+use once_cell::sync::Lazy;
use regex::Captures;
use regex::Regex;
use std::borrow::Cow;
@@ -56,16 +57,23 @@ use text_size::TextSize;
use tokio::sync::mpsc;
use tokio::sync::oneshot;
-lazy_static::lazy_static! {
- static ref BRACKET_ACCESSOR_RE: Regex = Regex::new(r#"^\[['"](.+)[\['"]\]$"#).unwrap();
- static ref CAPTION_RE: Regex = Regex::new(r"<caption>(.*?)</caption>\s*\r?\n((?:\s|\S)*)").unwrap();
- static ref CODEBLOCK_RE: Regex = Regex::new(r"^\s*[~`]{3}").unwrap();
- static ref EMAIL_MATCH_RE: Regex = Regex::new(r"(.+)\s<([-.\w]+@[-.\w]+)>").unwrap();
- static ref JSDOC_LINKS_RE: Regex = Regex::new(r"(?i)\{@(link|linkplain|linkcode) (https?://[^ |}]+?)(?:[| ]([^{}\n]+?))?\}").unwrap();
- static ref PART_KIND_MODIFIER_RE: Regex = Regex::new(r",|\s+").unwrap();
- static ref PART_RE: Regex = Regex::new(r"^(\S+)\s*-?\s*").unwrap();
- static ref SCOPE_RE: Regex = Regex::new(r"scope_(\d)").unwrap();
-}
+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 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());
const FILE_EXTENSION_KIND_MODIFIERS: &[&str] =
&[".d.ts", ".ts", ".tsx", ".js", ".jsx", ".json"];
diff --git a/cli/lsp/urls.rs b/cli/lsp/urls.rs
index 19f53f297..94830d34a 100644
--- a/cli/lsp/urls.rs
+++ b/cli/lsp/urls.rs
@@ -9,13 +9,13 @@ use deno_core::error::AnyError;
use deno_core::url::Position;
use deno_core::url::Url;
use deno_core::ModuleSpecifier;
+use once_cell::sync::Lazy;
use std::collections::HashMap;
-lazy_static::lazy_static! {
- /// Used in situations where a default URL needs to be used where otherwise a
- /// panic is undesired.
- pub(crate) static ref INVALID_SPECIFIER: ModuleSpecifier = ModuleSpecifier::parse("deno://invalid").unwrap();
-}
+/// Used in situations where a default URL needs to be used where otherwise a
+/// panic is undesired.
+pub(crate) static INVALID_SPECIFIER: Lazy<ModuleSpecifier> =
+ Lazy::new(|| ModuleSpecifier::parse("deno://invalid").unwrap());
/// Matches the `encodeURIComponent()` encoding from JavaScript, which matches
/// the component percent encoding set.
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index 252939f85..c32423f71 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -8,6 +8,7 @@ use deno_core::error::AnyError;
use deno_core::resolve_url_or_path;
use deno_core::url::Url;
use log::Level;
+use once_cell::sync::Lazy;
use regex::Regex;
use regex::RegexBuilder;
use std::env;
@@ -21,15 +22,12 @@ use std::path::PathBuf;
#[cfg(not(windows))]
use std::os::unix::fs::PermissionsExt;
-lazy_static::lazy_static! {
- static ref EXEC_NAME_RE: Regex = RegexBuilder::new(
- r"^[a-z][\w-]*$"
- ).case_insensitive(true).build().unwrap();
- // Regular expression to test disk driver letter. eg "C:\\User\username\path\to"
- static ref DRIVE_LETTER_REG: Regex = RegexBuilder::new(
- r"^[c-z]:"
- ).case_insensitive(true).build().unwrap();
-}
+static EXEC_NAME_RE: Lazy<Regex> = Lazy::new(|| {
+ RegexBuilder::new(r"^[a-z][\w-]*$")
+ .case_insensitive(true)
+ .build()
+ .unwrap()
+});
fn validate_name(exec_name: &str) -> Result<(), AnyError> {
if EXEC_NAME_RE.is_match(exec_name) {
@@ -375,13 +373,12 @@ fn is_in_path(dir: &Path) -> bool {
mod tests {
use super::*;
use deno_core::parking_lot::Mutex;
+ use once_cell::sync::Lazy;
use std::process::Command;
use tempfile::TempDir;
use test_util::testdata_path;
- lazy_static::lazy_static! {
- pub static ref ENV_LOCK: Mutex<()> = Mutex::new(());
- }
+ pub static ENV_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
#[test]
fn install_infer_name_from_url() {
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs
index 5838cb290..b0fddc39c 100644
--- a/cli/tools/upgrade.rs
+++ b/cli/tools/upgrade.rs
@@ -7,6 +7,7 @@ use deno_core::error::AnyError;
use deno_core::futures::StreamExt;
use deno_runtime::deno_fetch::reqwest;
use deno_runtime::deno_fetch::reqwest::Client;
+use once_cell::sync::Lazy;
use semver_parser::version::parse as semver_parse;
use std::fs;
use std::io::Write;
@@ -15,9 +16,8 @@ use std::path::PathBuf;
use std::process::Command;
use tempfile::TempDir;
-lazy_static::lazy_static! {
- static ref ARCHIVE_NAME: String = format!("deno-{}.zip", env!("TARGET"));
-}
+static ARCHIVE_NAME: Lazy<String> =
+ Lazy::new(|| format!("deno-{}.zip", env!("TARGET")));
const RELEASE_URL: &str = "https://github.com/denoland/deno/releases";
diff --git a/cli/tsc.rs b/cli/tsc.rs
index e87cb7c7d..b5df0c350 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -25,6 +25,7 @@ use deno_core::ModuleSpecifier;
use deno_core::OpFn;
use deno_core::RuntimeOptions;
use deno_core::Snapshot;
+use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
@@ -63,29 +64,39 @@ macro_rules! inc {
};
}
-lazy_static::lazy_static! {
- /// Contains static assets that are not preloaded in the compiler snapshot.
- pub(crate) static ref STATIC_ASSETS: HashMap<&'static str, &'static str> = (&[
- ("lib.dom.asynciterable.d.ts", inc!("lib.dom.asynciterable.d.ts")),
- ("lib.dom.d.ts", inc!("lib.dom.d.ts")),
- ("lib.dom.iterable.d.ts", inc!("lib.dom.iterable.d.ts")),
- ("lib.es6.d.ts", inc!("lib.es6.d.ts")),
- ("lib.es2016.full.d.ts", inc!("lib.es2016.full.d.ts")),
- ("lib.es2017.full.d.ts", inc!("lib.es2017.full.d.ts")),
- ("lib.es2018.full.d.ts", inc!("lib.es2018.full.d.ts")),
- ("lib.es2019.full.d.ts", inc!("lib.es2019.full.d.ts")),
- ("lib.es2020.full.d.ts", inc!("lib.es2020.full.d.ts")),
- ("lib.es2021.full.d.ts", inc!("lib.es2021.full.d.ts")),
- ("lib.esnext.full.d.ts", inc!("lib.esnext.full.d.ts")),
- ("lib.scripthost.d.ts", inc!("lib.scripthost.d.ts")),
- ("lib.webworker.d.ts", inc!("lib.webworker.d.ts")),
- ("lib.webworker.importscripts.d.ts", inc!("lib.webworker.importscripts.d.ts")),
- ("lib.webworker.iterable.d.ts", inc!("lib.webworker.iterable.d.ts")),
- ])
- .iter()
- .cloned()
- .collect();
-}
+/// Contains static assets that are not preloaded in the compiler snapshot.
+pub(crate) static STATIC_ASSETS: Lazy<HashMap<&'static str, &'static str>> =
+ Lazy::new(|| {
+ (&[
+ (
+ "lib.dom.asynciterable.d.ts",
+ inc!("lib.dom.asynciterable.d.ts"),
+ ),
+ ("lib.dom.d.ts", inc!("lib.dom.d.ts")),
+ ("lib.dom.iterable.d.ts", inc!("lib.dom.iterable.d.ts")),
+ ("lib.es6.d.ts", inc!("lib.es6.d.ts")),
+ ("lib.es2016.full.d.ts", inc!("lib.es2016.full.d.ts")),
+ ("lib.es2017.full.d.ts", inc!("lib.es2017.full.d.ts")),
+ ("lib.es2018.full.d.ts", inc!("lib.es2018.full.d.ts")),
+ ("lib.es2019.full.d.ts", inc!("lib.es2019.full.d.ts")),
+ ("lib.es2020.full.d.ts", inc!("lib.es2020.full.d.ts")),
+ ("lib.es2021.full.d.ts", inc!("lib.es2021.full.d.ts")),
+ ("lib.esnext.full.d.ts", inc!("lib.esnext.full.d.ts")),
+ ("lib.scripthost.d.ts", inc!("lib.scripthost.d.ts")),
+ ("lib.webworker.d.ts", inc!("lib.webworker.d.ts")),
+ (
+ "lib.webworker.importscripts.d.ts",
+ inc!("lib.webworker.importscripts.d.ts"),
+ ),
+ (
+ "lib.webworker.iterable.d.ts",
+ inc!("lib.webworker.iterable.d.ts"),
+ ),
+ ])
+ .iter()
+ .cloned()
+ .collect()
+ });
/// Retrieve a static asset that are included in the binary.
pub fn get_asset(asset: &str) -> Option<&'static str> {