diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-10 00:20:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-09 23:20:52 +0000 |
commit | 69959aa01fab8ccc482cb3ee218af4e65d3fbc6e (patch) | |
tree | 1221798cf514662cd0e52b3feaa0d16b58aa6697 /cli/cache | |
parent | 741afc4b94427588c628925fef464623d373430f (diff) |
fix: update deno_lint and swc (#21718)
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/cache')
-rw-r--r-- | cli/cache/module_info.rs | 11 | ||||
-rw-r--r-- | cli/cache/parsed_source.rs | 30 |
2 files changed, 29 insertions, 12 deletions
diff --git a/cli/cache/module_info.rs b/cli/cache/module_info.rs index 9240b2387..4a80774f6 100644 --- a/cli/cache/module_info.rs +++ b/cli/cache/module_info.rs @@ -6,11 +6,9 @@ use deno_ast::MediaType; use deno_ast::ModuleSpecifier; use deno_core::error::AnyError; use deno_core::serde_json; -use deno_graph::CapturingModuleParser; use deno_graph::DefaultModuleAnalyzer; use deno_graph::ModuleInfo; use deno_graph::ModuleParser; -use deno_graph::ParsedSourceStore; use deno_runtime::deno_webstorage::rusqlite::params; use super::cache_db::CacheDB; @@ -115,19 +113,18 @@ impl ModuleInfoCache { pub fn as_module_analyzer<'a>( &'a self, - parser: Option<&'a dyn ModuleParser>, - store: &'a dyn ParsedSourceStore, + parser: &'a dyn ModuleParser, ) -> ModuleInfoCacheModuleAnalyzer<'a> { ModuleInfoCacheModuleAnalyzer { module_info_cache: self, - parser: CapturingModuleParser::new(parser, store), + parser, } } } pub struct ModuleInfoCacheModuleAnalyzer<'a> { module_info_cache: &'a ModuleInfoCache, - parser: CapturingModuleParser<'a>, + parser: &'a dyn ModuleParser, } impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> { @@ -156,7 +153,7 @@ impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> { } // otherwise, get the module info from the parsed source cache - let analyzer = DefaultModuleAnalyzer::new(&self.parser); + let analyzer = DefaultModuleAnalyzer::new(self.parser); let module_info = analyzer.analyze(specifier, source, media_type)?; // then attempt to cache it diff --git a/cli/cache/parsed_source.rs b/cli/cache/parsed_source.rs index 021c37f1b..77f2e5953 100644 --- a/cli/cache/parsed_source.rs +++ b/cli/cache/parsed_source.rs @@ -9,6 +9,7 @@ use deno_ast::ParsedSource; use deno_core::parking_lot::Mutex; use deno_graph::CapturingModuleParser; use deno_graph::ModuleParser; +use deno_graph::ParseOptions; #[derive(Default)] pub struct ParsedSourceCache { @@ -37,7 +38,13 @@ impl ParsedSourceCache { ) -> deno_core::anyhow::Result<ParsedSource, deno_ast::Diagnostic> { let parser = self.as_capturing_parser(); // this will conditionally parse because it's using a CapturingModuleParser - parser.parse_module(specifier, source, media_type) + parser.parse_module(ParseOptions { + specifier, + source, + media_type, + // don't bother enabling because this method is currently only used for emitting + scope_analysis: false, + }) } /// Frees the parsed source from memory. @@ -50,10 +57,6 @@ impl ParsedSourceCache { pub fn as_capturing_parser(&self) -> CapturingModuleParser { CapturingModuleParser::new(None, self) } - - pub fn as_store(self: &Arc<Self>) -> Arc<dyn deno_graph::ParsedSourceStore> { - self.clone() - } } /// It's ok that this is racy since in non-LSP situations @@ -76,4 +79,21 @@ impl deno_graph::ParsedSourceStore for ParsedSourceCache { ) -> Option<ParsedSource> { self.sources.lock().get(specifier).cloned() } + + fn get_scope_analysis_parsed_source( + &self, + specifier: &deno_graph::ModuleSpecifier, + ) -> Option<ParsedSource> { + let mut sources = self.sources.lock(); + let parsed_source = sources.get(specifier)?; + if parsed_source.has_scope_analysis() { + Some(parsed_source.clone()) + } else { + // upgrade to have scope analysis + let parsed_source = sources.remove(specifier).unwrap(); + let parsed_source = parsed_source.into_with_scope_analysis(); + sources.insert(specifier.clone(), parsed_source.clone()); + Some(parsed_source) + } + } } |