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
21
cli/emit.rs
21
cli/emit.rs
|
@ -199,15 +199,13 @@ pub fn get_ts_config_for_emit(
|
|||
/// 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
|
||||
/// 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
|
||||
/// the emittable files in the roots, so they get type checked and optionally
|
||||
/// emitted, otherwise they would be ignored if only imported into JavaScript.
|
||||
/// redirects resolved. We need to include all the emittable files in
|
||||
/// the roots, so they get type checked and optionally emitted,
|
||||
/// otherwise they would be ignored if only imported into JavaScript.
|
||||
fn get_tsc_roots(
|
||||
roots: &[(ModuleSpecifier, ModuleKind)],
|
||||
graph_data: &GraphData,
|
||||
check_js: bool,
|
||||
) -> Vec<(ModuleSpecifier, MediaType)> {
|
||||
if !check_js {
|
||||
graph_data
|
||||
.entries()
|
||||
.into_iter()
|
||||
|
@ -232,17 +230,6 @@ fn get_tsc_roots(
|
|||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
} else {
|
||||
roots
|
||||
.iter()
|
||||
.filter_map(|(specifier, _)| match graph_data.get(specifier) {
|
||||
Some(ModuleEntry::Module { media_type, .. }) => {
|
||||
Some((specifier.clone(), *media_type))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// A hashing function that takes the source code, version and optionally a
|
||||
|
@ -328,7 +315,7 @@ pub fn check(
|
|||
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 {
|
||||
for (root, _) in roots {
|
||||
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'.");
|
||||
}
|
||||
|
||||
// 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 {
|
||||
args: "run --quiet --unstable --no-prompt no_prompt.ts",
|
||||
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