Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es): Allow input source map file to be omitted #8951

Merged
merged 2 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ extern crate swc_common as common;

use std::{
fs::{read_to_string, File},
io::ErrorKind,
path::{Path, PathBuf},
sync::Arc,
};
Expand Down Expand Up @@ -154,6 +155,7 @@ use swc_ecma_visit::{FoldWith, VisitMutWith, VisitWith};
pub use swc_error_reporters::handler::{try_with_handler, HandlerOpts};
pub use swc_node_comments::SwcComments;
use swc_timer::timer;
use tracing::warn;
use url::Url;

pub use crate::builder::PassBuilder;
Expand Down Expand Up @@ -339,6 +341,23 @@ impl Compiler {
let path = map_path.display().to_string();
let file = File::open(&path);

// If file is not found, we should return None.
// Some libraries generates source map but omit them from the
// npm package.
//
// See https://github.com/swc-project/swc/issues/8789#issuecomment-2105055772
if file
.as_ref()
.is_err_and(|err| err.kind() == ErrorKind::NotFound)
{
warn!(
"source map is specified by sourceMappingURL but \
there's no source map at `{}`",
path
);
return Ok(None);
}

// Old behavior.
let file = if !is_default {
file?
Expand Down
Loading