Skip to content

Commit

Permalink
Fixed relative paths in generated source maps.
Browse files Browse the repository at this point in the history
  • Loading branch information
cutsoy committed Jan 15, 2023
1 parent e9680ab commit c24a356
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion litho-export/src/typescript/source_mapped.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Borrow;
use std::collections::HashMap;
use std::env::current_dir;
use std::path::Path;

use litho_language::lex::raw::RawToken;
Expand Down Expand Up @@ -57,7 +58,15 @@ impl<'a> SourceMapped<'a> {
if let Some((source, index)) = self.sources.get(&token.span.source_id) {
let (src_line, src_column) = index.lookup(token.span.start);

let source = self.builder.add_source(source);
let path = current_dir().ok().map(|dir| dir.join(source));

let source =
self.builder
.add_source(match path.as_ref().and_then(|path| path.to_str()) {
Some(path) => path,
None => source,
});

let name = self.builder.add_name(token.source.borrow());

self.builder.add_raw(
Expand Down

0 comments on commit c24a356

Please sign in to comment.