Skip to content

Commit

Permalink
fix: should ignores names without columns (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Sep 4, 2024
1 parent 91d09c1 commit cfde068
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl MappingsEncoder for FullMappingsEncoder {
fn encode(&mut self, mapping: &Mapping) {
if self.active_mapping && self.current_line == mapping.generated_line {
// A mapping is still active
if mapping.original.is_some_and(|original| {
if mapping.original.as_ref().is_some_and(|original| {
original.source_index == self.current_source_index
&& original.original_line == self.current_original_line
&& original.original_column == self.current_original_column
Expand Down
7 changes: 4 additions & 3 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ fn stream_chunks_of_source_map_full<'a>(
tracking_generated_index = current_generated_index;
tracking_generated_line = mapping.generated_line;
tracking_generated_column = mapping.generated_column;
tracking_mapping_original = mapping.original;
tracking_mapping_original = mapping.original.clone();

current_mapping = mappings_iter.next();
}
Expand Down Expand Up @@ -497,7 +497,7 @@ fn stream_chunks_of_source_map_lines_final<'a>(
let mut current_generated_line = 1;

let mut on_mapping = |mut mapping: Mapping| {
if let Some(mut original) = mapping.original.filter(|_| {
if let Some(original) = mapping.original.as_mut().filter(|_| {
current_generated_line <= mapping.generated_line
&& mapping.generated_line <= final_line
}) {
Expand Down Expand Up @@ -556,8 +556,9 @@ fn stream_chunks_of_source_map_lines_full<'a>(
}
current_generated_line += 1;
}
if let Some(mut original) = mapping
if let Some(original) = mapping
.original
.as_mut()
.filter(|_| mapping.generated_line as usize <= lines.len())
{
let chunk = lines[current_generated_line as usize - 1];
Expand Down
2 changes: 1 addition & 1 deletion src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ pub struct Mapping {
}

/// Represent original position information of a [Mapping].
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct OriginalLocation {
/// Source index.
pub source_index: u32,
Expand Down
44 changes: 44 additions & 0 deletions src/source_map_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,48 @@ mod tests {
.unwrap(),
);
}

#[test]
fn should_ignores_names_without_columns() {
let source = SourceMapSource::new(SourceMapSourceOptions {
value: "h",
name: "hello.txt",
source_map: SourceMap::from_json(
r#"{
"version": 3,
"sources": ["hello.txt"],
"mappings": "AAAAA",
"names": ["hello"]
}"#,
)
.unwrap(),
original_source: Some("hello".to_string()),
inner_source_map: Some(
SourceMap::from_json(
r#"{
"version": 3,
"sources": ["hello world.txt"],
"mappings": "AAAA",
"names": [],
"sourcesContent": ["hello, world!"]
}"#,
)
.unwrap(),
),
remove_original_source: false,
});
assert_eq!(
source.map(&MapOptions::new(false)).unwrap(),
SourceMap::from_json(
r#"{
"mappings": "AAAA",
"names": [],
"sources": ["hello world.txt"],
"version": 3,
"sourcesContent": ["hello, world!"]
}"#
)
.unwrap()
);
}
}

0 comments on commit cfde068

Please sign in to comment.