diff options
Diffstat (limited to 'cli/tools')
| -rw-r--r-- | cli/tools/bench/mod.rs | 4 | ||||
| -rw-r--r-- | cli/tools/coverage/mod.rs | 13 | ||||
| -rw-r--r-- | cli/tools/doc.rs | 2 | ||||
| -rw-r--r-- | cli/tools/fmt.rs | 8 | ||||
| -rw-r--r-- | cli/tools/lint/mod.rs | 8 | ||||
| -rw-r--r-- | cli/tools/registry/diagnostics.rs | 22 | ||||
| -rw-r--r-- | cli/tools/registry/graph.rs | 4 | ||||
| -rw-r--r-- | cli/tools/registry/tar.rs | 2 | ||||
| -rw-r--r-- | cli/tools/registry/unfurl.rs | 50 | ||||
| -rw-r--r-- | cli/tools/repl/session.rs | 11 | ||||
| -rw-r--r-- | cli/tools/test/mod.rs | 8 | ||||
| -rw-r--r-- | cli/tools/vendor/analyze.rs | 3 | ||||
| -rw-r--r-- | cli/tools/vendor/build.rs | 2 | ||||
| -rw-r--r-- | cli/tools/vendor/import_map.rs | 2 |
14 files changed, 65 insertions, 74 deletions
diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs index dd94205cb..a6c8d3e16 100644 --- a/cli/tools/bench/mod.rs +++ b/cli/tools/bench/mod.rs @@ -506,14 +506,14 @@ pub async fn run_benchmarks_with_watch( let bench_modules_to_reload = if let Some(changed_paths) = changed_paths { let changed_paths = changed_paths.into_iter().collect::<HashSet<_>>(); - let mut result = Vec::new(); + let mut result = IndexSet::with_capacity(bench_modules.len()); for bench_module_specifier in bench_modules { if has_graph_root_local_dependent_changed( &graph, bench_module_specifier, &changed_paths, ) { - result.push(bench_module_specifier.clone()); + result.insert(bench_module_specifier.clone()); } } result diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs index 030bf425e..6175bd964 100644 --- a/cli/tools/coverage/mod.rs +++ b/cli/tools/coverage/mod.rs @@ -25,7 +25,6 @@ use deno_core::serde_json; use deno_core::sourcemap::SourceMap; use deno_core::url::Url; use deno_core::LocalInspectorSession; -use deno_core::ModuleCodeString; use regex::Regex; use std::fs; use std::fs::File; @@ -565,7 +564,7 @@ pub async fn cover_files( | MediaType::Cjs | MediaType::Mjs | MediaType::Json => None, - MediaType::Dts | MediaType::Dmts | MediaType::Dcts => Some(String::new()), + MediaType::Dts | MediaType::Dmts | MediaType::Dcts => Some(Vec::new()), MediaType::TypeScript | MediaType::Jsx | MediaType::Mts @@ -586,11 +585,13 @@ pub async fn cover_files( unreachable!() } }; - let runtime_code: ModuleCodeString = transpiled_code - .map(|c| c.into()) - .unwrap_or_else(|| original_source.clone().into()); + let runtime_code: String = match transpiled_code { + Some(code) => String::from_utf8(code) + .with_context(|| format!("Failed decoding {}", file.specifier))?, + None => original_source.to_string(), + }; - let source_map = source_map_from_code(&runtime_code); + let source_map = source_map_from_code(runtime_code.as_bytes()); let coverage_report = generate_coverage_report( &script_coverage, runtime_code.as_str().to_owned(), diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index bebe4567f..44bf19d50 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -350,7 +350,7 @@ fn check_diagnostics(diagnostics: &[DocDiagnostic]) -> Result<(), AnyError> { for (_, diagnostics_by_col) in diagnostics_by_lc { for (_, diagnostics) in diagnostics_by_col { for diagnostic in diagnostics { - log::error!("{}", diagnostic.display()); + log::error!("{}\n", diagnostic.display()); } } } diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index ef3d48cb5..b37a8e06b 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -211,7 +211,7 @@ fn format_markdown( codeblock_config.line_width = line_width; dprint_plugin_typescript::format_text( &fake_filename, - text, + text.to_string(), &codeblock_config, ) } @@ -255,7 +255,11 @@ pub fn format_file( ), _ => { let config = get_resolved_typescript_config(fmt_options); - dprint_plugin_typescript::format_text(file_path, file_text, &config) + dprint_plugin_typescript::format_text( + file_path, + file_text.to_string(), + &config, + ) } } } diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index 7253c99b2..151d0f11d 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -244,7 +244,7 @@ async fn lint_files( incremental_cache.update_file( &file_path, // ensure the returned text is used here as it may have been modified via --fix - file_source.text_info().text_str(), + file_source.text(), ) } } @@ -396,7 +396,7 @@ fn lint_file_and_fix( media_type, linter, config.clone(), - source.text_info(), + source.text_info_lazy(), &diagnostics, )?; match change { @@ -423,7 +423,7 @@ fn lint_file_and_fix( if fix_iterations > 0 { // everything looks good and the file still parses, so write it out - fs::write(file_path, source.text_info().text_str()) + fs::write(file_path, source.text().as_ref()) .context("Failed writing fix to file.")?; } @@ -668,7 +668,7 @@ impl LintReporter for PrettyLintReporter { } } - log::error!("{}", d.display()); + log::error!("{}\n", d.display()); } fn visit_error(&mut self, file_path: &str, err: &AnyError) { diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs index 1c3a3bd58..3f3e1ee96 100644 --- a/cli/tools/registry/diagnostics.rs +++ b/cli/tools/registry/diagnostics.rs @@ -40,11 +40,7 @@ impl PublishDiagnosticsCollector { diagnostics.sort_by_cached_key(|d| d.sorting_key()); for diagnostic in diagnostics { - // todo(https://github.com/denoland/deno_ast/issues/245): use log crate here - #[allow(clippy::print_stderr)] - { - eprint!("{}", diagnostic.display()); - } + log::error!("{}", diagnostic.display()); if matches!(diagnostic.level(), DiagnosticLevel::Error) { errors += 1; } @@ -287,7 +283,7 @@ impl Diagnostic for PublishDiagnostic { Some(DiagnosticSnippet { source: Cow::Borrowed(text_info), - highlight: DiagnosticSnippetHighlight { + highlights: vec![DiagnosticSnippetHighlight { style: DiagnosticSnippetHighlightStyle::Error, range: DiagnosticSourceRange { start: DiagnosticSourcePos::LineAndCol { @@ -300,7 +296,7 @@ impl Diagnostic for PublishDiagnostic { }, }, description: Some("the specifier".into()), - }, + }], }) } @@ -314,14 +310,14 @@ impl Diagnostic for PublishDiagnostic { .. } => Some(DiagnosticSnippet { source: Cow::Borrowed(text_info), - highlight: DiagnosticSnippetHighlight { + highlights: vec![DiagnosticSnippetHighlight { style: DiagnosticSnippetHighlightStyle::Warning, range: DiagnosticSourceRange { start: DiagnosticSourcePos::SourcePos(range.start), end: DiagnosticSourcePos::SourcePos(range.end), }, description: Some("the unanalyzable dynamic import".into()), - }, + }], }), }, InvalidPath { .. } => None, @@ -343,14 +339,14 @@ impl Diagnostic for PublishDiagnostic { range, text_info, .. } => Some(DiagnosticSnippet { source: Cow::Borrowed(text_info), - highlight: DiagnosticSnippetHighlight { + highlights: vec![DiagnosticSnippetHighlight { style: DiagnosticSnippetHighlightStyle::Error, range: DiagnosticSourceRange { start: DiagnosticSourcePos::SourcePos(range.start), end: DiagnosticSourcePos::SourcePos(range.end), }, description: Some("the triple slash directive".into()), - }, + }], }), } } @@ -398,14 +394,14 @@ impl Diagnostic for PublishDiagnostic { let end = replacement.line_end(0); Some(DiagnosticSnippet { source: Cow::Owned(replacement), - highlight: DiagnosticSnippetHighlight { + highlights: vec![DiagnosticSnippetHighlight { style: DiagnosticSnippetHighlightStyle::Hint, range: DiagnosticSourceRange { start: DiagnosticSourcePos::SourcePos(start), end: DiagnosticSourcePos::SourcePos(end), }, description: Some("try this specifier".into()), - }, + }], }) } None => None, diff --git a/cli/tools/registry/graph.rs b/cli/tools/registry/graph.rs index b363efdb4..73b72c1b6 100644 --- a/cli/tools/registry/graph.rs +++ b/cli/tools/registry/graph.rs @@ -130,7 +130,7 @@ impl GraphDiagnosticsCollector { prefer_fast_check_graph: false, follow_type_only: true, }; - let mut iter = graph.walk(&graph.roots, options); + let mut iter = graph.walk(graph.roots.iter(), options); while let Some((specifier, entry)) = iter.next() { if skip_specifiers.contains(specifier) { iter.skip_previous_dependencies(); @@ -196,7 +196,7 @@ fn check_for_banned_triple_slash_directives( PublishDiagnostic::BannedTripleSlashDirectives { specifier: parsed_source.specifier().clone(), range: comment.range(), - text_info: parsed_source.text_info().clone(), + text_info: parsed_source.text_info_lazy().clone(), }, ); } diff --git a/cli/tools/registry/tar.rs b/cli/tools/registry/tar.rs index 8124a0c9e..f98d4b09c 100644 --- a/cli/tools/registry/tar.rs +++ b/cli/tools/registry/tar.rs @@ -126,7 +126,7 @@ fn resolve_content_maybe_unfurling( let text = String::from_utf8(data)?; deno_ast::parse_module(deno_ast::ParseParams { specifier: specifier.clone(), - text_info: deno_ast::SourceTextInfo::from_string(text), + text: text.into(), media_type, capture_tokens: false, maybe_syntax: None, diff --git a/cli/tools/registry/unfurl.rs b/cli/tools/registry/unfurl.rs index f45b6ffc3..bc3272835 100644 --- a/cli/tools/registry/unfurl.rs +++ b/cli/tools/registry/unfurl.rs @@ -121,16 +121,15 @@ impl<'a> SpecifierUnfurler<'a> { fn try_unfurl_dynamic_dep( &self, module_url: &lsp_types::Url, - parsed_source: &ParsedSource, + text_info: &SourceTextInfo, dep: &deno_graph::DynamicDependencyDescriptor, text_changes: &mut Vec<deno_ast::TextChange>, ) -> bool { match &dep.argument { deno_graph::DynamicArgument::String(specifier) => { - let range = to_range(parsed_source, &dep.argument_range); - let maybe_relative_index = parsed_source.text_info().text_str() - [range.start..range.end] - .find(specifier); + let range = to_range(text_info, &dep.argument_range); + let maybe_relative_index = + text_info.text_str()[range.start..range.end].find(specifier); let Some(relative_index) = maybe_relative_index else { return true; // always say it's analyzable for a string }; @@ -159,9 +158,9 @@ impl<'a> SpecifierUnfurler<'a> { let Some(unfurled) = unfurled else { return true; // nothing to unfurl }; - let range = to_range(parsed_source, &dep.argument_range); + let range = to_range(text_info, &dep.argument_range); let maybe_relative_index = - parsed_source.text_info().text_str()[range.start..].find(specifier); + text_info.text_str()[range.start..].find(specifier); let Some(relative_index) = maybe_relative_index else { return false; }; @@ -192,6 +191,7 @@ impl<'a> SpecifierUnfurler<'a> { diagnostic_reporter: &mut dyn FnMut(SpecifierUnfurlerDiagnostic), ) -> String { let mut text_changes = Vec::new(); + let text_info = parsed_source.text_info_lazy(); let module_info = ParserModuleAnalyzer::module_info(parsed_source); let analyze_specifier = |specifier: &str, @@ -199,7 +199,7 @@ impl<'a> SpecifierUnfurler<'a> { text_changes: &mut Vec<deno_ast::TextChange>| { if let Some(unfurled) = self.unfurl_specifier(url, specifier) { text_changes.push(deno_ast::TextChange { - range: to_range(parsed_source, range), + range: to_range(text_info, range), new_text: unfurled, }); } @@ -214,27 +214,19 @@ impl<'a> SpecifierUnfurler<'a> { ); } DependencyDescriptor::Dynamic(dep) => { - let success = self.try_unfurl_dynamic_dep( - url, - parsed_source, - dep, - &mut text_changes, - ); + let success = + self.try_unfurl_dynamic_dep(url, text_info, dep, &mut text_changes); if !success { - let start_pos = parsed_source - .text_info() - .line_start(dep.argument_range.start.line) + let start_pos = text_info.line_start(dep.argument_range.start.line) + dep.argument_range.start.character; - let end_pos = parsed_source - .text_info() - .line_start(dep.argument_range.end.line) + let end_pos = text_info.line_start(dep.argument_range.end.line) + dep.argument_range.end.character; diagnostic_reporter( SpecifierUnfurlerDiagnostic::UnanalyzableDynamicImport { specifier: url.to_owned(), range: SourceRange::new(start_pos, end_pos), - text_info: parsed_source.text_info().clone(), + text_info: text_info.clone(), }, ); } @@ -267,10 +259,8 @@ impl<'a> SpecifierUnfurler<'a> { ); } - let rewritten_text = deno_ast::apply_text_changes( - parsed_source.text_info().text_str(), - text_changes, - ); + let rewritten_text = + deno_ast::apply_text_changes(text_info.text_str(), text_changes); rewritten_text } } @@ -295,13 +285,13 @@ fn relative_url( } fn to_range( - parsed_source: &ParsedSource, + text_info: &SourceTextInfo, range: &deno_graph::PositionRange, ) -> std::ops::Range<usize> { let mut range = range - .as_source_range(parsed_source.text_info()) - .as_byte_range(parsed_source.text_info().range().start); - let text = &parsed_source.text_info().text_str()[range.clone()]; + .as_source_range(text_info) + .as_byte_range(text_info.range().start); + let text = &text_info.text_str()[range.clone()]; if text.starts_with('"') || text.starts_with('\'') { range.start += 1; } @@ -338,7 +328,7 @@ mod tests { capture_tokens: false, maybe_syntax: None, scope_analysis: false, - text_info: deno_ast::SourceTextInfo::new(source_code.into()), + text: source_code.into(), }) .unwrap() } diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 1bc8a96d0..b122713c0 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -639,10 +639,11 @@ impl ReplSession { source_map: deno_ast::SourceMapOption::None, source_map_file: None, inline_sources: false, - keep_comments: false, + remove_comments: false, }, )? .into_source() + .into_string()? .text; let value = self @@ -817,7 +818,7 @@ fn parse_source_as( let parsed = deno_ast::parse_module(deno_ast::ParseParams { specifier, - text_info: deno_ast::SourceTextInfo::from_string(source), + text: source.into(), media_type, capture_tokens: true, maybe_syntax: None, @@ -884,7 +885,7 @@ fn analyze_jsx_pragmas( range: comment_source_to_position_range( c.start(), &m, - parsed_source.text_info(), + parsed_source.text_info_lazy(), true, ), }); @@ -898,7 +899,7 @@ fn analyze_jsx_pragmas( range: comment_source_to_position_range( c.start(), &m, - parsed_source.text_info(), + parsed_source.text_info_lazy(), false, ), }); @@ -912,7 +913,7 @@ fn analyze_jsx_pragmas( range: comment_source_to_position_range( c.start(), &m, - parsed_source.text_info(), + parsed_source.text_info_lazy(), false, ), }); diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index fa69ad950..06ff39abe 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -1249,7 +1249,7 @@ fn extract_files_from_source_comments( ) -> Result<Vec<File>, AnyError> { let parsed_source = deno_ast::parse_module(deno_ast::ParseParams { specifier: specifier.clone(), - text_info: deno_ast::SourceTextInfo::new(source), + text: source, media_type, capture_tokens: false, maybe_syntax: None, @@ -1273,7 +1273,7 @@ fn extract_files_from_source_comments( specifier, &comment.text, media_type, - parsed_source.text_info().line_index(comment.start()), + parsed_source.text_info_lazy().line_index(comment.start()), blocks_regex, lines_regex, ) @@ -1877,7 +1877,7 @@ pub async fn run_tests_with_watch( let test_modules_to_reload = if let Some(changed_paths) = changed_paths { - let mut result = Vec::new(); + let mut result = IndexSet::with_capacity(test_modules.len()); let changed_paths = changed_paths.into_iter().collect::<HashSet<_>>(); for test_module_specifier in test_modules { if has_graph_root_local_dependent_changed( @@ -1885,7 +1885,7 @@ pub async fn run_tests_with_watch( test_module_specifier, &changed_paths, ) { - result.push(test_module_specifier.clone()); + result.insert(test_module_specifier.clone()); } } result diff --git a/cli/tools/vendor/analyze.rs b/cli/tools/vendor/analyze.rs index 2b00f6bf4..3e5964be6 100644 --- a/cli/tools/vendor/analyze.rs +++ b/cli/tools/vendor/analyze.rs @@ -64,7 +64,6 @@ mod test { use deno_ast::ModuleSpecifier; use deno_ast::ParseParams; use deno_ast::ParsedSource; - use deno_ast::SourceTextInfo; use super::has_default_export; @@ -107,7 +106,7 @@ mod test { maybe_syntax: None, media_type: MediaType::TypeScript, scope_analysis: false, - text_info: SourceTextInfo::from_string(text.to_string()), + text: text.into(), }) .unwrap() } diff --git a/cli/tools/vendor/build.rs b/cli/tools/vendor/build.rs index fd7401f77..5aef63192 100644 --- a/cli/tools/vendor/build.rs +++ b/cli/tools/vendor/build.rs @@ -118,7 +118,7 @@ pub async fn build< graph_util::graph_valid( &graph, &real_fs, - &graph.roots, + &graph.roots.iter().cloned().collect::<Vec<_>>(), graph_util::GraphValidOptions { is_vendoring: true, check_js: true, diff --git a/cli/tools/vendor/import_map.rs b/cli/tools/vendor/import_map.rs index 7f627f35e..68f2530d7 100644 --- a/cli/tools/vendor/import_map.rs +++ b/cli/tools/vendor/import_map.rs @@ -250,7 +250,7 @@ fn visit_modules( let parsed_source = parsed_source_cache.get_parsed_source_from_js_module(module)?; - let text_info = parsed_source.text_info().clone(); + let text_info = parsed_source.text_info_lazy().clone(); for dep in module.dependencies.values() { visit_resolution( |
