summaryrefslogtreecommitdiff
path: root/cli/graph_util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/graph_util.rs')
-rw-r--r--cli/graph_util.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/cli/graph_util.rs b/cli/graph_util.rs
index 11678574c..f2063108f 100644
--- a/cli/graph_util.rs
+++ b/cli/graph_util.rs
@@ -13,12 +13,18 @@ use deno_graph::ModuleGraphError;
use deno_graph::ModuleKind;
use deno_graph::Range;
use deno_graph::Resolved;
+use once_cell::sync::Lazy;
+use regex::Regex;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::sync::Arc;
+/// Matches the `@ts-check` pragma.
+static TS_CHECK_RE: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r#"(?i)^\s*@ts-check(?:\s+|$)"#).unwrap());
+
pub fn contains_specifier(
v: &[(ModuleSpecifier, ModuleKind)],
specifier: &ModuleSpecifier,
@@ -33,6 +39,8 @@ pub enum ModuleEntry {
code: Arc<String>,
dependencies: BTreeMap<String, Dependency>,
media_type: MediaType,
+ /// Whether or not this is a JS/JSX module with a `@ts-check` directive.
+ ts_check: bool,
/// A set of type libs that the module has passed a type check with this
/// session. This would consist of window, worker or both.
checked_libs: HashSet<TypeLib>,
@@ -122,9 +130,23 @@ impl GraphData {
}
}
}
+ let ts_check = match &media_type {
+ MediaType::JavaScript
+ | MediaType::Mjs
+ | MediaType::Cjs
+ | MediaType::Jsx => {
+ let parsed_source = module.maybe_parsed_source.as_ref().unwrap();
+ parsed_source
+ .get_leading_comments()
+ .iter()
+ .any(|c| TS_CHECK_RE.is_match(&c.text))
+ }
+ _ => false,
+ };
let module_entry = ModuleEntry::Module {
code,
dependencies: module.dependencies.clone(),
+ ts_check,
media_type,
checked_libs: Default::default(),
maybe_types,