Skip to content

Commit

Permalink
feat: Remove SourceMapGetter trait (#847)
Browse files Browse the repository at this point in the history
This trait was deprecated in
#823 and is
scheduled to be removed in 0.300.0
  • Loading branch information
bartlomieju authored Jul 25, 2024
1 parent 2927e78 commit ed14aae
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 54 deletions.
2 changes: 0 additions & 2 deletions core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ pub use crate::runtime::MODULE_MAP_SLOT_INDEX;
pub use crate::runtime::V8_WRAPPER_OBJECT_INDEX;
pub use crate::runtime::V8_WRAPPER_TYPE_INDEX;
pub use crate::source_map::SourceMapData;
#[allow(deprecated)]
pub use crate::source_map::SourceMapGetter;
pub use crate::tasks::V8CrossThreadTaskSpawner;
pub use crate::tasks::V8TaskSpawner;

Expand Down
11 changes: 1 addition & 10 deletions core/runtime/jsruntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ use crate::runtime::ContextState;
use crate::runtime::JsRealm;
use crate::runtime::OpDriverImpl;
use crate::source_map::SourceMapData;
#[allow(deprecated)]
use crate::source_map::SourceMapGetter;
use crate::source_map::SourceMapper;
use crate::stats::RuntimeActivityType;
use crate::Extension;
Expand Down Expand Up @@ -443,11 +441,6 @@ pub struct JsRuntimeState {

#[derive(Default)]
pub struct RuntimeOptions {
/// Source map reference for errors.
#[deprecated = "Update `ModuleLoader` trait implementations. This option will be removed in deno_core v0.300.0."]
#[allow(deprecated)]
pub source_map_getter: Option<Rc<dyn SourceMapGetter>>,

/// Allows to map error type to a string "class" used to represent
/// error in JavaScript.
pub get_error_class_fn: Option<GetErrorClassFn>,
Expand Down Expand Up @@ -694,9 +687,7 @@ impl JsRuntime {
.module_loader
.unwrap_or_else(|| Rc::new(NoopModuleLoader));

#[allow(deprecated)]
let mut source_mapper =
SourceMapper::new(loader.clone(), options.source_map_getter);
let mut source_mapper = SourceMapper::new(loader.clone());

let mut sources = extension_set::into_sources_and_source_maps(
options.extension_transpiler.as_deref(),
Expand Down
46 changes: 4 additions & 42 deletions core/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

//! This mod provides functions to remap a `JsError` based on a source map.
// TODO(bartlomieju): remove once `SourceMapGetter` is removed.
#![allow(deprecated)]

use crate::resolve_url;
use crate::ModuleLoader;
use crate::ModuleName;
Expand All @@ -14,17 +11,6 @@ use std::collections::HashMap;
use std::rc::Rc;
use std::str;

#[deprecated = "Use `ModuleLoader` methods instead. This trait will be removed in deno_core v0.300.0."]
pub trait SourceMapGetter {
/// Returns the raw source map file.
fn get_source_map(&self, file_name: &str) -> Option<Vec<u8>>;
fn get_source_line(
&self,
file_name: &str,
line_number: usize,
) -> Option<String>;
}

#[derive(Debug, PartialEq)]
pub enum SourceMapApplication {
/// No mapping was applied, the location is unchanged.
Expand All @@ -51,22 +37,17 @@ pub struct SourceMapper {
source_lines: HashMap<(String, i64), Option<String>>,

loader: Rc<dyn ModuleLoader>,
getter: Option<Rc<dyn SourceMapGetter>>,

ext_source_maps: HashMap<ModuleName, SourceMapData>,
}

impl SourceMapper {
pub fn new(
loader: Rc<dyn ModuleLoader>,
getter: Option<Rc<dyn SourceMapGetter>>,
) -> Self {
pub fn new(loader: Rc<dyn ModuleLoader>) -> Self {
Self {
maps: Default::default(),
source_lines: Default::default(),
ext_source_maps: Default::default(),
loader,
getter,
}
}

Expand Down Expand Up @@ -100,7 +81,6 @@ impl SourceMapper {
let line_number = line_number - 1;
let column_number = column_number - 1;

let getter = self.getter.as_ref();
let maybe_source_map =
self.maps.entry(file_name.to_owned()).or_insert_with(|| {
None
Expand All @@ -110,9 +90,6 @@ impl SourceMapper {
.or_else(|| {
SourceMap::from_slice(&self.loader.get_source_map(file_name)?).ok()
})
.or_else(|| {
SourceMap::from_slice(&getter?.get_source_map(file_name)?).ok()
})
});

let Some(source_map) = maybe_source_map.as_ref() else {
Expand Down Expand Up @@ -172,24 +149,9 @@ impl SourceMapper {
return maybe_source_line.clone();
}

// TODO(bartlomieju): shouldn't we cache `None` values to avoid computing it each time, instead of early return?
if let Some(source_line) = self
let s = self
.loader
.get_source_mapped_source_line(file_name, (line_number - 1) as usize)
.filter(|s| s.len() <= Self::MAX_SOURCE_LINE_LENGTH)
{
// Cache and return
self.source_lines.insert(
(file_name.to_string(), line_number),
Some(source_line.to_string()),
);
return Some(source_line);
}

// TODO(bartlomieju): remove in deno_core 0.230.0
// Fallback to a deprecated API
let getter = self.getter.as_ref()?;
let s = getter.get_source_line(file_name, (line_number - 1) as usize);
.get_source_mapped_source_line(file_name, (line_number - 1) as usize);
let maybe_source_line =
s.filter(|s| s.len() <= Self::MAX_SOURCE_LINE_LENGTH);
// Cache and return
Expand Down Expand Up @@ -275,7 +237,7 @@ mod tests {
},
);

let mut source_mapper = SourceMapper::new(Rc::new(loader), None);
let mut source_mapper = SourceMapper::new(Rc::new(loader));

// Non-existent file
let application =
Expand Down

0 comments on commit ed14aae

Please sign in to comment.