summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-11-01 12:27:00 -0400
committerGitHub <noreply@github.com>2024-11-01 12:27:00 -0400
commit826e42a5b5880c974ae019a7a21aade6a718062c (patch)
treea46502ecc3c73e4f7fc3a4517d83c7b2f3d0c0d3 /runtime
parent4774eab64d5176e997b6431f03f075782321b3d9 (diff)
fix: improved support for cjs and cts modules (#26558)
* cts support * better cjs/cts type checking * deno compile cjs/cts support * More efficient detect cjs (going towards stabilization) * Determination of whether .js, .ts, .jsx, or .tsx is cjs or esm is only done after loading * Support `import x = require(...);` Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/errors.rs14
-rw-r--r--runtime/shared.rs9
2 files changed, 12 insertions, 11 deletions
diff --git a/runtime/errors.rs b/runtime/errors.rs
index a5c436e75..ada26ec35 100644
--- a/runtime/errors.rs
+++ b/runtime/errors.rs
@@ -1048,8 +1048,6 @@ mod node {
WorkerThreadsFilenameError::UrlToPathString => "Error",
WorkerThreadsFilenameError::UrlToPath => "Error",
WorkerThreadsFilenameError::FileNotFound(_) => "Error",
- WorkerThreadsFilenameError::NeitherEsmNorCjs => "Error",
- WorkerThreadsFilenameError::UrlToNodeResolution(_) => "Error",
WorkerThreadsFilenameError::Fs(e) => super::get_fs_error(e),
}
}
@@ -1058,11 +1056,13 @@ mod node {
match error {
RequireError::UrlParse(e) => get_url_parse_error_class(e),
RequireError::Permission(e) => get_error_class_name(e).unwrap_or("Error"),
- RequireError::PackageExportsResolve(_) => "Error",
- RequireError::PackageJsonLoad(_) => "Error",
- RequireError::ClosestPkgJson(_) => "Error",
- RequireError::FilePathConversion(_) => "Error",
- RequireError::PackageImportsResolve(_) => "Error",
+ RequireError::PackageExportsResolve(_)
+ | RequireError::PackageJsonLoad(_)
+ | RequireError::ClosestPkgJson(_)
+ | RequireError::FilePathConversion(_)
+ | RequireError::UrlConversion(_)
+ | RequireError::ReadModule(_)
+ | RequireError::PackageImportsResolve(_) => "Error",
RequireError::Fs(e) | RequireError::UnableToGetCwd(e) => {
super::get_fs_error(e)
}
diff --git a/runtime/shared.rs b/runtime/shared.rs
index 02dfd1871..f7d76f67a 100644
--- a/runtime/shared.rs
+++ b/runtime/shared.rs
@@ -98,6 +98,7 @@ pub fn maybe_transpile_source(
imports_not_used_as_values: deno_ast::ImportsNotUsedAsValues::Remove,
..Default::default()
},
+ &deno_ast::TranspileModuleOptions::default(),
&deno_ast::EmitOptions {
source_map: if cfg!(debug_assertions) {
SourceMapOption::Separate
@@ -109,9 +110,9 @@ pub fn maybe_transpile_source(
)?
.into_source();
- let maybe_source_map: Option<SourceMapData> =
- transpiled_source.source_map.map(|sm| sm.into());
- let source_text = String::from_utf8(transpiled_source.source)?;
-
+ let maybe_source_map: Option<SourceMapData> = transpiled_source
+ .source_map
+ .map(|sm| sm.into_bytes().into());
+ let source_text = transpiled_source.text;
Ok((source_text.into(), maybe_source_map))
}