@@ -5,7 +5,7 @@ use swc_common::{
5
5
FileName , comments:: { Comment , Comments , CommentMap } , SourceFile , BytePos
6
6
} ;
7
7
use swc_ecma_ast:: { Module } ;
8
- use swc_ecma_parser:: { Parser , Session , SourceFileInput , Syntax , lexer:: Lexer , Capturing , JscTarget , token:: { TokenAndSpan } } ;
8
+ use swc_ecma_parser:: { Parser , SourceFileInput , Syntax , lexer:: Lexer , Capturing , JscTarget , token:: { TokenAndSpan } } ;
9
9
10
10
pub struct ParsedSourceFile < ' a > {
11
11
pub module : Module ,
@@ -36,8 +36,7 @@ pub fn parse_swc_ast<'a>(file_path: &PathBuf, file_text: &'a str) -> Result<Pars
36
36
37
37
fn parse_inner < ' a > ( file_path : & PathBuf , file_text : & ' a str ) -> Result < ParsedSourceFile < ' a > , String > {
38
38
let handler = Handler :: with_emitter ( false , false , Box :: new ( EmptyEmitter { } ) ) ;
39
- let session = Session { handler : & handler } ;
40
-
39
+
41
40
let file_bytes = file_text. as_bytes ( ) ;
42
41
let source_file = SourceFile :: new (
43
42
FileName :: Custom ( file_path. to_string_lossy ( ) . into ( ) ) ,
@@ -54,23 +53,23 @@ fn parse_inner<'a>(file_path: &PathBuf, file_text: &'a str) -> Result<ParsedSour
54
53
ts_config. dynamic_import = true ;
55
54
ts_config. decorators = true ;
56
55
let lexer = Lexer :: new (
57
- session,
58
56
Syntax :: Typescript ( ts_config) ,
59
57
JscTarget :: Es2019 ,
60
58
SourceFileInput :: from ( & source_file) ,
61
59
Some ( & comments)
62
60
) ;
63
61
let lexer = Capturing :: new ( lexer) ;
64
- let mut parser = Parser :: new_from ( session , lexer) ;
62
+ let mut parser = Parser :: new_from ( lexer) ;
65
63
let parse_module_result = parser. parse_module ( ) ;
66
64
let tokens = parser. input ( ) . take ( ) ;
67
65
68
66
match parse_module_result {
69
- Err ( mut error) => {
67
+ Err ( error) => {
70
68
// mark the diagnostic as being handled (otherwise it will panic in its drop)
71
- error. cancel ( ) ;
69
+ let mut diagnostic = error. into_diagnostic ( & handler) ;
70
+ diagnostic. cancel ( ) ;
72
71
// return the formatted diagnostic string
73
- Err ( format_diagnostic ( & error , file_text) )
72
+ Err ( format_diagnostic ( & diagnostic , file_text) )
74
73
} ,
75
74
Ok ( module) => Ok ( ( module, tokens) )
76
75
}
0 commit comments