1
- #![ cfg_attr(
2
- any( not( any( feature = "plugin" ) ) , target_arch = "wasm32" ) ,
3
- allow( unused)
4
- ) ]
5
1
use std:: {
6
2
collections:: { HashMap , HashSet } ,
7
- env, fmt ,
3
+ env,
8
4
path:: { Path , PathBuf } ,
9
5
sync:: Arc ,
10
6
usize,
@@ -16,20 +12,19 @@ use either::Either;
16
12
use indexmap:: IndexMap ;
17
13
use once_cell:: sync:: Lazy ;
18
14
use rustc_hash:: FxHashMap ;
19
- use serde:: {
20
- de:: { Unexpected , Visitor } ,
21
- Deserialize , Deserializer , Serialize , Serializer ,
22
- } ;
15
+ use serde:: { Deserialize , Serialize } ;
23
16
use swc_atoms:: JsWord ;
24
17
use swc_cached:: regex:: CachedRegex ;
18
+ #[ allow( unused) ]
19
+ use swc_common:: plugin:: metadata:: TransformPluginMetadataContext ;
25
20
use swc_common:: {
26
21
chain,
27
22
collections:: { AHashMap , AHashSet , ARandomState } ,
28
23
comments:: { Comments , SingleThreadedComments } ,
29
24
errors:: Handler ,
30
- plugin:: metadata:: TransformPluginMetadataContext ,
31
25
FileName , Mark , SourceMap , SyntaxContext ,
32
26
} ;
27
+ pub use swc_compiler_base:: { IsModule , SourceMapsConfig } ;
33
28
use swc_config:: {
34
29
config_types:: { BoolConfig , BoolOr , BoolOrDataConfig , MergingOption } ,
35
30
merge:: Merge ,
@@ -40,15 +35,11 @@ use swc_ecma_lints::{
40
35
config:: LintConfig ,
41
36
rules:: { lint_to_fold, LintParams } ,
42
37
} ;
43
- use swc_ecma_loader:: {
44
- resolvers:: { lru:: CachingResolver , node:: NodeModulesResolver , tsc:: TsConfigResolver } ,
45
- TargetEnv ,
38
+ use swc_ecma_loader:: resolvers:: {
39
+ lru:: CachingResolver , node:: NodeModulesResolver , tsc:: TsConfigResolver ,
46
40
} ;
47
41
pub use swc_ecma_minifier:: js:: * ;
48
- use swc_ecma_minifier:: option:: {
49
- terser:: { TerserCompressorOptions , TerserEcmaVersion , TerserTopLevelOptions } ,
50
- MangleOptions ,
51
- } ;
42
+ use swc_ecma_minifier:: option:: terser:: TerserTopLevelOptions ;
52
43
#[ allow( deprecated) ]
53
44
pub use swc_ecma_parser:: JscTarget ;
54
45
use swc_ecma_parser:: { parse_file_as_expr, Syntax , TsConfig } ;
@@ -111,74 +102,6 @@ pub fn init_plugin_module_cache_once(
111
102
} ) ;
112
103
}
113
104
114
- #[ derive( Clone , Debug , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
115
- pub enum IsModule {
116
- Bool ( bool ) ,
117
- Unknown ,
118
- }
119
-
120
- impl Default for IsModule {
121
- fn default ( ) -> Self {
122
- IsModule :: Bool ( true )
123
- }
124
- }
125
-
126
- impl Merge for IsModule {
127
- fn merge ( & mut self , other : Self ) {
128
- if * self == Default :: default ( ) {
129
- * self = other;
130
- }
131
- }
132
- }
133
-
134
- impl Serialize for IsModule {
135
- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
136
- where
137
- S : Serializer ,
138
- {
139
- match * self {
140
- IsModule :: Bool ( ref b) => b. serialize ( serializer) ,
141
- IsModule :: Unknown => "unknown" . serialize ( serializer) ,
142
- }
143
- }
144
- }
145
-
146
- impl < ' de > Deserialize < ' de > for IsModule {
147
- fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
148
- where
149
- D : Deserializer < ' de > ,
150
- {
151
- struct IsModuleVisitor ;
152
-
153
- impl < ' de > Visitor < ' de > for IsModuleVisitor {
154
- type Value = IsModule ;
155
-
156
- fn expecting ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
157
- formatter. write_str ( "a boolean or the string 'unknown'" )
158
- }
159
-
160
- fn visit_bool < E > ( self , b : bool ) -> Result < Self :: Value , E >
161
- where
162
- E : serde:: de:: Error ,
163
- {
164
- Ok ( IsModule :: Bool ( b) )
165
- }
166
-
167
- fn visit_str < E > ( self , s : & str ) -> Result < Self :: Value , E >
168
- where
169
- E : serde:: de:: Error ,
170
- {
171
- match s {
172
- "unknown" => Ok ( IsModule :: Unknown ) ,
173
- _ => Err ( serde:: de:: Error :: invalid_value ( Unexpected :: Str ( s) , & self ) ) ,
174
- }
175
- }
176
- }
177
-
178
- deserializer. deserialize_any ( IsModuleVisitor )
179
- }
180
- }
181
-
182
105
#[ derive( Default , Clone , Serialize , Deserialize ) ]
183
106
#[ serde( rename_all = "camelCase" ) ]
184
107
pub struct ParseOptions {
@@ -273,32 +196,6 @@ impl Options {
273
196
}
274
197
}
275
198
276
- /// Configuration related to source map generated by swc.
277
- #[ derive( Clone , Serialize , Deserialize , Debug ) ]
278
- #[ serde( untagged) ]
279
- pub enum SourceMapsConfig {
280
- Bool ( bool ) ,
281
- Str ( String ) ,
282
- }
283
-
284
- impl SourceMapsConfig {
285
- pub fn enabled ( & self ) -> bool {
286
- match * self {
287
- SourceMapsConfig :: Bool ( b) => b,
288
- SourceMapsConfig :: Str ( ref s) => {
289
- assert_eq ! ( s, "inline" , "Source map must be true, false or inline" ) ;
290
- true
291
- }
292
- }
293
- }
294
- }
295
-
296
- impl Default for SourceMapsConfig {
297
- fn default ( ) -> Self {
298
- SourceMapsConfig :: Bool ( true )
299
- }
300
- }
301
-
302
199
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
303
200
#[ serde( untagged) ]
304
201
pub enum InputSourceMap {
@@ -694,7 +591,11 @@ impl Options {
694
591
695
592
let plugin_resolver = CachingResolver :: new (
696
593
40 ,
697
- NodeModulesResolver :: new ( TargetEnv :: Node , Default :: default ( ) , true ) ,
594
+ NodeModulesResolver :: new (
595
+ swc_ecma_loader:: TargetEnv :: Node ,
596
+ Default :: default ( ) ,
597
+ true ,
598
+ ) ,
698
599
) ;
699
600
700
601
if let Some ( plugins) = & experimental. plugins {
1 commit comments
github-actions[bot] commentedon Sep 29, 2023
Benchmark
es/full/bugs-1
280201
ns/iter (± 5607
)275732
ns/iter (± 5271
)1.02
es/full/minify/libraries/antd
1310526047
ns/iter (± 11376564
)1317335861
ns/iter (± 18339464
)0.99
es/full/minify/libraries/d3
275164752
ns/iter (± 3153972
)278448673
ns/iter (± 4068117
)0.99
es/full/minify/libraries/echarts
1054495733
ns/iter (± 7356799
)1069715861
ns/iter (± 18519258
)0.99
es/full/minify/libraries/jquery
84242648
ns/iter (± 275071
)83943412
ns/iter (± 356041
)1.00
es/full/minify/libraries/lodash
97837238
ns/iter (± 365983
)97164732
ns/iter (± 1003130
)1.01
es/full/minify/libraries/moment
50195787
ns/iter (± 236687
)49692797
ns/iter (± 507924
)1.01
es/full/minify/libraries/react
18104776
ns/iter (± 52715
)17927125
ns/iter (± 121391
)1.01
es/full/minify/libraries/terser
218314555
ns/iter (± 1291933
)217851544
ns/iter (± 556096
)1.00
es/full/minify/libraries/three
387263870
ns/iter (± 5311824
)384824470
ns/iter (± 4641007
)1.01
es/full/minify/libraries/typescript
2656679454
ns/iter (± 8650809
)2619621222
ns/iter (± 14311976
)1.01
es/full/minify/libraries/victory
565451908
ns/iter (± 5860535
)565626120
ns/iter (± 13492290
)1.00
es/full/minify/libraries/vue
119774923
ns/iter (± 662793
)119160498
ns/iter (± 887111
)1.01
es/full/codegen/es3
34428
ns/iter (± 308
)32902
ns/iter (± 350
)1.05
es/full/codegen/es5
34455
ns/iter (± 144
)33216
ns/iter (± 105
)1.04
es/full/codegen/es2015
34489
ns/iter (± 108
)33148
ns/iter (± 326
)1.04
es/full/codegen/es2016
34539
ns/iter (± 95
)33032
ns/iter (± 342
)1.05
es/full/codegen/es2017
34455
ns/iter (± 96
)32954
ns/iter (± 237
)1.05
es/full/codegen/es2018
34432
ns/iter (± 144
)32607
ns/iter (± 355
)1.06
es/full/codegen/es2019
34432
ns/iter (± 74
)32854
ns/iter (± 245
)1.05
es/full/codegen/es2020
34382
ns/iter (± 113
)32569
ns/iter (± 558
)1.06
es/full/all/es3
163524166
ns/iter (± 1438852
)163851776
ns/iter (± 2172918
)1.00
es/full/all/es5
156285705
ns/iter (± 1300526
)156793280
ns/iter (± 1166950
)1.00
es/full/all/es2015
117285573
ns/iter (± 1237867
)116819362
ns/iter (± 1439385
)1.00
es/full/all/es2016
115618089
ns/iter (± 1139415
)114867685
ns/iter (± 1483834
)1.01
es/full/all/es2017
115560119
ns/iter (± 812321
)114815280
ns/iter (± 882306
)1.01
es/full/all/es2018
112997450
ns/iter (± 1708116
)112425090
ns/iter (± 1664909
)1.01
es/full/all/es2019
112210471
ns/iter (± 918013
)111800171
ns/iter (± 927539
)1.00
es/full/all/es2020
108142879
ns/iter (± 839416
)107668447
ns/iter (± 879134
)1.00
es/full/parser
490869
ns/iter (± 4803
)484279
ns/iter (± 7857
)1.01
es/full/base/fixer
18805
ns/iter (± 187
)18425
ns/iter (± 241
)1.02
es/full/base/resolver_and_hygiene
81280
ns/iter (± 315
)78884
ns/iter (± 922
)1.03
serialization of serde
281
ns/iter (± 5
)292
ns/iter (± 4
)0.96
This comment was automatically generated by workflow using github-action-benchmark.