mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(cli): properly handle type checking root modules with type defini… (#8263)
This commit is contained in:
parent
280ab920a8
commit
4f67f0cc60
3 changed files with 33 additions and 2 deletions
|
@ -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()
|
||||
|
@ -1934,6 +1944,23 @@ pub mod tests {
|
|||
assert_eq!(h.tsbuildinfo_calls.len(), 1);
|
||||
}
|
||||
|
||||
#[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 =
|
||||
|
|
1
cli/tests/module_graph/file_typesref.d.ts
vendored
Normal file
1
cli/tests/module_graph/file_typesref.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export const a: "a";
|
3
cli/tests/module_graph/file_typesref.js
Normal file
3
cli/tests/module_graph/file_typesref.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
/// <reference types="./typesref.d.ts" />
|
||||
|
||||
export const a = "a";
|
Loading…
Add table
Reference in a new issue