mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix(cli): expand tsc roots when using checkJs (#15164)
A JS file can still point to a TS file, so we need to expand the roots in the checkJs case too. Fixes: #15163
This commit is contained in:
parent
2423f83ca8
commit
a34ed568e9
7 changed files with 46 additions and 38 deletions
63
cli/emit.rs
63
cli/emit.rs
|
@ -199,50 +199,37 @@ pub fn get_ts_config_for_emit(
|
||||||
/// Transform the graph into root specifiers that we can feed `tsc`. We have to
|
/// Transform the graph into root specifiers that we can feed `tsc`. We have to
|
||||||
/// provide the media type for root modules because `tsc` does not "resolve" the
|
/// provide the media type for root modules because `tsc` does not "resolve" the
|
||||||
/// media type like other modules, as well as a root specifier needs any
|
/// media type like other modules, as well as a root specifier needs any
|
||||||
/// redirects resolved. If we aren't checking JavaScript, we need to include all
|
/// redirects resolved. We need to include all the emittable files in
|
||||||
/// the emittable files in the roots, so they get type checked and optionally
|
/// the roots, so they get type checked and optionally emitted,
|
||||||
/// emitted, otherwise they would be ignored if only imported into JavaScript.
|
/// otherwise they would be ignored if only imported into JavaScript.
|
||||||
fn get_tsc_roots(
|
fn get_tsc_roots(
|
||||||
roots: &[(ModuleSpecifier, ModuleKind)],
|
|
||||||
graph_data: &GraphData,
|
graph_data: &GraphData,
|
||||||
check_js: bool,
|
check_js: bool,
|
||||||
) -> Vec<(ModuleSpecifier, MediaType)> {
|
) -> Vec<(ModuleSpecifier, MediaType)> {
|
||||||
if !check_js {
|
graph_data
|
||||||
graph_data
|
.entries()
|
||||||
.entries()
|
.into_iter()
|
||||||
.into_iter()
|
.filter_map(|(specifier, module_entry)| match module_entry {
|
||||||
.filter_map(|(specifier, module_entry)| match module_entry {
|
ModuleEntry::Module {
|
||||||
ModuleEntry::Module {
|
media_type,
|
||||||
media_type,
|
ts_check,
|
||||||
ts_check,
|
..
|
||||||
..
|
} => match &media_type {
|
||||||
} => match &media_type {
|
MediaType::TypeScript
|
||||||
MediaType::TypeScript
|
| MediaType::Tsx
|
||||||
| MediaType::Tsx
|
| MediaType::Mts
|
||||||
| MediaType::Mts
|
| MediaType::Cts
|
||||||
| MediaType::Cts
|
| MediaType::Jsx => Some((specifier.clone(), *media_type)),
|
||||||
| MediaType::Jsx => Some((specifier.clone(), *media_type)),
|
MediaType::JavaScript | MediaType::Mjs | MediaType::Cjs
|
||||||
MediaType::JavaScript | MediaType::Mjs | MediaType::Cjs
|
if check_js || *ts_check =>
|
||||||
if check_js || *ts_check =>
|
{
|
||||||
{
|
|
||||||
Some((specifier.clone(), *media_type))
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
} else {
|
|
||||||
roots
|
|
||||||
.iter()
|
|
||||||
.filter_map(|(specifier, _)| match graph_data.get(specifier) {
|
|
||||||
Some(ModuleEntry::Module { media_type, .. }) => {
|
|
||||||
Some((specifier.clone(), *media_type))
|
Some((specifier.clone(), *media_type))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
},
|
||||||
.collect()
|
_ => None,
|
||||||
}
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A hashing function that takes the source code, version and optionally a
|
/// A hashing function that takes the source code, version and optionally a
|
||||||
|
@ -328,7 +315,7 @@ pub fn check(
|
||||||
return Ok(Default::default());
|
return Ok(Default::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
let root_names = get_tsc_roots(roots, &segment_graph_data, check_js);
|
let root_names = get_tsc_roots(&segment_graph_data, check_js);
|
||||||
if options.log_checks {
|
if options.log_checks {
|
||||||
for (root, _) in roots {
|
for (root, _) in roots {
|
||||||
let root_str = root.to_string();
|
let root_str = root.to_string();
|
||||||
|
|
|
@ -2701,6 +2701,13 @@ fn check_local_then_remote() {
|
||||||
assert_contains!(stderr, "Type 'string' is not assignable to type 'number'.");
|
assert_contains!(stderr, "Type 'string' is not assignable to type 'number'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression test for https://github.com/denoland/deno/issues/15163
|
||||||
|
itest!(check_js_points_to_ts {
|
||||||
|
args: "run --quiet --check --config checkjs.tsconfig.json run/check_js_points_to_ts/test.js",
|
||||||
|
output: "run/check_js_points_to_ts/test.js.out",
|
||||||
|
exit_code: 1,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(no_prompt_flag {
|
itest!(no_prompt_flag {
|
||||||
args: "run --quiet --unstable --no-prompt no_prompt.ts",
|
args: "run --quiet --unstable --no-prompt no_prompt.ts",
|
||||||
output_str: Some(""),
|
output_str: Some(""),
|
||||||
|
|
3
cli/tests/testdata/run/check_js_points_to_ts/bar.ts
vendored
Normal file
3
cli/tests/testdata/run/check_js_points_to_ts/bar.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export function bar(): string {
|
||||||
|
return 42;
|
||||||
|
}
|
0
cli/tests/testdata/run/check_js_points_to_ts/foo.d.ts
vendored
Normal file
0
cli/tests/testdata/run/check_js_points_to_ts/foo.d.ts
vendored
Normal file
4
cli/tests/testdata/run/check_js_points_to_ts/foo.js
vendored
Normal file
4
cli/tests/testdata/run/check_js_points_to_ts/foo.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import { bar } from "./bar.ts";
|
||||||
|
export function foo() {
|
||||||
|
bar();
|
||||||
|
}
|
3
cli/tests/testdata/run/check_js_points_to_ts/test.js
vendored
Normal file
3
cli/tests/testdata/run/check_js_points_to_ts/test.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
// @deno-types="./foo.d.ts"
|
||||||
|
import { foo } from "./foo.js";
|
||||||
|
foo();
|
4
cli/tests/testdata/run/check_js_points_to_ts/test.js.out
vendored
Normal file
4
cli/tests/testdata/run/check_js_points_to_ts/test.js.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
|
||||||
|
return 42;
|
||||||
|
~~~~~~~~~~
|
||||||
|
at [WILDCARD]
|
Loading…
Reference in a new issue