Skip to content

Commit

Permalink
fix: add back IntoSwcFileName
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Aug 23, 2024
1 parent 61cc2f4 commit 534cee7
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,39 @@

use std::rc::Rc;

use crate::swc::common::FileName;
use crate::swc::common::SourceFile;

use crate::ModuleSpecifier;

/// This is used in JSR, so don't remove it.
pub trait IntoSwcFileName {
fn into_file_name(self) -> FileName;
}

impl IntoSwcFileName for ModuleSpecifier {
fn into_file_name(self) -> FileName {
FileName::Url(self)
}
}

impl IntoSwcFileName for String {
fn into_file_name(self) -> FileName {
FileName::Custom(self)
}
}

#[derive(Clone, Default)]
pub struct SourceMap {
inner: Rc<crate::swc::common::SourceMap>,
}

impl SourceMap {
pub fn single(specifier: ModuleSpecifier, source: String) -> Self {
pub fn single(file_name: impl IntoSwcFileName, source: String) -> Self {
let map = Self::default();
map
.inner
.new_source_file(Rc::new(swc_common::FileName::Url(specifier)), source);
map.inner.new_source_file(
Rc::new(IntoSwcFileName::into_file_name(file_name)),
source,
);
map
}

Expand All @@ -26,11 +44,12 @@ impl SourceMap {

pub fn new_source_file(
&self,
specifier: ModuleSpecifier,
file_name: impl IntoSwcFileName,
source: String,
) -> Rc<SourceFile> {
self
.inner
.new_source_file(Rc::new(swc_common::FileName::Url(specifier)), source)
self.inner.new_source_file(
Rc::new(IntoSwcFileName::into_file_name(file_name)),
source,
)
}
}

0 comments on commit 534cee7

Please sign in to comment.