@@ -78,6 +78,7 @@ pub struct Collect {
78
78
in_function : bool ,
79
79
in_assign : bool ,
80
80
in_class : bool ,
81
+ is_module : bool ,
81
82
}
82
83
83
84
#[ derive( Debug , Serialize ) ]
@@ -120,12 +121,14 @@ impl Collect {
120
121
ignore_mark : Mark ,
121
122
global_mark : Mark ,
122
123
trace_bailouts : bool ,
124
+ is_module : bool ,
123
125
) -> Self {
124
126
Collect {
125
127
source_map,
126
128
decls,
127
129
ignore_mark,
128
130
global_mark,
131
+ is_module,
129
132
static_cjs_exports : true ,
130
133
has_cjs_exports : false ,
131
134
is_esm : false ,
@@ -690,7 +693,9 @@ impl Visit for Collect {
690
693
}
691
694
Expr :: This ( _this) => {
692
695
if self . in_module_this {
693
- handle_export ! ( ) ;
696
+ if !self . is_module {
697
+ handle_export ! ( ) ;
698
+ }
694
699
} else if !self . in_class {
695
700
if let MemberProp :: Ident ( prop) = & node. prop {
696
701
self . this_exprs . insert ( id ! ( prop) , ( prop. clone ( ) , node. span ) ) ;
@@ -767,27 +772,6 @@ impl Visit for Collect {
767
772
self . used_imports . insert ( id ! ( ident) ) ;
768
773
}
769
774
}
770
- Expr :: Bin ( bin_expr) => {
771
- if self . in_module_this {
772
- // Some TSC polyfills use a pattern like below.
773
- // We want to avoid marking these modules as CJS
774
- // e.g. var _polyfill = (this && this.polyfill) || function () {}
775
- if matches ! ( bin_expr. op, BinaryOp :: LogicalAnd ) && matches ! ( * bin_expr. left, Expr :: This ( ..) )
776
- {
777
- match & * bin_expr. right {
778
- Expr :: Member ( member_expr) => {
779
- if matches ! ( * member_expr. obj, Expr :: This ( ..) )
780
- && matches ! ( member_expr. prop, MemberProp :: Ident ( ..) )
781
- {
782
- return ;
783
- }
784
- }
785
- _ => { }
786
- }
787
- }
788
- }
789
- node. visit_children_with ( self ) ;
790
- }
791
775
_ => {
792
776
node. visit_children_with ( self ) ;
793
777
}
@@ -820,7 +804,7 @@ impl Visit for Collect {
820
804
}
821
805
822
806
fn visit_this_expr ( & mut self , node : & ThisExpr ) {
823
- if self . in_module_this {
807
+ if ! self . is_module && self . in_module_this {
824
808
self . has_cjs_exports = true ;
825
809
self . static_cjs_exports = false ;
826
810
self . add_bailout ( node. span , BailoutReason :: FreeExports ) ;
0 commit comments