@@ -11,15 +11,15 @@ use swc_ecmascript::{
11
11
visit:: { noop_fold_type, Fold } ,
12
12
} ;
13
13
14
- /// Note: This paths requires runnning `resolver` **before** running this.
14
+ /// Note: This paths requires running `resolver` **before** running this.
15
15
pub fn next_ssg ( ) -> impl Fold {
16
16
Repeat :: new ( NextSsg {
17
17
state : Default :: default ( ) ,
18
18
in_lhs_of_var : false ,
19
19
} )
20
20
}
21
21
22
- /// State of the transforms. Shared by the anayzer and the tranform .
22
+ /// State of the transforms. Shared by the analyzer and the transform .
23
23
#[ derive( Debug , Default ) ]
24
24
struct State {
25
25
/// Identifiers referenced by non-data function codes.
@@ -45,11 +45,7 @@ struct State {
45
45
46
46
impl State {
47
47
fn is_data_identifier ( & mut self , i : & Ident ) -> Result < bool , Error > {
48
- let ssg_exports = & [
49
- "getStaticProps" ,
50
- "getStaticPaths" ,
51
- "getServerSideProps" ,
52
- ] ;
48
+ let ssg_exports = & [ "getStaticProps" , "getStaticPaths" , "getServerSideProps" ] ;
53
49
54
50
if ssg_exports. contains ( & & * i. sym ) {
55
51
if & * i. sym == "getServerSideProps" {
@@ -125,7 +121,9 @@ impl Fold for Analyzer<'_> {
125
121
}
126
122
127
123
fn fold_export_named_specifier ( & mut self , s : ExportNamedSpecifier ) -> ExportNamedSpecifier {
128
- self . add_ref ( s. orig . to_id ( ) ) ;
124
+ if let ModuleExportName :: Ident ( id) = & s. orig {
125
+ self . add_ref ( id. to_id ( ) ) ;
126
+ }
129
127
130
128
s
131
129
}
@@ -189,7 +187,7 @@ impl Fold for Analyzer<'_> {
189
187
e
190
188
}
191
189
192
- /// Drops [ExportDecl] if all speicifers are removed.
190
+ /// Drops [ExportDecl] if all specifiers are removed.
193
191
fn fold_module_item ( & mut self , s : ModuleItem ) -> ModuleItem {
194
192
match s {
195
193
ModuleItem :: ModuleDecl ( ModuleDecl :: ExportNamed ( e) ) if !e. specifiers . is_empty ( ) => {
@@ -211,8 +209,7 @@ impl Fold for Analyzer<'_> {
211
209
ModuleItem :: ModuleDecl ( ModuleDecl :: ExportDecl ( e) ) => match & e. decl {
212
210
Decl :: Fn ( f) => {
213
211
// Drop getStaticProps.
214
- if let Ok ( is_data_identifier) = self . state . is_data_identifier ( & f. ident )
215
- {
212
+ if let Ok ( is_data_identifier) = self . state . is_data_identifier ( & f. ident ) {
216
213
if is_data_identifier {
217
214
return ModuleItem :: Stmt ( Stmt :: Empty ( EmptyStmt { span : DUMMY_SP } ) ) ;
218
215
}
@@ -493,29 +490,38 @@ impl Fold for NextSsg {
493
490
494
491
n. specifiers . retain ( |s| {
495
492
let preserve = match s {
496
- ExportSpecifier :: Namespace ( ExportNamespaceSpecifier { name : exported, .. } )
493
+ ExportSpecifier :: Namespace ( ExportNamespaceSpecifier {
494
+ name : ModuleExportName :: Ident ( exported) ,
495
+ ..
496
+ } )
497
497
| ExportSpecifier :: Default ( ExportDefaultSpecifier { exported, .. } )
498
498
| ExportSpecifier :: Named ( ExportNamedSpecifier {
499
- exported : Some ( exported) ,
499
+ exported : Some ( ModuleExportName :: Ident ( exported) ) ,
500
500
..
501
501
} ) => self
502
502
. state
503
503
. is_data_identifier ( & exported)
504
504
. map ( |is_data_identifier| !is_data_identifier) ,
505
- ExportSpecifier :: Named ( s) => self
505
+ ExportSpecifier :: Named ( ExportNamedSpecifier {
506
+ orig : ModuleExportName :: Ident ( orig) ,
507
+ ..
508
+ } ) => self
506
509
. state
507
- . is_data_identifier ( & s . orig )
510
+ . is_data_identifier ( & orig)
508
511
. map ( |is_data_identifier| !is_data_identifier) ,
512
+
513
+ _ => Ok ( true ) ,
509
514
} ;
510
515
511
516
match preserve {
512
517
Ok ( false ) => {
513
- tracing:: trace!(
514
- "Dropping a export specifier because it's a data identifier"
515
- ) ;
518
+ tracing:: trace!( "Dropping a export specifier because it's a data identifier" ) ;
516
519
517
520
match s {
518
- ExportSpecifier :: Named ( ExportNamedSpecifier { orig, .. } ) => {
521
+ ExportSpecifier :: Named ( ExportNamedSpecifier {
522
+ orig : ModuleExportName :: Ident ( orig) ,
523
+ ..
524
+ } ) => {
519
525
self . state . should_run_again = true ;
520
526
self . state . refs_from_data_fn . insert ( orig. to_id ( ) ) ;
521
527
}
0 commit comments