Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave committed Sep 28, 2023
1 parent b3744f4 commit c320405
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,23 @@ pub trait PathMap {
fn set_path(&mut self, path: PathBuf, source: SourceId);
}

impl<T: PathMap> MapFileStore<T> {
pub fn update_file(&mut self, id: SourceId, content: String) {
self.sources[id.0 as usize].content = content;
}

/// Returns the NEW length of the file's content
pub fn append_to_file(&mut self, id: SourceId, content: &str) -> usize {
let existing = &mut self.sources[id.0 as usize].content;
existing.push_str(content);
existing.len()
}
}

impl MapFileStore<WithPathMap> {
/// TODO partial updates
pub fn update_file_at_path(&mut self, path: &Path, content: String) {
self.sources[self.mappings.0[path].0 as usize].content = content;
self.update_file(self.mappings.0[path], content);
}

/// Either a rename or move
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ impl SourceMapBuilder {
source: from_source,
} = source_position;

self.used_sources.insert(from_source.clone());
self.used_sources.insert(*from_source);

self.mappings.push(MappingOrBreak::Mapping(SourceMapping {
from_source: from_source.clone(),
source_byte_start: source_byte_start.clone().try_into().unwrap(),
from_source: *from_source,
source_byte_start: (*source_byte_start).try_into().unwrap(),
on_output_column: self.current_output_column,
// source_byte_end: *source_byte_end,
// on_output_line: self.current_output_line,
Expand Down
4 changes: 2 additions & 2 deletions src/lines_columns_indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ mod tests {
let mut last = iterator.next().unwrap();
for part in iterator {
let value = &source[last..part];
let value = value.strip_suffix("\n").unwrap();
let value = value.strip_suffix("\r").unwrap_or(value);
let value = value.strip_suffix('\n').unwrap();
let value = value.strip_suffix('\r').unwrap_or(value);
actual_lines.push(value);
last = part;
}
Expand Down
6 changes: 5 additions & 1 deletion src/to_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ impl StringWithSourceMap {
#[cfg(feature = "inline-source-map")]
/// Build the output and append the source map in base 64
pub fn build_with_inline_source_map(self, filesystem: &impl FileSystem) -> String {
use base64::Engine;

let Self(mut source, source_map) = self;
let built_source_map = source_map.build(filesystem);
// Inline URL:
source.push_str("\n//# sourceMappingURL=data:application/json;base64,");
source.push_str(&base64::encode(built_source_map.to_json(filesystem)));
source.push_str(
&base64::prelude::BASE64_STANDARD.encode(built_source_map.to_json(filesystem)),
);
source
}
}
Expand Down

0 comments on commit c320405

Please sign in to comment.