feat: TypeScript 5.0.2 (except decorators) (#18294)

This upgrades TypeScript to 5.0.2, but does not have ES decorator
support because swc does not support that yet.
This commit is contained in:
David Sherret 2023-03-21 11:46:40 -04:00 committed by GitHub
parent 0366d6833f
commit 2fcf1f14cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
111 changed files with 173492 additions and 178485 deletions

View file

@ -4,6 +4,7 @@ use std::borrow::Cow;
use std::path::Path;
use std::path::PathBuf;
use deno_ast::MediaType;
use deno_ast::ModuleSpecifier;
use deno_core::error::uri_error;
use deno_core::error::AnyError;
@ -28,6 +29,44 @@ pub fn get_extension(file_path: &Path) -> Option<String> {
.map(|e| e.to_lowercase());
}
/// TypeScript figures out the type of file based on the extension, but we take
/// other factors into account like the file headers. The hack here is to map the
/// specifier passed to TypeScript to a new specifier with the file extension.
pub fn mapped_specifier_for_tsc(
specifier: &ModuleSpecifier,
media_type: MediaType,
) -> Option<String> {
let ext_media_type = MediaType::from_specifier(specifier);
if media_type != ext_media_type {
// we can't just add on the extension because typescript considers
// all .d.*.ts files as declaration files in TS 5.0+
if media_type != MediaType::Dts
&& media_type == MediaType::TypeScript
&& specifier
.path()
.split('/')
.last()
.map(|last| last.contains(".d."))
.unwrap_or(false)
{
let mut path_parts = specifier
.path()
.split('/')
.map(ToOwned::to_owned)
.collect::<Vec<_>>();
let last_part = path_parts.last_mut().unwrap();
*last_part = last_part.replace(".d.", "$d$");
let mut specifier = specifier.clone();
specifier.set_path(&path_parts.join("/"));
Some(format!("{}{}", specifier, media_type.as_ts_extension()))
} else {
Some(format!("{}{}", specifier, media_type.as_ts_extension()))
}
} else {
None
}
}
/// Attempts to convert a specifier to a file path. By default, uses the Url
/// crate's `to_file_path()` method, but falls back to try and resolve unix-style
/// paths on Windows.