summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/module_graph.rs42
-rw-r--r--cli/tests/fix_emittable_skipped.js7
-rw-r--r--cli/tests/fix_emittable_skipped.ts.out2
-rw-r--r--cli/tests/integration_tests.rs5
-rw-r--r--cli/tests/subdir/emittable.d.ts1
-rw-r--r--cli/tests/subdir/polyfill.ts10
6 files changed, 60 insertions, 7 deletions
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index 4d0a4419f..08f6c5f32 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -774,7 +774,7 @@ impl Graph {
info!("{} {}", colors::green("Check"), specifier);
}
- let root_names = self.get_root_names();
+ let root_names = self.get_root_names(!config.get_check_js());
let maybe_tsbuildinfo = self.maybe_tsbuildinfo.clone();
let hash_data =
vec![config.as_bytes(), version::DENO.as_bytes().to_owned()];
@@ -896,7 +896,7 @@ impl Graph {
None
};
- let root_names = self.get_root_names();
+ let root_names = self.get_root_names(!config.get_check_js());
let hash_data =
vec![config.as_bytes(), version::DENO.as_bytes().to_owned()];
let graph = Rc::new(RefCell::new(self));
@@ -1152,10 +1152,37 @@ impl Graph {
/// Transform `self.roots` into something that works for `tsc`, because `tsc`
/// doesn't like root names without extensions that match its expectations,
/// nor does it have any concept of redirection, so we have to resolve all
- /// that upfront before feeding it to `tsc`.
- fn get_root_names(&self) -> Vec<(ModuleSpecifier, MediaType)> {
- self
- .roots
+ /// that upfront before feeding it to `tsc`. In addition, if checkJs is not
+ /// true, we should pass all emittable files in as the roots, so that `tsc`
+ /// type checks them and potentially emits them.
+ fn get_root_names(
+ &self,
+ include_emittable: bool,
+ ) -> Vec<(ModuleSpecifier, MediaType)> {
+ let root_names: Vec<ModuleSpecifier> = if include_emittable {
+ // in situations where there is `allowJs` with tsc, but not `checkJs`,
+ // then tsc will not parse the whole module graph, meaning that any
+ // JavaScript importing TypeScript will get ignored, meaning that those
+ // files will not get emitted. To counter act that behavior, we will
+ // include all modules that are emittable.
+ let mut specifiers = HashSet::<&ModuleSpecifier>::new();
+ for (_, module) in self.modules.iter() {
+ if module.media_type == MediaType::JSX
+ || module.media_type == MediaType::TypeScript
+ || module.media_type == MediaType::TSX
+ {
+ specifiers.insert(&module.specifier);
+ }
+ }
+ // We should include all the original roots as well.
+ for specifier in self.roots.iter() {
+ specifiers.insert(specifier);
+ }
+ specifiers.into_iter().cloned().collect()
+ } else {
+ self.roots.clone()
+ };
+ root_names
.iter()
.map(|ms| {
// if the root module has a types specifier, we should be sending that
@@ -1417,9 +1444,10 @@ impl Graph {
if module.media_type == MediaType::Dts {
continue;
}
- // if we don't have check_js enabled, we won't touch non TypeScript
+ // if we don't have check_js enabled, we won't touch non TypeScript or JSX
// modules
if !(emit_options.check_js
+ || module.media_type == MediaType::JSX
|| module.media_type == MediaType::TSX
|| module.media_type == MediaType::TypeScript)
{
diff --git a/cli/tests/fix_emittable_skipped.js b/cli/tests/fix_emittable_skipped.js
new file mode 100644
index 000000000..f61907b06
--- /dev/null
+++ b/cli/tests/fix_emittable_skipped.js
@@ -0,0 +1,7 @@
+/// <reference types="./subdir/emittable.d.ts" />
+
+import "./subdir/polyfill.ts";
+
+export const a = "a";
+
+console.log(globalThis.polyfill);
diff --git a/cli/tests/fix_emittable_skipped.ts.out b/cli/tests/fix_emittable_skipped.ts.out
new file mode 100644
index 000000000..108c2d67f
--- /dev/null
+++ b/cli/tests/fix_emittable_skipped.ts.out
@@ -0,0 +1,2 @@
+[WILDCARD]
+[Function]
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 6aa2c8a9d..16be10900 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -2865,6 +2865,11 @@ itest!(tsx_imports {
output: "tsx_imports.ts.out",
});
+itest!(fix_emittable_skipped {
+ args: "run --reload fix_emittable_skipped.js",
+ output: "fix_emittable_skipped.ts.out",
+});
+
itest!(fix_exotic_specifiers {
args: "run --quiet --reload fix_exotic_specifiers.ts",
output: "fix_exotic_specifiers.ts.out",
diff --git a/cli/tests/subdir/emittable.d.ts b/cli/tests/subdir/emittable.d.ts
new file mode 100644
index 000000000..425b80f24
--- /dev/null
+++ b/cli/tests/subdir/emittable.d.ts
@@ -0,0 +1 @@
+export const a: string;
diff --git a/cli/tests/subdir/polyfill.ts b/cli/tests/subdir/polyfill.ts
new file mode 100644
index 000000000..e1cd923cb
--- /dev/null
+++ b/cli/tests/subdir/polyfill.ts
@@ -0,0 +1,10 @@
+declare global {
+ const polyfill: () => void;
+}
+
+export {};
+
+// deno-lint-ignore no-explicit-any
+(globalThis as any).polyfill = () => {
+ console.log("polyfill");
+};