summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-01-13 11:58:00 -0500
committerGitHub <noreply@github.com>2022-01-13 11:58:00 -0500
commitf12164646ba8327e9e6275b0ab97602f85e9854f (patch)
tree1668ac008ac455d38d9eacd70dec4ed7f1d542c2 /cli/tools
parent5e2d7737f5542c02572aa6585c8a6a78c84ae5ab (diff)
refactor: move transpiling to deno_ast (#13332)
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/doc.rs14
-rw-r--r--cli/tools/repl/session.rs19
-rw-r--r--cli/tools/test.rs25
3 files changed, 25 insertions, 33 deletions
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index 5b258a540..1ef2e29eb 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -30,10 +30,10 @@ struct StubDocLoader;
impl Loader for StubDocLoader {
fn load(
&mut self,
- specifier: &ModuleSpecifier,
+ _specifier: &ModuleSpecifier,
_is_dynamic: bool,
) -> LoadFuture {
- Box::pin(future::ready((specifier.clone(), Ok(None))))
+ Box::pin(future::ready(Ok(None)))
}
}
@@ -74,18 +74,16 @@ impl Loader for DocLoader {
let specifier = specifier.clone();
let ps = self.ps.clone();
async move {
- let result = ps
- .file_fetcher
+ ps.file_fetcher
.fetch(&specifier, &mut Permissions::allow_all())
.await
.map(|file| {
Some(LoadResponse {
- specifier: specifier.clone(),
+ specifier,
content: file.source.clone(),
maybe_headers: file.maybe_headers,
})
- });
- (specifier.clone(), result)
+ })
}
.boxed_local()
}
@@ -113,6 +111,7 @@ pub async fn print_docs(
None,
None,
None,
+ None,
)
.await;
let doc_parser =
@@ -152,6 +151,7 @@ pub async fn print_docs(
Some(&resolver),
None,
None,
+ None,
)
.await;
let doc_parser =
diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs
index d8276396a..5d458189f 100644
--- a/cli/tools/repl/session.rs
+++ b/cli/tools/repl/session.rs
@@ -1,10 +1,9 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-use crate::ast::transpile;
-use crate::ast::Diagnostics;
-use crate::ast::ImportsNotUsedAsValues;
use crate::colors;
use crate::lsp::ReplLanguageServer;
+use deno_ast::DiagnosticsError;
+use deno_ast::ImportsNotUsedAsValues;
use deno_core::error::AnyError;
use deno_core::futures::FutureExt;
use deno_core::serde_json::json;
@@ -184,7 +183,7 @@ impl ReplSession {
Some(diagnostic) => {
Ok(EvaluationOutput::Error(format_diagnostic(diagnostic)))
}
- None => match err.downcast_ref::<Diagnostics>() {
+ None => match err.downcast_ref::<DiagnosticsError>() {
Some(diagnostics) => Ok(EvaluationOutput::Error(
diagnostics
.0
@@ -311,9 +310,8 @@ impl ReplSession {
scope_analysis: false,
})?;
- let transpiled_src = transpile(
- &parsed_module,
- &crate::ast::EmitOptions {
+ let transpiled_src = parsed_module
+ .transpile(&deno_ast::EmitOptions {
emit_metadata: false,
source_map: false,
inline_source_map: false,
@@ -326,10 +324,9 @@ impl ReplSession {
jsx_factory: "React.createElement".into(),
jsx_fragment_factory: "React.Fragment".into(),
jsx_import_source: None,
- repl_imports: true,
- },
- )?
- .0;
+ var_decl_imports: true,
+ })?
+ .text;
let value = self
.evaluate_expression(&format!(
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index e5f03a19c..d991ef1ec 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -1,6 +1,5 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-use crate::ast::Location;
use crate::cache;
use crate::cache::CacherLoader;
use crate::colors;
@@ -535,9 +534,10 @@ async fn test_specifier(
}
fn extract_files_from_regex_blocks(
- location: &Location,
+ specifier: &ModuleSpecifier,
source: &str,
media_type: MediaType,
+ file_line_index: usize,
blocks_regex: &Regex,
lines_regex: &Regex,
) -> Result<Vec<File>, AnyError> {
@@ -594,9 +594,9 @@ fn extract_files_from_regex_blocks(
let file_specifier = deno_core::resolve_url_or_path(&format!(
"{}${}-{}{}",
- location.specifier,
- location.line + line_offset,
- location.line + line_offset + line_count,
+ specifier,
+ file_line_index + line_offset + 1,
+ file_line_index + line_offset + line_count + 1,
file_media_type.as_ts_extension(),
))
.unwrap();
@@ -642,12 +642,11 @@ fn extract_files_from_source_comments(
true
})
.flat_map(|comment| {
- let location = Location::from_pos(&parsed_source, comment.span.lo);
-
extract_files_from_regex_blocks(
- &location,
+ specifier,
&comment.text,
media_type,
+ parsed_source.source().line_index(comment.span.lo),
&blocks_regex,
&lines_regex,
)
@@ -663,19 +662,14 @@ fn extract_files_from_fenced_blocks(
source: &str,
media_type: MediaType,
) -> Result<Vec<File>, AnyError> {
- let location = Location {
- specifier: specifier.to_string(),
- line: 1,
- col: 0,
- };
-
let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?;
let lines_regex = Regex::new(r"(?:\# ?)?(.*)")?;
extract_files_from_regex_blocks(
- &location,
+ specifier,
source,
media_type,
+ /* file line index */ 0,
&blocks_regex,
&lines_regex,
)
@@ -1150,6 +1144,7 @@ pub async fn run_tests_with_watch(
maybe_resolver,
maybe_locker,
None,
+ None,
)
.await;
graph_valid(&graph, !no_check, check_js)?;