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.
This commit is contained in:
Giorgi Rostomashvili 2020-04-06 22:52:25 +02:00 committed by GitHub
parent ee126eb4a7
commit f82b9ba329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 0 deletions

View File

@ -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
}
}

View File

@ -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",

View File

@ -0,0 +1,3 @@
import * as foo from "./subdir/type_reference.js";
console.log(foo.foo);

View File

@ -0,0 +1,3 @@
[WILDCARD]
fetch_source_file specifier: file:[WILDCARD]cli/tests/subdir/type_reference.d.ts
[WILDCARD]