summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiorgi Rostomashvili <rostogiorgi@gmail.com>2020-04-06 22:52:25 +0200
committerGitHub <noreply@github.com>2020-04-06 16:52:25 -0400
commitf82b9ba329856b9b52c831b456e4823fad62f858 (patch)
tree9ec09d8c551a7269445fe2741c77bc951ba491a0
parentee126eb4a72ba757cc819dc3656f1ab89666ce81 (diff)
fix: fetch reference types for JS files (#4652)
Fixes #4000 and fixes #4476. Now always tries to fetch reference types for JS files. Does not throw if it fails, since Typescript compiler will complain if the file is not there(it will try to fetch it again first) and people who just use JS should not be bothered by this error. Not sure about my test, it passes and catches the bug but maybe there is a better way to express it.
-rw-r--r--cli/global_state.rs12
-rw-r--r--cli/tests/integration_tests.rs7
-rw-r--r--cli/tests/type_directives_js_main.js3
-rw-r--r--cli/tests/type_directives_js_main.js.out3
4 files changed, 25 insertions, 0 deletions
diff --git a/cli/global_state.rs b/cli/global_state.rs
index 129ab276a..c9383bd88 100644
--- a/cli/global_state.rs
+++ b/cli/global_state.rs
@@ -138,6 +138,18 @@ impl GlobalState {
.compile(state1.clone(), &out, target_lib)
.await
} else {
+ if let Some(types_url) = out.types_url.clone() {
+ let types_specifier = ModuleSpecifier::from(types_url);
+ state1
+ .file_fetcher
+ .fetch_source_file(
+ &types_specifier,
+ Some(module_specifier.clone()),
+ )
+ .await
+ .ok();
+ };
+
state1.js_compiler.compile(out).await
}
}
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 227566432..bef4c8d56 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -1415,6 +1415,13 @@ itest!(type_directives_02 {
output: "type_directives_02.ts.out",
});
+itest!(type_directives_js_main {
+ args: "run --reload -L debug type_directives_js_main.js",
+ output: "type_directives_js_main.js.out",
+ check_stderr: true,
+ exit_code: 0,
+});
+
itest!(types {
args: "types",
output: "types.out",
diff --git a/cli/tests/type_directives_js_main.js b/cli/tests/type_directives_js_main.js
new file mode 100644
index 000000000..f7274bf26
--- /dev/null
+++ b/cli/tests/type_directives_js_main.js
@@ -0,0 +1,3 @@
+import * as foo from "./subdir/type_reference.js";
+
+console.log(foo.foo);
diff --git a/cli/tests/type_directives_js_main.js.out b/cli/tests/type_directives_js_main.js.out
new file mode 100644
index 000000000..714dbd0b7
--- /dev/null
+++ b/cli/tests/type_directives_js_main.js.out
@@ -0,0 +1,3 @@
+[WILDCARD]
+fetch_source_file specifier: file:[WILDCARD]cli/tests/subdir/type_reference.d.ts
+[WILDCARD] \ No newline at end of file