Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions turbopack/crates/turbopack-core/src/code_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,15 @@ impl Code {
}
last_byte_pos = *byte_pos;

sections.push((pos, map.clone().unwrap_or_else(SourceMap::empty_rope)))
if pos.column != 0 || map.is_some() {
sections.push((pos, map.clone().unwrap_or_else(SourceMap::empty_rope)))
}
}

SourceMap::sections_to_rope(sections)
if sections.len() == 1 && sections[0].0.line == 0 && sections[0].0.column == 0 {
Ok(sections.into_iter().next().unwrap().1)
} else {
SourceMap::sections_to_rope(sections)
}
}
}
6 changes: 5 additions & 1 deletion turbopack/crates/turbopack-ecmascript/src/minify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn minify(path: &FileSystemPath, code: &Code, source_maps: bool, mangle: boo
builder,
// findSourceMapURL assumes this co-located sourceMappingURL,
// and needs to be adjusted in case this is ever changed.
"\n\n//# sourceMappingURL={}.map",
"\n//# sourceMappingURL={}.map",
urlencoding::encode(path.file_name())
)?;
} else {
Expand Down Expand Up @@ -156,6 +156,10 @@ fn print_program(
.emit_program(&program)
.context("failed to emit module")?;
}
if source_maps {
// end with a new line when we have a source map comment
buf.push(b'\n');
}
// Invalid utf8 is valid in javascript world.
// SAFETY: SWC generates valid utf8.
unsafe { String::from_utf8_unchecked(buf) }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading