mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
parent
a6b2a4474e
commit
c6def993e0
12 changed files with 220 additions and 56 deletions
33
cli/cache/parsed_source.rs
vendored
33
cli/cache/parsed_source.rs
vendored
|
@ -11,6 +11,39 @@ use deno_graph::CapturingModuleParser;
|
|||
use deno_graph::ModuleParser;
|
||||
use deno_graph::ParseOptions;
|
||||
|
||||
/// Lazily parses JS/TS sources from a `deno_graph::ModuleGraph` given
|
||||
/// a `ParsedSourceCache`. Note that deno_graph doesn't necessarily cause
|
||||
/// files to end up in the `ParsedSourceCache` because it might have all
|
||||
/// the information it needs via caching in order to skip parsing.
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct LazyGraphSourceParser<'a> {
|
||||
cache: &'a ParsedSourceCache,
|
||||
graph: &'a deno_graph::ModuleGraph,
|
||||
}
|
||||
|
||||
impl<'a> LazyGraphSourceParser<'a> {
|
||||
pub fn new(
|
||||
cache: &'a ParsedSourceCache,
|
||||
graph: &'a deno_graph::ModuleGraph,
|
||||
) -> Self {
|
||||
Self { cache, graph }
|
||||
}
|
||||
|
||||
pub fn get_or_parse_source(
|
||||
&self,
|
||||
module_specifier: &ModuleSpecifier,
|
||||
) -> Result<Option<deno_ast::ParsedSource>, deno_ast::Diagnostic> {
|
||||
let Some(deno_graph::Module::Js(module)) = self.graph.get(module_specifier)
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
self
|
||||
.cache
|
||||
.get_parsed_source_from_js_module(module)
|
||||
.map(Some)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ParsedSourceCache {
|
||||
sources: Mutex<HashMap<ModuleSpecifier, ParsedSource>>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue