summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-11-07 06:53:37 +1100
committerGitHub <noreply@github.com>2020-11-07 06:53:37 +1100
commit4f67f0cc6033983540ed51f1270fb420cac45487 (patch)
tree6e62ed5357396014d938866c39c4ed6fc792d4f3
parent280ab920a8129248f536d4a49b53d5c71ba340f1 (diff)
fix(cli): properly handle type checking root modules with type defini… (#8263)
-rw-r--r--cli/module_graph.rs31
-rw-r--r--cli/tests/module_graph/file_typesref.d.ts1
-rw-r--r--cli/tests/module_graph/file_typesref.js3
3 files changed, 33 insertions, 2 deletions
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index 7a6d68086..9b3d79a94 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -1154,11 +1154,21 @@ impl Graph {
.roots
.iter()
.map(|ms| {
+ // if the root module has a types specifier, we should be sending that
+ // to tsc instead of the original specifier
+ let specifier = self.resolve_specifier(ms);
+ let module = self.get_module(specifier).unwrap();
+ let specifier = if let Some((_, types_specifier)) = &module.maybe_types
+ {
+ self.resolve_specifier(types_specifier)
+ } else {
+ specifier
+ };
(
// root modules can be redirects, so before we pass it to tsc we need
// to resolve the redirect
- self.resolve_specifier(ms).clone(),
- self.get_media_type(ms).unwrap(),
+ specifier.clone(),
+ self.get_media_type(specifier).unwrap(),
)
})
.collect()
@@ -1935,6 +1945,23 @@ pub mod tests {
}
#[tokio::test]
+ async fn fix_graph_check_types_root() {
+ let specifier = ModuleSpecifier::resolve_url_or_path("file:///typesref.js")
+ .expect("could not resolve module");
+ let (graph, _) = setup(specifier).await;
+ let result_info = graph
+ .check(CheckOptions {
+ debug: false,
+ emit: false,
+ lib: TypeLib::DenoWindow,
+ maybe_config_path: None,
+ reload: false,
+ })
+ .expect("should have checked");
+ assert!(result_info.diagnostics.is_empty());
+ }
+
+ #[tokio::test]
async fn test_graph_check_user_config() {
let specifier =
ModuleSpecifier::resolve_url_or_path("file:///tests/checkwithconfig.ts")
diff --git a/cli/tests/module_graph/file_typesref.d.ts b/cli/tests/module_graph/file_typesref.d.ts
new file mode 100644
index 000000000..8ae31dde3
--- /dev/null
+++ b/cli/tests/module_graph/file_typesref.d.ts
@@ -0,0 +1 @@
+export const a: "a";
diff --git a/cli/tests/module_graph/file_typesref.js b/cli/tests/module_graph/file_typesref.js
new file mode 100644
index 000000000..79da24cae
--- /dev/null
+++ b/cli/tests/module_graph/file_typesref.js
@@ -0,0 +1,3 @@
+/// <reference types="./typesref.d.ts" />
+
+export const a = "a";