diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2021-05-13 08:07:22 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-13 08:07:22 +0900 |
commit | e8a7f237de30a8291f97e318ba79382b65a8d228 (patch) | |
tree | 296ab382a42ff499c41ac6d68f9ee19b1bda3bbd /cli/file_fetcher.rs | |
parent | ea83f18f9009a9201b876a1fbe006e194116bd8d (diff) |
fix(cli): ignore x-typescript-types header when media type is not js/jsx (#10574)
Diffstat (limited to 'cli/file_fetcher.rs')
-rw-r--r-- | cli/file_fetcher.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 471873195..7ab2f5cce 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -327,7 +327,12 @@ impl FileFetcher { let (media_type, maybe_charset) = map_content_type(specifier, maybe_content_type); let source = strip_shebang(get_source_from_bytes(bytes, maybe_charset)?); - let maybe_types = headers.get("x-typescript-types").cloned(); + let maybe_types = match media_type { + MediaType::JavaScript | MediaType::Jsx => { + headers.get("x-typescript-types").cloned() + } + _ => None, + }; Ok(File { local, @@ -1593,7 +1598,7 @@ mod tests { } #[tokio::test] - async fn test_fetch_remote_with_types() { + async fn test_fetch_remote_javascript_with_types() { let specifier = resolve_url_or_path("http://127.0.0.1:4545/xTypeScriptTypes.js").unwrap(); let (file, _) = test_fetch_remote(&specifier).await; @@ -1604,6 +1609,27 @@ mod tests { } #[tokio::test] + async fn test_fetch_remote_jsx_with_types() { + let specifier = + resolve_url_or_path("http://127.0.0.1:4545/xTypeScriptTypes.jsx") + .unwrap(); + let (file, _) = test_fetch_remote(&specifier).await; + assert_eq!(file.media_type, MediaType::Jsx,); + assert_eq!( + file.maybe_types, + Some("./xTypeScriptTypes.d.ts".to_string()) + ); + } + + #[tokio::test] + async fn test_fetch_remote_typescript_with_types() { + let specifier = + resolve_url_or_path("http://127.0.0.1:4545/xTypeScriptTypes.ts").unwrap(); + let (file, _) = test_fetch_remote(&specifier).await; + assert_eq!(file.maybe_types, None); + } + + #[tokio::test] async fn test_fetch_remote_utf16_le() { let expected = std::str::from_utf8(b"\xEF\xBB\xBFconsole.log(\"Hello World\");\x0A") |