@@ -19,8 +19,8 @@ use deno_ast::SourcePos;
19
19
use deno_ast:: SourceRangedForSpanned ;
20
20
21
21
use deno_ast:: swc:: common:: comments:: CommentKind ;
22
- use deno_ast:: Diagnostic ;
23
22
use deno_ast:: MediaType ;
23
+ use deno_ast:: ParseDiagnostic ;
24
24
use deno_ast:: ParsedSource ;
25
25
use deno_ast:: SourceTextInfo ;
26
26
use once_cell:: sync:: Lazy ;
@@ -50,6 +50,7 @@ static TYPES_REFERENCE_RE: Lazy<Regex> =
50
50
Lazy :: new ( || Regex :: new ( r#"(?i)\stypes\s*=\s*["']([^"']*)["']"# ) . unwrap ( ) ) ;
51
51
52
52
pub struct ParseOptions < ' a > {
53
+ // this is not cloned in lazy parsing scenarios (thus the reference)
53
54
pub specifier : & ' a ModuleSpecifier ,
54
55
pub source : Arc < str > ,
55
56
pub media_type : MediaType ,
@@ -61,7 +62,7 @@ pub trait ModuleParser {
61
62
fn parse_module (
62
63
& self ,
63
64
options : ParseOptions ,
64
- ) -> Result < ParsedSource , Diagnostic > ;
65
+ ) -> Result < ParsedSource , ParseDiagnostic > ;
65
66
}
66
67
67
68
#[ derive( Default , Clone ) ]
@@ -71,9 +72,9 @@ impl ModuleParser for DefaultModuleParser {
71
72
fn parse_module (
72
73
& self ,
73
74
options : ParseOptions ,
74
- ) -> Result < ParsedSource , Diagnostic > {
75
+ ) -> Result < ParsedSource , ParseDiagnostic > {
75
76
deno_ast:: parse_module ( deno_ast:: ParseParams {
76
- specifier : options. specifier . to_string ( ) ,
77
+ specifier : options. specifier . clone ( ) ,
77
78
text_info : SourceTextInfo :: new ( options. source ) ,
78
79
media_type : options. media_type ,
79
80
capture_tokens : options. scope_analysis ,
@@ -192,7 +193,7 @@ impl<'a> ModuleParser for CapturingModuleParser<'a> {
192
193
fn parse_module (
193
194
& self ,
194
195
options : ParseOptions ,
195
- ) -> Result < ParsedSource , Diagnostic > {
196
+ ) -> Result < ParsedSource , ParseDiagnostic > {
196
197
if let Some ( parsed_source) = self . get_from_store_if_matches ( & options) {
197
198
Ok ( parsed_source)
198
199
} else {
@@ -260,7 +261,7 @@ impl<'a> ModuleAnalyzer for DefaultModuleAnalyzer<'a> {
260
261
specifier : & deno_ast:: ModuleSpecifier ,
261
262
source : Arc < str > ,
262
263
media_type : MediaType ,
263
- ) -> Result < ModuleInfo , Diagnostic > {
264
+ ) -> Result < ModuleInfo , ParseDiagnostic > {
264
265
let default_parser = DefaultModuleParser ;
265
266
let parser = self . parser . unwrap_or ( & default_parser) ;
266
267
let parsed_source = parser. parse_module ( ParseOptions {
@@ -312,7 +313,7 @@ impl ModuleAnalyzer for CapturingModuleAnalyzer {
312
313
specifier : & deno_ast:: ModuleSpecifier ,
313
314
source : Arc < str > ,
314
315
media_type : MediaType ,
315
- ) -> Result < ModuleInfo , Diagnostic > {
316
+ ) -> Result < ModuleInfo , ParseDiagnostic > {
316
317
let capturing_parser = self . as_capturing_parser ( ) ;
317
318
let module_analyzer = DefaultModuleAnalyzer :: new ( & capturing_parser) ;
318
319
module_analyzer. analyze ( specifier, source, media_type)
@@ -323,7 +324,7 @@ impl ModuleParser for CapturingModuleAnalyzer {
323
324
fn parse_module (
324
325
& self ,
325
326
options : ParseOptions ,
326
- ) -> Result < ParsedSource , Diagnostic > {
327
+ ) -> Result < ParsedSource , ParseDiagnostic > {
327
328
let capturing_parser = self . as_capturing_parser ( ) ;
328
329
capturing_parser. parse_module ( options)
329
330
}
0 commit comments