summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/coverage/mod.rs11
-rw-r--r--cli/tools/doc.rs4
-rw-r--r--cli/tools/repl/editor.rs31
-rw-r--r--cli/tools/repl/mod.rs2
-rw-r--r--cli/tools/repl/session.rs2
-rw-r--r--cli/tools/test.rs9
-rw-r--r--cli/tools/vendor/analyze.rs2
-rw-r--r--cli/tools/vendor/import_map.rs12
-rw-r--r--cli/tools/vendor/test.rs3
9 files changed, 35 insertions, 41 deletions
diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs
index d68071085..f89aaf52b 100644
--- a/cli/tools/coverage/mod.rs
+++ b/cli/tools/coverage/mod.rs
@@ -175,12 +175,12 @@ fn generate_coverage_report(
.map(|source_map| SourceMap::from_slice(source_map).unwrap());
let text_lines = TextLines::new(script_source);
- let comment_spans = deno_ast::lex(script_source, MediaType::JavaScript)
+ let comment_ranges = deno_ast::lex(script_source, MediaType::JavaScript)
.into_iter()
.filter(|item| {
matches!(item.inner, deno_ast::TokenOrComment::Comment { .. })
})
- .map(|item| item.span)
+ .map(|item| item.range)
.collect::<Vec<_>>();
let url = Url::parse(&script_coverage.url).unwrap();
@@ -267,9 +267,8 @@ fn generate_coverage_report(
for line_index in 0..text_lines.lines_count() {
let line_start_offset = text_lines.line_start(line_index);
let line_end_offset = text_lines.line_end(line_index);
- let ignore = comment_spans.iter().any(|span| {
- (span.lo.0 as usize) <= line_start_offset
- && (span.hi.0 as usize) >= line_end_offset
+ let ignore = comment_ranges.iter().any(|range| {
+ range.start <= line_start_offset && range.end >= line_end_offset
}) || script_source[line_start_offset..line_end_offset]
.trim()
.is_empty();
@@ -664,7 +663,7 @@ pub async fn cover_files(
| MediaType::Unknown
| MediaType::Cjs
| MediaType::Mjs
- | MediaType::Json => file.source.as_ref().clone(),
+ | MediaType::Json => file.source.as_ref().to_string(),
MediaType::Dts | MediaType::Dmts | MediaType::Dcts => "".to_string(),
MediaType::TypeScript
| MediaType::Jsx
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index 36fc34e5b..a5826d1bc 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -122,7 +122,7 @@ pub async fn print_docs(
doc_parser.parse_source(
&source_file_specifier,
MediaType::Dts,
- Arc::new(get_types(ps.flags.unstable)),
+ get_types(ps.flags.unstable).into(),
)
} else {
let module_specifier = resolve_url_or_path(&source_file)?;
@@ -134,7 +134,7 @@ pub async fn print_docs(
local: PathBuf::from("./$deno$doc.ts"),
maybe_types: None,
media_type: MediaType::TypeScript,
- source: Arc::new(format!("export * from \"{}\";", module_specifier)),
+ source: format!("export * from \"{}\";", module_specifier).into(),
specifier: root_specifier.clone(),
maybe_headers: None,
};
diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs
index 43047e585..82719f27a 100644
--- a/cli/tools/repl/editor.rs
+++ b/cli/tools/repl/editor.rs
@@ -179,7 +179,7 @@ impl Completer for EditorHelper {
if !lsp_completions.is_empty() {
// assumes all lsp completions have the same start position
return Ok((
- lsp_completions[0].span.lo.0 as usize,
+ lsp_completions[0].range.start,
lsp_completions.into_iter().map(|c| c.new_text).collect(),
));
}
@@ -302,43 +302,40 @@ impl Highlighter for EditorHelper {
// Adding color adds more bytes to the string,
// so an offset is needed to stop spans falling out of sync.
let offset = out_line.len() - line.len();
- let span = std::ops::Range {
- start: item.span.lo.0 as usize,
- end: item.span.hi.0 as usize,
- };
+ let range = item.range;
out_line.replace_range(
- span.start + offset..span.end + offset,
+ range.start + offset..range.end + offset,
&match item.inner {
deno_ast::TokenOrComment::Token(token) => match token {
Token::Str { .. } | Token::Template { .. } | Token::BackQuote => {
- colors::green(&line[span]).to_string()
+ colors::green(&line[range]).to_string()
}
- Token::Regex(_, _) => colors::red(&line[span]).to_string(),
+ Token::Regex(_, _) => colors::red(&line[range]).to_string(),
Token::Num { .. } | Token::BigInt { .. } => {
- colors::yellow(&line[span]).to_string()
+ colors::yellow(&line[range]).to_string()
}
Token::Word(word) => match word {
Word::True | Word::False | Word::Null => {
- colors::yellow(&line[span]).to_string()
+ colors::yellow(&line[range]).to_string()
}
- Word::Keyword(_) => colors::cyan(&line[span]).to_string(),
+ Word::Keyword(_) => colors::cyan(&line[range]).to_string(),
Word::Ident(ident) => {
if ident == *"undefined" {
- colors::gray(&line[span]).to_string()
+ colors::gray(&line[range]).to_string()
} else if ident == *"Infinity" || ident == *"NaN" {
- colors::yellow(&line[span]).to_string()
+ colors::yellow(&line[range]).to_string()
} else if ident == *"async" || ident == *"of" {
- colors::cyan(&line[span]).to_string()
+ colors::cyan(&line[range]).to_string()
} else {
- line[span].to_string()
+ line[range].to_string()
}
}
},
- _ => line[span].to_string(),
+ _ => line[range].to_string(),
},
deno_ast::TokenOrComment::Comment { .. } => {
- colors::gray(&line[span]).to_string()
+ colors::gray(&line[range]).to_string()
}
},
);
diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs
index 7ca229ab3..110a89f14 100644
--- a/cli/tools/repl/mod.rs
+++ b/cli/tools/repl/mod.rs
@@ -70,7 +70,7 @@ async fn read_eval_file(
.fetch(&specifier, &mut Permissions::allow_all())
.await?;
- Ok((*file.source).clone())
+ Ok((*file.source).to_string())
}
pub async fn run(
diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs
index c256172e4..d5058ab72 100644
--- a/cli/tools/repl/session.rs
+++ b/cli/tools/repl/session.rs
@@ -332,7 +332,7 @@ impl ReplSession {
) -> Result<TsEvaluateResponse, AnyError> {
let parsed_module = deno_ast::parse_module(deno_ast::ParseParams {
specifier: "repl.ts".to_string(),
- source: deno_ast::SourceTextInfo::from_string(expression.to_string()),
+ text_info: deno_ast::SourceTextInfo::from_string(expression.to_string()),
media_type: deno_ast::MediaType::TypeScript,
capture_tokens: false,
maybe_syntax: None,
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 97507c536..4424ee28d 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -29,6 +29,7 @@ use crate::tools::coverage::CoverageCollector;
use deno_ast::swc::common::comments::CommentKind;
use deno_ast::MediaType;
+use deno_ast::SourceRangedForSpanned;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::error::JsError;
@@ -825,7 +826,7 @@ fn extract_files_from_regex_blocks(
local: file_specifier.to_file_path().unwrap(),
maybe_types: None,
media_type: file_media_type,
- source: Arc::new(file_source),
+ source: file_source.into(),
specifier: file_specifier,
maybe_headers: None,
})
@@ -837,12 +838,12 @@ fn extract_files_from_regex_blocks(
fn extract_files_from_source_comments(
specifier: &ModuleSpecifier,
- source: Arc<String>,
+ source: Arc<str>,
media_type: MediaType,
) -> Result<Vec<File>, AnyError> {
let parsed_source = deno_ast::parse_module(deno_ast::ParseParams {
specifier: specifier.as_str().to_string(),
- source: deno_ast::SourceTextInfo::new(source),
+ text_info: deno_ast::SourceTextInfo::new(source),
media_type,
capture_tokens: false,
maybe_syntax: None,
@@ -866,7 +867,7 @@ fn extract_files_from_source_comments(
specifier,
&comment.text,
media_type,
- parsed_source.source().line_index(comment.span.lo),
+ parsed_source.text_info().line_index(comment.start()),
&blocks_regex,
&lines_regex,
)
diff --git a/cli/tools/vendor/analyze.rs b/cli/tools/vendor/analyze.rs
index 0639c0487..6a1f53aae 100644
--- a/cli/tools/vendor/analyze.rs
+++ b/cli/tools/vendor/analyze.rs
@@ -106,7 +106,7 @@ mod test {
maybe_syntax: None,
media_type: MediaType::TypeScript,
scope_analysis: false,
- source: SourceTextInfo::from_string(text.to_string()),
+ text_info: SourceTextInfo::from_string(text.to_string()),
})
.unwrap()
}
diff --git a/cli/tools/vendor/import_map.rs b/cli/tools/vendor/import_map.rs
index 1df6e36d1..4bbdbd1ae 100644
--- a/cli/tools/vendor/import_map.rs
+++ b/cli/tools/vendor/import_map.rs
@@ -120,7 +120,7 @@ fn visit_modules(
) {
for module in modules {
let text_info = match &module.maybe_parsed_source {
- Some(source) => source.source(),
+ Some(source) => source.text_info(),
None => continue,
};
let source_text = match &module.maybe_source {
@@ -272,10 +272,8 @@ fn byte_range(
fn byte_index(text_info: &SourceTextInfo, pos: &Position) -> usize {
// todo(https://github.com/denoland/deno_graph/issues/79): use byte indexes all the way down
- text_info
- .byte_index(LineAndColumnIndex {
- line_index: pos.line,
- column_index: pos.character,
- })
- .0 as usize
+ text_info.loc_to_source_pos(LineAndColumnIndex {
+ line_index: pos.line,
+ column_index: pos.character,
+ }) - text_info.range().start
}
diff --git a/cli/tools/vendor/test.rs b/cli/tools/vendor/test.rs
index 7f4c18fca..5060c493a 100644
--- a/cli/tools/vendor/test.rs
+++ b/cli/tools/vendor/test.rs
@@ -5,7 +5,6 @@ use std::collections::HashMap;
use std::collections::HashSet;
use std::path::Path;
use std::path::PathBuf;
-use std::sync::Arc;
use deno_ast::ModuleSpecifier;
use deno_core::anyhow::anyhow;
@@ -97,7 +96,7 @@ impl Loader for TestLoader {
let result = self.files.get(specifier).map(|result| match result {
Ok(result) => Ok(LoadResponse::Module {
specifier: specifier.clone(),
- content: Arc::new(result.0.clone()),
+ content: result.0.clone().into(),
maybe_headers: result.1.clone(),
}),
Err(err) => Err(err),