1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 09:10:40 -05:00

chore: upgrade Rust to 1.54.0 (#11554)

This commit is contained in:
Yusuke Tanaka 2021-07-30 22:03:41 +09:00 committed by GitHub
parent c909faf9e6
commit 8f00b5542c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 156 additions and 161 deletions

View file

@ -79,7 +79,7 @@ jobs:
- name: Install Rust
uses: hecrj/setup-rust-action@v1
with:
rust-version: 1.53.0
rust-version: 1.54.0
- name: Install clippy and rustfmt
if: matrix.kind == 'lint'
@ -253,7 +253,7 @@ jobs:
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: e-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}
key: f-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}
# In main branch, always creates fresh cache
- name: Cache build output (main)
@ -268,7 +268,7 @@ jobs:
!./target/*/*.zip
!./target/*/*.tar.gz
key: |
d-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
f-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
# Restore cache from the latest 'main' branch build.
- name: Cache build output (PR)
@ -284,7 +284,7 @@ jobs:
!./target/*/*.tar.gz
key: never_saved
restore-keys: |
d-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
f-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
# Don't save cache after building PRs or branches other than 'main'.
- name: Skip save cache (PR)

View file

@ -234,11 +234,11 @@ fn get_binary_sizes(target_dir: &Path) -> Result<HashMap<String, u64>> {
);
// add up size for everything in target/release/deps/libswc*
let swc_size = rlib_size(&target_dir, "libswc");
let swc_size = rlib_size(target_dir, "libswc");
println!("swc {} bytes", swc_size);
sizes.insert("swc_rlib".to_string(), swc_size);
let rusty_v8_size = rlib_size(&target_dir, "librusty_v8");
let rusty_v8_size = rlib_size(target_dir, "librusty_v8");
println!("rusty_v8 {} bytes", rusty_v8_size);
sizes.insert("rusty_v8_rlib".to_string(), rusty_v8_size);

View file

@ -189,7 +189,7 @@ impl DiagnosticMessageChain {
pub fn format_message(&self, level: usize) -> String {
let mut s = String::new();
s.push_str(&std::iter::repeat(" ").take(level * 2).collect::<String>());
s.push_str(&" ".repeat(level * 2));
s.push_str(&self.message_text);
if let Some(next) = &self.next {
s.push('\n');

View file

@ -139,7 +139,7 @@ impl DiskCache {
pub fn set(&self, filename: &Path, data: &[u8]) -> std::io::Result<()> {
let path = self.location.join(filename);
match path.parent() {
Some(ref parent) => self.ensure_dir_exists(parent),
Some(parent) => self.ensure_dir_exists(parent),
None => Ok(()),
}?;
fs_util::atomic_write_file(&path, data, crate::http_cache::CACHE_PERM)

View file

@ -469,7 +469,7 @@ impl FileFetcher {
Ok((_, headers)) => headers.get("etag").cloned(),
_ => None,
};
let maybe_auth_token = self.auth_tokens.get(&specifier);
let maybe_auth_token = self.auth_tokens.get(specifier);
let specifier = specifier.clone();
let mut permissions = permissions.clone();
let client = self.http_client.clone();

View file

@ -67,7 +67,7 @@ fn format_frame(frame: &JsStackFrame) -> String {
formatted_method += &format!("{}.", type_name);
}
}
formatted_method += &function_name;
formatted_method += function_name;
if let Some(method_name) = &frame.method_name {
if !function_name.ends_with(method_name) {
formatted_method += &format!(" [as {}]", method_name);
@ -78,7 +78,7 @@ fn format_frame(frame: &JsStackFrame) -> String {
formatted_method += &format!("{}.", type_name);
}
if let Some(method_name) = &frame.method_name {
formatted_method += &method_name
formatted_method += method_name
} else {
formatted_method += "<anonymous>";
}

View file

@ -93,7 +93,7 @@ impl Metadata {
#[cfg(test)]
pub fn read(cache_filename: &Path) -> Result<Metadata, AnyError> {
let metadata_filename = Metadata::filename(&cache_filename);
let metadata_filename = Metadata::filename(cache_filename);
let metadata = fs::read_to_string(metadata_filename)?;
let metadata: Metadata = serde_json::from_str(&metadata)?;
Ok(metadata)

View file

@ -268,7 +268,7 @@ impl ImportMap {
}
// Sort in longest and alphabetical order.
normalized_map.sort_by(|k1, _v1, k2, _v2| match k1.cmp(&k2) {
normalized_map.sort_by(|k1, _v1, k2, _v2| match k1.cmp(k2) {
Ordering::Greater => Ordering::Less,
Ordering::Less => Ordering::Greater,
// JSON guarantees that there can't be duplicate keys
@ -324,7 +324,7 @@ impl ImportMap {
}
// Sort in longest and alphabetical order.
normalized_map.sort_by(|k1, _v1, k2, _v2| match k1.cmp(&k2) {
normalized_map.sort_by(|k1, _v1, k2, _v2| match k1.cmp(k2) {
Ordering::Greater => Ordering::Less,
Ordering::Less => Ordering::Greater,
// JSON guarantees that there can't be duplicate keys
@ -691,7 +691,7 @@ mod tests {
ImportMap::from_json(&test.import_map_base_url, &test.import_map)
.unwrap();
let maybe_resolved = import_map
.resolve(&given_specifier, &base_url)
.resolve(given_specifier, base_url)
.ok()
.map(|url| url.to_string());
assert_eq!(expected_specifier, &maybe_resolved, "{}", test.name);

View file

@ -291,7 +291,7 @@ pub fn parse_module(
ast::parse_with_source_map(
&specifier.to_string(),
source,
&media_type,
media_type,
source_map,
)
}
@ -309,7 +309,7 @@ pub fn analyze_dependencies(
// Parse leading comments for supported triple slash references.
for comment in parsed_module.get_leading_comments().iter() {
if let Some((ts_reference, span)) = parse_ts_reference(&comment) {
if let Some((ts_reference, span)) = parse_ts_reference(comment) {
let loc = parsed_module.source_map.lookup_char_pos(span.lo);
match ts_reference {
TypeScriptReference::Path(import) => {
@ -364,7 +364,7 @@ pub fn analyze_dependencies(
let maybe_resolved_type_dependency =
// Check for `@deno-types` pragmas that affect the import
if let Some(comment) = desc.leading_comments.last() {
parse_deno_types(&comment).as_ref().map(|(deno_types, span)| {
parse_deno_types(comment).as_ref().map(|(deno_types, span)| {
(
resolve_import(deno_types, specifier, maybe_import_map),
deno_types.clone(),

View file

@ -102,7 +102,7 @@ impl DenoTestCollector {
key_value_prop.value.as_ref()
{
let name = lit_str.value.to_string();
self.add_code_lens(name, &span);
self.add_code_lens(name, span);
}
}
}
@ -112,7 +112,7 @@ impl DenoTestCollector {
}
ast::Expr::Lit(ast::Lit::Str(lit_str)) => {
let name = lit_str.value.to_string();
self.add_code_lens(name, &span);
self.add_code_lens(name, span);
}
_ => (),
}
@ -415,7 +415,7 @@ async fn collect_tsc(
) -> Result<Vec<lsp::CodeLens>, AnyError> {
let workspace_settings = language_server.config.get_workspace_settings();
let line_index = language_server
.get_line_index_sync(&specifier)
.get_line_index_sync(specifier)
.ok_or_else(|| anyhow!("Missing line index."))?;
let navigation_tree = language_server.get_navigation_tree(specifier).await?;
let code_lenses = Rc::new(RefCell::new(Vec::new()));
@ -435,7 +435,7 @@ async fn collect_tsc(
| tsc::ScriptElementKind::MemberGetAccessorElement
| tsc::ScriptElementKind::MemberSetAccessorElement => {
if ABSTRACT_MODIFIER.is_match(&i.kind_modifiers) {
code_lenses.push(i.to_code_lens(&line_index, &specifier, &source));
code_lenses.push(i.to_code_lens(&line_index, specifier, &source));
}
}
_ => (),
@ -447,31 +447,31 @@ async fn collect_tsc(
let source = CodeLensSource::References;
if let Some(parent) = &mp {
if parent.kind == tsc::ScriptElementKind::EnumElement {
code_lenses.push(i.to_code_lens(&line_index, &specifier, &source));
code_lenses.push(i.to_code_lens(&line_index, specifier, &source));
}
}
match i.kind {
tsc::ScriptElementKind::FunctionElement => {
if workspace_settings.code_lens.references_all_functions {
code_lenses.push(i.to_code_lens(&line_index, &specifier, &source));
code_lenses.push(i.to_code_lens(&line_index, specifier, &source));
}
}
tsc::ScriptElementKind::ConstElement
| tsc::ScriptElementKind::LetElement
| tsc::ScriptElementKind::VariableElement => {
if EXPORT_MODIFIER.is_match(&i.kind_modifiers) {
code_lenses.push(i.to_code_lens(&line_index, &specifier, &source));
code_lenses.push(i.to_code_lens(&line_index, specifier, &source));
}
}
tsc::ScriptElementKind::ClassElement => {
if i.text != "<class>" {
code_lenses.push(i.to_code_lens(&line_index, &specifier, &source));
code_lenses.push(i.to_code_lens(&line_index, specifier, &source));
}
}
tsc::ScriptElementKind::InterfaceElement
| tsc::ScriptElementKind::TypeElement
| tsc::ScriptElementKind::EnumElement => {
code_lenses.push(i.to_code_lens(&line_index, &specifier, &source));
code_lenses.push(i.to_code_lens(&line_index, specifier, &source));
}
tsc::ScriptElementKind::LocalFunctionElement
| tsc::ScriptElementKind::MemberGetAccessorElement
@ -486,7 +486,7 @@ async fn collect_tsc(
| tsc::ScriptElementKind::TypeElement => {
code_lenses.push(i.to_code_lens(
&line_index,
&specifier,
specifier,
&source,
));
}

View file

@ -260,13 +260,13 @@ fn to_lsp_related_information(
if let (Some(source), Some(start), Some(end)) =
(&ri.source, &ri.start, &ri.end)
{
let uri = lsp::Url::parse(&source).unwrap();
let uri = lsp::Url::parse(source).unwrap();
Some(lsp::DiagnosticRelatedInformation {
location: lsp::Location {
uri,
range: to_lsp_range(start, end),
},
message: get_diagnostic_message(&ri),
message: get_diagnostic_message(ri),
})
} else {
None
@ -421,8 +421,8 @@ fn diagnose_dependency(
})
}
analysis::ResolvedDependency::Resolved(specifier) => {
if !(documents.contains_key(&specifier)
|| sources.contains_key(&specifier))
if !(documents.contains_key(specifier)
|| sources.contains_key(specifier))
{
let (code, message) = match specifier.scheme() {
"file" => (Some(lsp::NumberOrString::String("no-local".to_string())), format!("Unable to load a local module: \"{}\".\n Please check the file path.", specifier)),
@ -439,8 +439,8 @@ fn diagnose_dependency(
data: Some(json!({ "specifier": specifier })),
..Default::default()
});
} else if sources.contains_key(&specifier) {
if let Some(message) = sources.get_maybe_warning(&specifier) {
} else if sources.contains_key(specifier) {
if let Some(message) = sources.get_maybe_warning(specifier) {
diagnostics.push(lsp::Diagnostic {
range,
severity: Some(lsp::DiagnosticSeverity::Warning),

View file

@ -119,13 +119,13 @@ impl DocumentData {
let mut line_index = if let Some(line_index) = &self.line_index {
line_index.clone()
} else {
LineIndex::new(&content)
LineIndex::new(content)
};
let mut index_valid = IndexValid::All;
for change in content_changes {
if let Some(range) = change.range {
if !index_valid.covers(range.start.line) {
line_index = LineIndex::new(&content);
line_index = LineIndex::new(content);
}
index_valid = IndexValid::UpTo(range.start.line);
let range = line_index.get_text_range(range)?;
@ -139,7 +139,7 @@ impl DocumentData {
self.line_index = if index_valid == IndexValid::All {
Some(line_index)
} else {
Some(LineIndex::new(&content))
Some(LineIndex::new(content))
};
self.maybe_navigation_tree = None;
Ok(())

View file

@ -620,7 +620,7 @@ impl Inner {
Ok(maybe_asset.clone())
} else {
let maybe_asset =
tsc::get_asset(&specifier, &self.ts_server, self.snapshot()?).await?;
tsc::get_asset(specifier, &self.ts_server, self.snapshot()?).await?;
self.assets.insert(specifier.clone(), maybe_asset.clone());
Ok(maybe_asset)
}

View file

@ -104,7 +104,7 @@ fn get_completor_type(
if let StringOrNumber::String(name) = &k.name {
let value = match_result
.get(name)
.map(|s| s.to_string(Some(&k)))
.map(|s| s.to_string(Some(k)))
.unwrap_or_default();
len += value.chars().count();
if offset <= len {
@ -183,14 +183,13 @@ fn validate_config(config: &RegistryConfigurationJson) -> Result<(), AnyError> {
.collect()
});
let variable_names: Vec<String> = registry
.variables
.iter()
.map(|var| var.key.to_owned())
.collect();
for key_name in &key_names {
if !variable_names.contains(key_name) {
if !registry
.variables
.iter()
.map(|var| var.key.to_owned())
.any(|x| x == *key_name)
{
return Err(anyhow!("Invalid registry configuration. Registry with schema \"{}\" is missing variable declaration for key \"{}\".", registry.schema, key_name));
}
}

View file

@ -361,7 +361,7 @@ impl Inner {
&mut self,
specifier: &ModuleSpecifier,
) -> Option<String> {
let metadata = self.get_metadata(&specifier)?;
let metadata = self.get_metadata(specifier)?;
metadata.maybe_warning
}
@ -399,7 +399,7 @@ impl Inner {
map_content_type(specifier, maybe_content_type);
let source = get_source_from_bytes(bytes, maybe_charset).ok()?;
let maybe_types = headers.get("x-typescript-types").map(|s| {
analysis::resolve_import(s, &specifier, &self.maybe_import_map)
analysis::resolve_import(s, specifier, &self.maybe_import_map)
});
let maybe_warning = headers.get("x-deno-warning").cloned();
(source, media_type, maybe_types, maybe_warning)
@ -432,10 +432,10 @@ impl Inner {
fn get_path(&mut self, specifier: &ModuleSpecifier) -> Option<PathBuf> {
if specifier.scheme() == "file" {
specifier.to_file_path().ok()
} else if let Some(path) = self.remotes.get(&specifier) {
} else if let Some(path) = self.remotes.get(specifier) {
Some(path.clone())
} else {
let path = self.http_cache.get_cache_filename(&specifier)?;
let path = self.http_cache.get_cache_filename(specifier)?;
if path.is_file() {
self.remotes.insert(specifier.clone(), path.clone());
Some(path)

View file

@ -1293,7 +1293,7 @@ impl CallHierarchyOutgoingCall {
from_ranges: self
.from_spans
.iter()
.map(|span| span.to_range(&line_index))
.map(|span| span.to_range(line_index))
.collect(),
})
}

View file

@ -1088,7 +1088,7 @@ async fn test_command(
output.insert(specifier);
get_dependencies(
&graph,
graph,
graph.get_specifier(specifier)?,
output,
)?;
@ -1099,7 +1099,7 @@ async fn test_command(
output.insert(specifier);
get_dependencies(
&graph,
graph,
graph.get_specifier(specifier)?,
output,
)?;

View file

@ -348,7 +348,7 @@ impl Module {
// parse out any triple slash references
for comment in parsed_module.get_leading_comments().iter() {
if let Some((ts_reference, _)) = parse_ts_reference(&comment) {
if let Some((ts_reference, _)) = parse_ts_reference(comment) {
let location = parsed_module.get_location(&comment.span);
match ts_reference {
TypeScriptReference::Path(import) => {
@ -421,7 +421,7 @@ impl Module {
// Parse out any `@deno-types` pragmas and modify dependency
let maybe_type = if !desc.leading_comments.is_empty() {
let comment = desc.leading_comments.last().unwrap();
if let Some((deno_types, _)) = parse_deno_types(&comment).as_ref() {
if let Some((deno_types, _)) = parse_deno_types(comment).as_ref() {
Some(self.resolve_import(deno_types, Some(location.clone()))?)
} else {
None
@ -923,7 +923,7 @@ impl Graph {
// to ESM, which we don't really want unless someone has enabled the
// check_js option.
if !check_js
&& graph.get_media_type(&specifier) == Some(MediaType::JavaScript)
&& graph.get_media_type(specifier) == Some(MediaType::JavaScript)
{
debug!("skipping emit for {}", specifier);
continue;
@ -1931,7 +1931,7 @@ impl GraphBuilder {
maybe_referrer: &Option<Location>,
is_dynamic: bool,
) {
if !self.graph.modules.contains_key(&specifier) {
if !self.graph.modules.contains_key(specifier) {
self
.graph
.modules
@ -2231,21 +2231,21 @@ pub mod tests {
#[test]
fn test_get_version() {
let doc_a = "console.log(42);";
let version_a = get_version(&doc_a, "1.2.3", b"");
let version_a = get_version(doc_a, "1.2.3", b"");
let doc_b = "console.log(42);";
let version_b = get_version(&doc_b, "1.2.3", b"");
let version_b = get_version(doc_b, "1.2.3", b"");
assert_eq!(version_a, version_b);
let version_c = get_version(&doc_a, "1.2.3", b"options");
let version_c = get_version(doc_a, "1.2.3", b"options");
assert_ne!(version_a, version_c);
let version_d = get_version(&doc_b, "1.2.3", b"options");
let version_d = get_version(doc_b, "1.2.3", b"options");
assert_eq!(version_c, version_d);
let version_e = get_version(&doc_a, "1.2.4", b"");
let version_e = get_version(doc_a, "1.2.4", b"");
assert_ne!(version_a, version_e);
let version_f = get_version(&doc_b, "1.2.4", b"");
let version_f = get_version(doc_b, "1.2.4", b"");
assert_eq!(version_e, version_f);
}

View file

@ -115,9 +115,10 @@ impl ProgramState {
None => None,
Some(import_map_url) => {
let import_map_specifier =
deno_core::resolve_url_or_path(&import_map_url).context(
format!("Bad URL (\"{}\") for import map.", import_map_url),
)?;
deno_core::resolve_url_or_path(import_map_url).context(format!(
"Bad URL (\"{}\") for import map.",
import_map_url
))?;
let file = file_fetcher
.fetch(&import_map_specifier, &mut Permissions::allow_all())
.await
@ -369,11 +370,11 @@ impl ProgramState {
let emit_path = self
.dir
.gen_cache
.get_cache_filename_with_extension(&url, "js")?;
.get_cache_filename_with_extension(url, "js")?;
let emit_map_path = self
.dir
.gen_cache
.get_cache_filename_with_extension(&url, "js.map")?;
.get_cache_filename_with_extension(url, "js.map")?;
if let Ok(code) = self.dir.gen_cache.get(&emit_path) {
let maybe_map = if let Ok(map) = self.dir.gen_cache.get(&emit_map_path) {
Some(map)

View file

@ -327,7 +327,7 @@ impl SpecifierHandler for FetchHandler {
let mut maybe_map_path = None;
let map_path =
disk_cache.get_cache_filename_with_extension(&url, "js.map");
disk_cache.get_cache_filename_with_extension(url, "js.map");
let maybe_map = if let Some(map_path) = map_path {
if let Ok(map) = disk_cache.get(&map_path) {
maybe_map_path = Some(disk_cache.location.join(map_path));
@ -340,7 +340,7 @@ impl SpecifierHandler for FetchHandler {
};
let mut maybe_emit = None;
let mut maybe_emit_path = None;
let emit_path = disk_cache.get_cache_filename_with_extension(&url, "js");
let emit_path = disk_cache.get_cache_filename_with_extension(url, "js");
if let Some(emit_path) = emit_path {
if let Ok(code) = disk_cache.get(&emit_path) {
maybe_emit =

View file

@ -142,7 +142,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
_referrer: &str,
_is_main: bool,
) -> Result<ModuleSpecifier, AnyError> {
if let Ok(module_specifier) = resolve_url(&specifier) {
if let Ok(module_specifier) = resolve_url(specifier) {
if get_source_from_data_url(&module_specifier).is_ok()
|| specifier == SPECIFIER
{

View file

@ -709,7 +709,7 @@ pub async fn cover_files(
reporter.visit_coverage(
&script_coverage,
&script_source,
script_source,
maybe_source_map,
maybe_cached_source,
);

View file

@ -99,7 +99,7 @@ fn format_markdown(
) -> Result<String, String> {
let md_config = get_markdown_config();
dprint_plugin_markdown::format_text(
&file_text,
file_text,
&md_config,
move |tag, text, line_width| {
let tag = tag.to_lowercase();
@ -125,7 +125,7 @@ fn format_markdown(
if matches!(extension, "json" | "jsonc") {
let mut json_config = get_json_config();
json_config.line_width = line_width;
dprint_plugin_json::format_text(&text, &json_config)
dprint_plugin_json::format_text(text, &json_config)
} else {
let fake_filename =
PathBuf::from(format!("deno_fmt_stdin.{}", extension));
@ -133,7 +133,7 @@ fn format_markdown(
codeblock_config.line_width = line_width;
dprint_plugin_typescript::format_text(
&fake_filename,
&text,
text,
&codeblock_config,
)
}
@ -150,7 +150,7 @@ fn format_markdown(
/// See https://git.io/Jt4ht for configuration.
fn format_json(file_text: &str) -> Result<String, String> {
let json_config = get_json_config();
dprint_plugin_json::format_text(&file_text, &json_config)
dprint_plugin_json::format_text(file_text, &json_config)
.map_err(|e| e.to_string())
}
@ -162,11 +162,11 @@ pub fn format_file(
) -> Result<String, String> {
let ext = get_extension(file_path).unwrap_or_else(String::new);
if ext == "md" {
format_markdown(&file_text, config)
format_markdown(file_text, config)
} else if matches!(ext.as_str(), "json" | "jsonc") {
format_json(&file_text)
format_json(file_text)
} else {
dprint_plugin_typescript::format_text(&file_path, &file_text, &config)
dprint_plugin_typescript::format_text(file_path, file_text, &config)
.map_err(|e| e.to_string())
}
}

View file

@ -81,7 +81,7 @@ pub async fn lint_files(
sort_diagnostics(&mut file_diagnostics);
for d in file_diagnostics.iter() {
has_error.store(true, Ordering::Relaxed);
reporter.visit_diagnostic(&d, source.split('\n').collect());
reporter.visit_diagnostic(d, source.split('\n').collect());
}
}
Err(err) => {

View file

@ -555,7 +555,7 @@ impl ReplSession {
if evaluate_response.get("exceptionDetails").is_some()
&& wrapped_line != line
{
self.evaluate_ts_expression(&line).await?
self.evaluate_ts_expression(line).await?
} else {
evaluate_response
};
@ -632,7 +632,7 @@ impl ReplSession {
expression: &str,
) -> Result<Value, AnyError> {
let parsed_module =
crate::ast::parse("repl.ts", &expression, &crate::MediaType::TypeScript)?;
crate::ast::parse("repl.ts", expression, &crate::MediaType::TypeScript)?;
let transpiled_src = parsed_module
.transpile(&crate::ast::EmitOptions {

View file

@ -355,7 +355,7 @@ fn extract_files_from_regex_blocks(
lines_regex: &Regex,
) -> Result<Vec<File>, AnyError> {
let files = blocks_regex
.captures_iter(&source)
.captures_iter(source)
.filter_map(|block| {
let maybe_attributes = block
.get(1)
@ -390,7 +390,7 @@ fn extract_files_from_regex_blocks(
// TODO(caspervonb) generate an inline source map
let mut file_source = String::new();
for line in lines_regex.captures_iter(&text) {
for line in lines_regex.captures_iter(text) {
let text = line.get(1).unwrap();
file_source.push_str(&format!("{}\n", text.as_str()));
}
@ -424,7 +424,7 @@ fn extract_files_from_source_comments(
source: &str,
media_type: &MediaType,
) -> Result<Vec<File>, AnyError> {
let parsed_module = ast::parse(&specifier.as_str(), &source, &media_type)?;
let parsed_module = ast::parse(specifier.as_str(), source, media_type)?;
let mut comments = parsed_module.get_comments();
comments
.sort_by_key(|comment| parsed_module.get_location(&comment.span).line);
@ -447,7 +447,7 @@ fn extract_files_from_source_comments(
extract_files_from_regex_blocks(
&location,
&comment.text,
&media_type,
media_type,
&blocks_regex,
&lines_regex,
)
@ -474,8 +474,8 @@ fn extract_files_from_fenced_blocks(
extract_files_from_regex_blocks(
&location,
&source,
&media_type,
source,
media_type,
&blocks_regex,
&lines_regex,
)

View file

@ -510,9 +510,9 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
.map(|(s, mt)| match s.scheme() {
"data" | "blob" => {
let specifier_str = if s.scheme() == "data" {
hash_data_url(&s, &mt)
hash_data_url(s, mt)
} else {
hash_blob_url(&s, &mt)
hash_blob_url(s, mt)
};
data_url_map.insert(specifier_str.clone(), s.clone());
specifier_str
@ -640,7 +640,7 @@ mod tests {
..Default::default()
}));
let mut builder = GraphBuilder::new(handler.clone(), None, None);
builder.add(&specifier, false).await?;
builder.add(specifier, false).await?;
let graph = Arc::new(Mutex::new(builder.get_graph()));
let config = TsConfig::new(json!({
"allowJs": true,

View file

@ -690,7 +690,7 @@ fn decode(
// - https://encoding.spec.whatwg.org/#dom-textdecoder-decode
// - https://github.com/denoland/deno/issues/6649
// - https://github.com/v8/v8/blob/d68fb4733e39525f9ff0a9222107c02c28096e2a/include/v8.h#L3277-L3278
match v8::String::new_from_utf8(scope, &buf, v8::NewStringType::Normal) {
match v8::String::new_from_utf8(scope, buf, v8::NewStringType::Normal) {
Some(text) => rv.set(text.into()),
None => {
let msg = v8::String::new(scope, "string too long").unwrap();

15
core/internal.d.ts vendored
View file

@ -48,21 +48,16 @@ declare namespace __bootstrap {
*/
declare namespace primordials {
type UncurryThis<T extends (this: unknown, ...args: unknown[]) => unknown> =
(
self: ThisParameterType<T>,
...args: Parameters<T>
) => ReturnType<T>;
(self: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T>;
type UncurryThisStaticApply<
T extends (this: unknown, ...args: unknown[]) => unknown,
> = (self: ThisParameterType<T>, args: Parameters<T>) => ReturnType<T>;
type StaticApply<T extends (this: unknown, ...args: unknown[]) => unknown> =
(
args: Parameters<T>,
) => ReturnType<T>;
(args: Parameters<T>) => ReturnType<T>;
export function uncurryThis<
T extends (...args: unknown[]) => unknown,
>(fn: T): (self: ThisType<T>, ...args: Parameters<T>) => ReturnType<T>;
export function uncurryThis<T extends (...args: unknown[]) => unknown>(
fn: T,
): (self: ThisType<T>, ...args: Parameters<T>) => ReturnType<T>;
export function makeSafe<T extends NewableFunction>(
unsafe: NewableFunction,
safe: T,

View file

@ -96,7 +96,7 @@ pub fn resolve_import(
} else {
Url::parse(base).map_err(InvalidBaseUrl)?
};
base.join(&specifier).map_err(InvalidUrl)?
base.join(specifier).map_err(InvalidUrl)?
}
// If parsing the specifier as a URL failed for a different reason than

View file

@ -362,7 +362,7 @@ pub async fn op_crypto_sign_key(
};
let rng = RingRand::SystemRandom::new();
let signature = key_pair.sign(&rng, &data)?;
let signature = key_pair.sign(&rng, data)?;
// Signature data as buffer.
signature.as_ref().to_vec()
@ -372,7 +372,7 @@ pub async fn op_crypto_sign_key(
let key = HmacKey::new(hash, &*args.key.data);
let signature = ring::hmac::sign(&key, &data);
let signature = ring::hmac::sign(&key, data);
signature.as_ref().to_vec()
}
_ => return Err(type_error("Unsupported algorithm".to_string())),

View file

@ -260,7 +260,7 @@ where
let address_path = Path::new(&args.path);
{
let mut s = state.borrow_mut();
s.borrow_mut::<NP>().check_write(&address_path)?;
s.borrow_mut::<NP>().check_write(address_path)?;
}
let resource = state
.borrow()
@ -338,8 +338,8 @@ where
super::check_unstable2(&state, "Deno.connect");
{
let mut state_ = state.borrow_mut();
state_.borrow_mut::<NP>().check_read(&address_path)?;
state_.borrow_mut::<NP>().check_write(&address_path)?;
state_.borrow_mut::<NP>().check_read(address_path)?;
state_.borrow_mut::<NP>().check_write(address_path)?;
}
let path = args.path;
let unix_stream = net_unix::UnixStream::connect(Path::new(&path)).await?;
@ -512,13 +512,13 @@ where
super::check_unstable(state, "Deno.listenDatagram");
}
let permissions = state.borrow_mut::<NP>();
permissions.check_read(&address_path)?;
permissions.check_write(&address_path)?;
permissions.check_read(address_path)?;
permissions.check_write(address_path)?;
}
let (rid, local_addr) = if transport == "unix" {
net_unix::listen_unix(state, &address_path)?
net_unix::listen_unix(state, address_path)?
} else {
net_unix::listen_unix_packet(state, &address_path)?
net_unix::listen_unix_packet(state, address_path)?
};
debug!(
"New listener {} {}",

View file

@ -36,7 +36,7 @@ impl BlobStore {
id: &Uuid,
) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
let parts = self.parts.lock();
let part = parts.get(&id);
let part = parts.get(id);
part.cloned()
}
@ -45,7 +45,7 @@ impl BlobStore {
id: &Uuid,
) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
let mut parts = self.parts.lock();
parts.remove(&id)
parts.remove(id)
}
pub fn get_object_url(
@ -78,7 +78,7 @@ impl BlobStore {
pub fn remove_object_url(&self, url: &Url) {
let mut blob_store = self.object_urls.lock();
blob_store.remove(&url);
blob_store.remove(url);
}
}

View file

@ -48,67 +48,67 @@ fn style(s: &str, colorspec: ColorSpec) -> impl fmt::Display {
pub fn red_bold(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_fg(Some(Red)).set_bold(true);
style(&s, style_spec)
style(s, style_spec)
}
pub fn green_bold(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_fg(Some(Green)).set_bold(true);
style(&s, style_spec)
style(s, style_spec)
}
pub fn italic_bold(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_bold(true).set_italic(true);
style(&s, style_spec)
style(s, style_spec)
}
pub fn white_on_red(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_bg(Some(Red)).set_fg(Some(White));
style(&s, style_spec)
style(s, style_spec)
}
pub fn black_on_green(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_bg(Some(Green)).set_fg(Some(Black));
style(&s, style_spec)
style(s, style_spec)
}
pub fn yellow(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_fg(Some(Yellow));
style(&s, style_spec)
style(s, style_spec)
}
pub fn cyan(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_fg(Some(Cyan));
style(&s, style_spec)
style(s, style_spec)
}
pub fn red(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_fg(Some(Red));
style(&s, style_spec)
style(s, style_spec)
}
pub fn green(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_fg(Some(Green));
style(&s, style_spec)
style(s, style_spec)
}
pub fn bold(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_bold(true);
style(&s, style_spec)
style(s, style_spec)
}
pub fn gray(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_fg(Some(Ansi256(8)));
style(&s, style_spec)
style(s, style_spec)
}
pub fn italic_bold_gray(s: &str) -> impl fmt::Display {
@ -117,11 +117,11 @@ pub fn italic_bold_gray(s: &str) -> impl fmt::Display {
.set_fg(Some(Ansi256(8)))
.set_bold(true)
.set_italic(true);
style(&s, style_spec)
style(s, style_spec)
}
pub fn intense_blue(s: &str) -> impl fmt::Display {
let mut style_spec = ColorSpec::new();
style_spec.set_fg(Some(Blue)).set_intense(true);
style(&s, style_spec)
style(s, style_spec)
}

View file

@ -1366,7 +1366,7 @@ fn make_temp(
let prefix_ = prefix.unwrap_or("");
let suffix_ = suffix.unwrap_or("");
let mut buf: PathBuf = match dir {
Some(ref p) => p.to_path_buf(),
Some(p) => p.to_path_buf(),
None => temp_dir(),
}
.join("_");

View file

@ -712,7 +712,7 @@ impl UnaryPermission<RunDescriptor> {
pub fn request(&mut self, cmd: Option<&str>) -> PermissionState {
if let Some(cmd) = cmd {
let state = self.query(Some(&cmd));
let state = self.query(Some(cmd));
if state == PermissionState::Prompt {
if permission_prompt(&format!("run access to \"{}\"", cmd)) {
self.granted_list.retain(|cmd_| cmd_.0 != cmd);
@ -819,7 +819,7 @@ impl Permissions {
name: "read",
description: "read the file system",
global_state: global_state_from_option(state),
granted_list: resolve_read_allowlist(&state),
granted_list: resolve_read_allowlist(state),
denied_list: Default::default(),
prompt,
}
@ -833,7 +833,7 @@ impl Permissions {
name: "write",
description: "write to the file system",
global_state: global_state_from_option(state),
granted_list: resolve_write_allowlist(&state),
granted_list: resolve_write_allowlist(state),
denied_list: Default::default(),
prompt,
}
@ -1469,15 +1469,15 @@ mod tests {
#[rustfmt::skip]
{
assert_eq!(perms1.read.query(None), PermissionState::Granted);
assert_eq!(perms1.read.query(Some(&Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms1.read.query(Some(Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms2.read.query(None), PermissionState::Prompt);
assert_eq!(perms2.read.query(Some(&Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms2.read.query(Some(&Path::new("/foo/bar"))), PermissionState::Granted);
assert_eq!(perms2.read.query(Some(Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms2.read.query(Some(Path::new("/foo/bar"))), PermissionState::Granted);
assert_eq!(perms1.write.query(None), PermissionState::Granted);
assert_eq!(perms1.write.query(Some(&Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms1.write.query(Some(Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms2.write.query(None), PermissionState::Prompt);
assert_eq!(perms2.write.query(Some(&Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms2.write.query(Some(&Path::new("/foo/bar"))), PermissionState::Granted);
assert_eq!(perms2.write.query(Some(Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms2.write.query(Some(Path::new("/foo/bar"))), PermissionState::Granted);
assert_eq!(perms1.net.query::<&str>(None), PermissionState::Granted);
assert_eq!(perms1.net.query(Some(&("127.0.0.1", None))), PermissionState::Granted);
assert_eq!(perms2.net.query::<&str>(None), PermissionState::Prompt);
@ -1504,13 +1504,13 @@ mod tests {
{
let _guard = PERMISSION_PROMPT_GUARD.lock();
set_prompt_result(true);
assert_eq!(perms.read.request(Some(&Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms.read.request(Some(Path::new("/foo"))), PermissionState::Granted);
assert_eq!(perms.read.query(None), PermissionState::Prompt);
set_prompt_result(false);
assert_eq!(perms.read.request(Some(&Path::new("/foo/bar"))), PermissionState::Granted);
assert_eq!(perms.read.request(Some(Path::new("/foo/bar"))), PermissionState::Granted);
set_prompt_result(false);
assert_eq!(perms.write.request(Some(&Path::new("/foo"))), PermissionState::Denied);
assert_eq!(perms.write.query(Some(&Path::new("/foo/bar"))), PermissionState::Prompt);
assert_eq!(perms.write.request(Some(Path::new("/foo"))), PermissionState::Denied);
assert_eq!(perms.write.query(Some(Path::new("/foo/bar"))), PermissionState::Prompt);
set_prompt_result(true);
assert_eq!(perms.write.request(None), PermissionState::Denied);
set_prompt_result(true);
@ -1572,12 +1572,12 @@ mod tests {
};
#[rustfmt::skip]
{
assert_eq!(perms.read.revoke(Some(&Path::new("/foo/bar"))), PermissionState::Granted);
assert_eq!(perms.read.revoke(Some(&Path::new("/foo"))), PermissionState::Prompt);
assert_eq!(perms.read.query(Some(&Path::new("/foo/bar"))), PermissionState::Prompt);
assert_eq!(perms.write.revoke(Some(&Path::new("/foo/bar"))), PermissionState::Granted);
assert_eq!(perms.read.revoke(Some(Path::new("/foo/bar"))), PermissionState::Granted);
assert_eq!(perms.read.revoke(Some(Path::new("/foo"))), PermissionState::Prompt);
assert_eq!(perms.read.query(Some(Path::new("/foo/bar"))), PermissionState::Prompt);
assert_eq!(perms.write.revoke(Some(Path::new("/foo/bar"))), PermissionState::Granted);
assert_eq!(perms.write.revoke(None), PermissionState::Prompt);
assert_eq!(perms.write.query(Some(&Path::new("/foo/bar"))), PermissionState::Prompt);
assert_eq!(perms.write.query(Some(Path::new("/foo/bar"))), PermissionState::Prompt);
assert_eq!(perms.net.revoke(Some(&("127.0.0.1", Some(8000)))), PermissionState::Granted);
assert_eq!(perms.net.revoke(Some(&("127.0.0.1", None))), PermissionState::Prompt);
assert_eq!(perms.env.revoke(Some(&"HOME".to_string())), PermissionState::Prompt);
@ -1602,16 +1602,16 @@ mod tests {
let _guard = PERMISSION_PROMPT_GUARD.lock();
set_prompt_result(true);
assert!(perms.read.check(&Path::new("/foo")).is_ok());
assert!(perms.read.check(Path::new("/foo")).is_ok());
set_prompt_result(false);
assert!(perms.read.check(&Path::new("/foo")).is_ok());
assert!(perms.read.check(&Path::new("/bar")).is_err());
assert!(perms.read.check(Path::new("/foo")).is_ok());
assert!(perms.read.check(Path::new("/bar")).is_err());
set_prompt_result(true);
assert!(perms.write.check(&Path::new("/foo")).is_ok());
assert!(perms.write.check(Path::new("/foo")).is_ok());
set_prompt_result(false);
assert!(perms.write.check(&Path::new("/foo")).is_ok());
assert!(perms.write.check(&Path::new("/bar")).is_err());
assert!(perms.write.check(Path::new("/foo")).is_ok());
assert!(perms.write.check(Path::new("/bar")).is_err());
set_prompt_result(true);
assert!(perms.net.check(&("127.0.0.1", Some(8000))).is_ok());
@ -1655,20 +1655,20 @@ mod tests {
let _guard = PERMISSION_PROMPT_GUARD.lock();
set_prompt_result(false);
assert!(perms.read.check(&Path::new("/foo")).is_err());
assert!(perms.read.check(Path::new("/foo")).is_err());
set_prompt_result(true);
assert!(perms.read.check(&Path::new("/foo")).is_err());
assert!(perms.read.check(&Path::new("/bar")).is_ok());
assert!(perms.read.check(Path::new("/foo")).is_err());
assert!(perms.read.check(Path::new("/bar")).is_ok());
set_prompt_result(false);
assert!(perms.read.check(&Path::new("/bar")).is_ok());
assert!(perms.read.check(Path::new("/bar")).is_ok());
set_prompt_result(false);
assert!(perms.write.check(&Path::new("/foo")).is_err());
assert!(perms.write.check(Path::new("/foo")).is_err());
set_prompt_result(true);
assert!(perms.write.check(&Path::new("/foo")).is_err());
assert!(perms.write.check(&Path::new("/bar")).is_ok());
assert!(perms.write.check(Path::new("/foo")).is_err());
assert!(perms.write.check(Path::new("/bar")).is_ok());
set_prompt_result(false);
assert!(perms.write.check(&Path::new("/bar")).is_ok());
assert!(perms.write.check(Path::new("/bar")).is_ok());
set_prompt_result(false);
assert!(perms.net.check(&("127.0.0.1", Some(8000))).is_err());