@@ -10,6 +10,7 @@ use swc_ecma_visit::{noop_fold_type, Fold, FoldWith, VisitWith};
10
10
11
11
use crate :: {
12
12
path:: { ImportResolver , Resolver } ,
13
+ top_level_this:: top_level_this,
13
14
util:: { local_name_for_src, use_strict} ,
14
15
} ;
15
16
#[ derive( Debug , Clone , Default , Serialize , Deserialize ) ]
@@ -33,7 +34,6 @@ struct SystemJs {
33
34
export_values : Vec < Box < Expr > > ,
34
35
tla : bool ,
35
36
enter_async_fn : u32 ,
36
- is_global_this : bool ,
37
37
root_fn_decl_idents : Vec < Ident > ,
38
38
module_item_meta_list : Vec < ModuleItemMeta > ,
39
39
import_idents : Vec < Id > ,
@@ -51,7 +51,6 @@ pub fn system_js(unresolved_mark: Mark, config: Config) -> impl Fold {
51
51
export_map : Default :: default ( ) ,
52
52
export_names : vec ! [ ] ,
53
53
export_values : vec ! [ ] ,
54
- is_global_this : true ,
55
54
tla : false ,
56
55
enter_async_fn : 0 ,
57
56
root_fn_decl_idents : vec ! [ ] ,
@@ -72,7 +71,6 @@ pub fn system_js_with_resolver(
72
71
unresolved_mark,
73
72
resolver : Resolver :: Real { base, resolver } ,
74
73
config,
75
- is_global_this : true ,
76
74
declare_var_idents : vec ! [ ] ,
77
75
export_map : Default :: default ( ) ,
78
76
export_names : vec ! [ ] ,
@@ -96,19 +94,6 @@ struct ModuleItemMeta {
96
94
}
97
95
98
96
impl SystemJs {
99
- fn fold_children_with_non_global_this < T > ( & mut self , n : T ) -> T
100
- where
101
- T : FoldWith < Self > ,
102
- {
103
- let is_global_this = self . is_global_this ;
104
-
105
- self . is_global_this = false ;
106
- let node = n. fold_children_with ( self ) ;
107
- self . is_global_this = is_global_this;
108
-
109
- node
110
- }
111
-
112
97
fn export_call ( & self , name : JsWord , span : Span , expr : Expr ) -> CallExpr {
113
98
CallExpr {
114
99
span,
@@ -609,12 +594,6 @@ impl Fold for SystemJs {
609
594
610
595
Expr :: Await ( await_expr)
611
596
}
612
- Expr :: This ( this_expr) => {
613
- if !self . config . allow_top_level_this && self . is_global_this {
614
- return * undefined ( DUMMY_SP ) ;
615
- }
616
- Expr :: This ( this_expr)
617
- }
618
597
_ => expr,
619
598
}
620
599
}
@@ -631,14 +610,6 @@ impl Fold for SystemJs {
631
610
fold_fn_expr
632
611
}
633
612
634
- fn fold_class_expr ( & mut self , n : ClassExpr ) -> ClassExpr {
635
- self . fold_children_with_non_global_this ( n)
636
- }
637
-
638
- fn fold_function ( & mut self , n : Function ) -> Function {
639
- self . fold_children_with_non_global_this ( n)
640
- }
641
-
642
613
fn fold_prop ( & mut self , prop : Prop ) -> Prop {
643
614
let prop = prop. fold_children_with ( self ) ;
644
615
@@ -659,6 +630,13 @@ impl Fold for SystemJs {
659
630
}
660
631
661
632
fn fold_module ( & mut self , module : Module ) -> Module {
633
+ let module = {
634
+ let mut module = module;
635
+ if !self . config . allow_top_level_this {
636
+ top_level_this ( & mut module, * undefined ( DUMMY_SP ) ) ;
637
+ }
638
+ module
639
+ } ;
662
640
let mut before_body_stmts: Vec < Stmt > = vec ! [ ] ;
663
641
let mut execute_stmts = vec ! [ ] ;
664
642
0 commit comments