summaryrefslogtreecommitdiff
path: root/cli/tools/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools/test.rs')
-rw-r--r--cli/tools/test.rs42
1 files changed, 25 insertions, 17 deletions
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 859e23934..dc1cd643f 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -1,6 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-use crate::ast;
use crate::ast::Location;
use crate::colors;
use crate::create_main_worker;
@@ -12,7 +11,6 @@ use crate::fs_util::collect_specifiers;
use crate::fs_util::is_supported_test_ext;
use crate::fs_util::is_supported_test_path;
use crate::located_script_name;
-use crate::media_type::MediaType;
use crate::module_graph;
use crate::module_graph::GraphBuilder;
use crate::module_graph::Module;
@@ -22,6 +20,8 @@ use crate::program_state::ProgramState;
use crate::tokio_util;
use crate::tools::coverage::CoverageCollector;
use crate::FetchHandler;
+use deno_ast::swc::common::comments::CommentKind;
+use deno_ast::MediaType;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
use deno_core::futures::future;
@@ -47,7 +47,6 @@ use std::sync::mpsc::Sender;
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;
-use swc_common::comments::CommentKind;
use uuid::Uuid;
/// The test mode is used to determine how a specifier is to be tested.
@@ -269,7 +268,7 @@ async fn test_specifier(
local: test_specifier.to_file_path().unwrap(),
maybe_types: None,
media_type: MediaType::JavaScript,
- source: test_source.clone(),
+ source: Arc::new(test_source),
specifier: test_specifier.clone(),
maybe_headers: None,
};
@@ -344,7 +343,7 @@ async fn test_specifier(
fn extract_files_from_regex_blocks(
location: &Location,
source: &str,
- media_type: &MediaType,
+ media_type: MediaType,
blocks_regex: &Regex,
lines_regex: &Regex,
) -> Result<Vec<File>, AnyError> {
@@ -365,11 +364,11 @@ fn extract_files_from_regex_blocks(
Some(&"jsx") => MediaType::Jsx,
Some(&"ts") => MediaType::TypeScript,
Some(&"tsx") => MediaType::Tsx,
- Some(&"") => *media_type,
+ Some(&"") => media_type,
_ => MediaType::Unknown,
}
} else {
- *media_type
+ media_type
};
if file_media_type == MediaType::Unknown {
@@ -408,7 +407,7 @@ fn extract_files_from_regex_blocks(
local: file_specifier.to_file_path().unwrap(),
maybe_types: None,
media_type: file_media_type,
- source: file_source,
+ source: Arc::new(file_source),
specifier: file_specifier,
maybe_headers: None,
})
@@ -420,11 +419,20 @@ fn extract_files_from_regex_blocks(
fn extract_files_from_source_comments(
specifier: &ModuleSpecifier,
- source: &str,
- media_type: &MediaType,
+ source: Arc<String>,
+ media_type: MediaType,
) -> Result<Vec<File>, AnyError> {
- let parsed_module = ast::parse(specifier.as_str(), source, media_type)?;
- let comments = parsed_module.get_comments();
+ let parsed_source = deno_ast::parse_module(deno_ast::ParseParams {
+ specifier: specifier.as_str().to_string(),
+ source: deno_ast::SourceTextInfo::new(
+ deno_ast::swc::common::BytePos(0),
+ source,
+ ),
+ media_type,
+ capture_tokens: false,
+ maybe_syntax: None,
+ })?;
+ let comments = parsed_source.comments().get_vec();
let blocks_regex = Regex::new(r"```([^\n]*)\n([\S\s]*?)```")?;
let lines_regex = Regex::new(r"(?:\* ?)(?:\# ?)?(.*)")?;
@@ -438,7 +446,7 @@ fn extract_files_from_source_comments(
true
})
.flat_map(|comment| {
- let location = parsed_module.get_location(comment.span.lo);
+ let location = Location::from_pos(&parsed_source, comment.span.lo);
extract_files_from_regex_blocks(
&location,
@@ -457,7 +465,7 @@ fn extract_files_from_source_comments(
fn extract_files_from_fenced_blocks(
specifier: &ModuleSpecifier,
source: &str,
- media_type: &MediaType,
+ media_type: MediaType,
) -> Result<Vec<File>, AnyError> {
let location = Location {
specifier: specifier.to_string(),
@@ -493,13 +501,13 @@ async fn fetch_inline_files(
extract_files_from_fenced_blocks(
&file.specifier,
&file.source,
- &file.media_type,
+ file.media_type,
)
} else {
extract_files_from_source_comments(
&file.specifier,
- &file.source,
- &file.media_type,
+ file.source.clone(),
+ file.media_type,
)
};