diff options
author | Rafael Ávila de Espíndola <espindola@chiselstrike.com> | 2022-07-14 14:40:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-14 10:40:47 -0400 |
commit | a34ed568e98d2f10f699f707841cab96847d3ce9 (patch) | |
tree | d919e3316a574393344c7a198b6cdf36f71ce9d1 /cli/emit.rs | |
parent | 2423f83ca87f5175791af90c05f00946de624d8e (diff) |
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
Diffstat (limited to 'cli/emit.rs')
-rw-r--r-- | cli/emit.rs | 63 |
1 files changed, 25 insertions, 38 deletions
diff --git a/cli/emit.rs b/cli/emit.rs index 924af49c4..c7a31fc0f 100644 --- a/cli/emit.rs +++ b/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 /// 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() - .filter_map(|(specifier, module_entry)| match module_entry { - ModuleEntry::Module { - media_type, - ts_check, - .. - } => match &media_type { - MediaType::TypeScript - | MediaType::Tsx - | MediaType::Mts - | MediaType::Cts - | MediaType::Jsx => Some((specifier.clone(), *media_type)), - MediaType::JavaScript | MediaType::Mjs | MediaType::Cjs - 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, .. }) => { + graph_data + .entries() + .into_iter() + .filter_map(|(specifier, module_entry)| match module_entry { + ModuleEntry::Module { + media_type, + ts_check, + .. + } => match &media_type { + MediaType::TypeScript + | MediaType::Tsx + | MediaType::Mts + | MediaType::Cts + | MediaType::Jsx => Some((specifier.clone(), *media_type)), + MediaType::JavaScript | MediaType::Mjs | MediaType::Cjs + if check_js || *ts_check => + { Some((specifier.clone(), *media_type)) } _ => None, - }) - .collect() - } + }, + _ => 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(); |