summaryrefslogtreecommitdiff
path: root/cli/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp')
-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
8 files changed, 229 insertions, 132 deletions
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.