mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
fix: SourceMap::span_to_lines for empty file (#1198)
Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
This commit is contained in:
parent
bae0eda8bd
commit
546a01cdc2
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_common"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.10.4"
|
||||
version = "0.10.5"
|
||||
|
||||
[features]
|
||||
concurrent = ["parking_lot"]
|
||||
|
@ -457,6 +457,14 @@ impl SourceMap {
|
||||
}
|
||||
assert!(hi.line >= lo.line);
|
||||
|
||||
// Empty file contains no lines
|
||||
if lo.file.src.is_empty() {
|
||||
return Ok(FileLines {
|
||||
file: lo.file,
|
||||
lines: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
let mut lines = Vec::with_capacity(hi.line - lo.line + 1);
|
||||
|
||||
// The span starts partway through the first line,
|
||||
@ -1313,6 +1321,18 @@ mod tests {
|
||||
assert_eq!(sstr, "blork.rs:2:1: 2:12");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t10() {
|
||||
// Test span_to_lines for a span of empty file
|
||||
let sm = SourceMap::new(FilePathMapping::empty());
|
||||
sm.new_source_file(PathBuf::from("blork.rs").into(), "".to_string());
|
||||
let span = Span::new(BytePos(0), BytePos(0), NO_EXPANSION);
|
||||
let file_lines = sm.span_to_lines(span).unwrap();
|
||||
|
||||
assert_eq!(file_lines.file.name, PathBuf::from("blork.rs").into());
|
||||
assert_eq!(file_lines.lines.len(), 0);
|
||||
}
|
||||
|
||||
/// Test failing to merge two spans on different lines
|
||||
#[test]
|
||||
fn span_merging_fail() {
|
||||
|
Loading…
Reference in New Issue
Block a user