@@ -20,8 +20,8 @@ pub struct SWC {
20
20
}
21
21
22
22
impl SWC {
23
- /// parse source code.
24
- pub fn parse ( specifier : & str , source : & str ) -> Result < Self , anyhow :: Error > {
23
+ /// parse the module from the source code.
24
+ pub fn parse ( specifier : & str , source : & str ) -> Result < Self , DiagnosticBuffer > {
25
25
let source_map = SourceMap :: default ( ) ;
26
26
let source_file = source_map. new_source_file ( FileName :: Real ( Path :: new ( specifier) . to_path_buf ( ) ) , source. into ( ) ) ;
27
27
let sm = & source_map;
@@ -39,24 +39,16 @@ impl SWC {
39
39
..HandlerFlags :: default ( )
40
40
} ,
41
41
) ;
42
- let module = parser
43
- . parse_module ( )
44
- . map_err ( move |err| {
45
- let mut diagnostic = err. into_diagnostic ( & handler) ;
46
- diagnostic. emit ( ) ;
47
- DiagnosticBuffer :: from_error_buffer ( error_buffer, |span| sm. lookup_char_pos ( span. lo ) )
48
- } )
49
- . unwrap ( ) ;
50
-
42
+ let module = parser. parse_module ( ) . map_err ( move |err| {
43
+ let mut diagnostic = err. into_diagnostic ( & handler) ;
44
+ diagnostic. emit ( ) ;
45
+ DiagnosticBuffer :: from_error_buffer ( error_buffer, |span| sm. lookup_char_pos ( span. lo ) )
46
+ } ) ?;
51
47
Ok ( SWC { module } )
52
48
}
53
49
54
50
/// get named exports and reexports of the module.
55
- pub fn parse_cjs_exports (
56
- & self ,
57
- node_env : & str ,
58
- call_mode : bool ,
59
- ) -> Result < ( Vec < String > , Vec < String > ) , anyhow:: Error > {
51
+ pub fn get_exports ( & self , node_env : & str , call_mode : bool ) -> ( Vec < String > , Vec < String > ) {
60
52
let mut lexer = CJSLexer {
61
53
call_mode,
62
54
node_env : node_env. to_owned ( ) ,
@@ -68,11 +60,9 @@ impl SWC {
68
60
} ;
69
61
let program = Program :: Module ( self . module . clone ( ) ) ;
70
62
program. fold_with ( & mut lexer) ;
71
- Ok ( (
63
+ (
72
64
lexer. named_exports . into_iter ( ) . collect ( ) ,
73
65
lexer. reexports . into_iter ( ) . collect ( ) ,
74
- ) )
66
+ )
75
67
}
76
68
}
77
-
78
-
0 commit comments