diff --git a/crates/oxc_sourcemap/src/concat_sourcemap_builder.rs b/crates/oxc_sourcemap/src/concat_sourcemap_builder.rs index 120c236ffe2110..5ca2f9d9bf7d7a 100644 --- a/crates/oxc_sourcemap/src/concat_sourcemap_builder.rs +++ b/crates/oxc_sourcemap/src/concat_sourcemap_builder.rs @@ -46,11 +46,12 @@ impl ConcatSourceMapBuilder { } // Extend `sources` and `source_contents`. - self.sources.reserve(sourcemap.sources.len()); - for (index, source) in sourcemap.get_sources().enumerate() { - let source_content = sourcemap.get_source_content(index as u32).unwrap_or_default(); - self.sources.push(source.into()); - self.source_contents.push(source_content.into()); + self.sources.extend(sourcemap.get_sources().map(Into::into)); + + if let Some(source_contents) = &sourcemap.source_contents { + self.source_contents.extend(source_contents.iter().map(AsRef::as_ref).map(Into::into)); + } else { + self.source_contents.extend((0..sourcemap.sources.len()).map(|_| Arc::default())); } // Extend `names`.