@@ -2,7 +2,7 @@ use crate::cjs::CJSLexer;
2
2
use crate :: error:: { DiagnosticBuffer , ErrorBuffer } ;
3
3
4
4
use indexmap:: { IndexMap , IndexSet } ;
5
- use std:: { path:: Path , rc :: Rc } ;
5
+ use std:: path:: Path ;
6
6
use swc_common:: {
7
7
comments:: SingleThreadedComments ,
8
8
errors:: { Handler , HandlerFlags } ,
@@ -16,10 +16,7 @@ use swc_ecmascript::{
16
16
} ;
17
17
18
18
pub struct SWC {
19
- pub specifier : String ,
20
19
pub module : Module ,
21
- pub source_map : Rc < SourceMap > ,
22
- pub comments : SingleThreadedComments ,
23
20
}
24
21
25
22
impl SWC {
@@ -29,7 +26,7 @@ impl SWC {
29
26
let source_file = source_map. new_source_file ( FileName :: Real ( Path :: new ( specifier) . to_path_buf ( ) ) , source. into ( ) ) ;
30
27
let sm = & source_map;
31
28
let error_buffer = ErrorBuffer :: new ( specifier) ;
32
- let syntax = Syntax :: Es ( get_es_config ( ) ) ;
29
+ let syntax = Syntax :: Es ( EsConfig :: default ( ) ) ;
33
30
let input = StringInput :: from ( & * source_file) ;
34
31
let comments = SingleThreadedComments :: default ( ) ;
35
32
let lexer = Lexer :: new ( syntax, EsVersion :: Es2020 , input, Some ( & comments) ) ;
@@ -51,42 +48,31 @@ impl SWC {
51
48
} )
52
49
. unwrap ( ) ;
53
50
54
- Ok ( SWC {
55
- specifier : specifier. into ( ) ,
56
- module,
57
- source_map : Rc :: new ( source_map) ,
58
- comments,
59
- } )
51
+ Ok ( SWC { module } )
60
52
}
61
53
62
- /// parse export names in the cjs module.
54
+ /// get named exports and reexports of the module.
63
55
pub fn parse_cjs_exports (
64
56
& self ,
65
57
node_env : & str ,
66
58
call_mode : bool ,
67
59
) -> Result < ( Vec < String > , Vec < String > ) , anyhow:: Error > {
68
60
let mut lexer = CJSLexer {
61
+ call_mode,
69
62
node_env : node_env. to_owned ( ) ,
70
- call_mode : call_mode,
71
63
fn_returned : false ,
72
64
idents : IndexMap :: new ( ) ,
73
65
exports_alias : IndexSet :: new ( ) ,
74
- exports : IndexSet :: new ( ) ,
66
+ named_exports : IndexSet :: new ( ) ,
75
67
reexports : IndexSet :: new ( ) ,
76
68
} ;
77
69
let program = Program :: Module ( self . module . clone ( ) ) ;
78
70
program. fold_with ( & mut lexer) ;
79
71
Ok ( (
80
- lexer. exports . into_iter ( ) . collect ( ) ,
72
+ lexer. named_exports . into_iter ( ) . collect ( ) ,
81
73
lexer. reexports . into_iter ( ) . collect ( ) ,
82
74
) )
83
75
}
84
76
}
85
77
86
- fn get_es_config ( ) -> EsConfig {
87
- EsConfig {
88
- import_attributes : true ,
89
- jsx : false ,
90
- ..EsConfig :: default ( )
91
- }
92
- }
78
+
0 commit comments