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

Turbopack: charset=utf-8 in data-url source maps #77112

Merged
merged 1 commit into from
Mar 14, 2025
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
6 changes: 5 additions & 1 deletion turbopack/crates/turbopack-ecmascript/src/references/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,10 @@ pub(crate) async fn analyse_ecmascript_module_internal(

let mut source_map_from_comment = false;
if let Some((_, path)) = paths_by_pos.into_iter().max_by_key(|&(pos, _)| pos) {
lazy_static! {
static ref JSON_DATA_URL_BASE64: Regex =
Regex::new(r"^data:application\/json;(?:charset=utf-8;)?base64").unwrap();
}
let origin_path = origin.origin_path();
if path.ends_with(".map") {
let source_map_origin = origin_path.parent().join(path.into());
Expand All @@ -703,7 +707,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
let source_map = reference.generate_source_map();
analysis.set_source_map(source_map.to_resolved().await?);
source_map_from_comment = true;
} else if path.starts_with("data:application/json;base64,") {
} else if JSON_DATA_URL_BASE64.is_match(path) {
let source_map = maybe_decode_data_url(path.into());
let source_map =
resolve_source_map_sources(source_map.as_ref(), origin_path).await?;
Expand Down
Loading