@@ -16,8 +16,8 @@ use crate::{
16
16
module_ref_rewriter:: { ImportMap , ModuleRefRewriter } ,
17
17
path:: { ImportResolver , Resolver } ,
18
18
util:: {
19
- clone_first_use_directive , define_es_module, emit_export_stmts, local_name_for_src,
20
- prop_name , use_strict , ImportInterop , ObjPropKeyIdent ,
19
+ define_es_module, emit_export_stmts, local_name_for_src, prop_name , use_strict ,
20
+ ImportInterop , ObjPropKeyIdent , VecStmtLike ,
21
21
} ,
22
22
} ;
23
23
@@ -113,15 +113,18 @@ where
113
113
114
114
let mut stmts: Vec < ModuleItem > = Vec :: with_capacity ( n. body . len ( ) + 6 ) ;
115
115
116
- stmts. extend ( clone_first_use_directive ( & n. body , false ) . map ( From :: from) ) ;
116
+ // Collect directives
117
+ stmts. extend (
118
+ & mut n
119
+ . body
120
+ . iter_mut ( )
121
+ . take_while ( |i| i. directive_continue ( ) )
122
+ . map ( |i| i. take ( ) ) ,
123
+ ) ;
117
124
118
125
// "use strict";
119
- if self . config . strict_mode {
120
- stmts. push (
121
- clone_first_use_directive ( & n. body , true )
122
- . unwrap_or_else ( use_strict)
123
- . into ( ) ,
124
- ) ;
126
+ if self . config . strict_mode && !stmts. has_use_strict ( ) {
127
+ stmts. push ( use_strict ( ) . into ( ) ) ;
125
128
}
126
129
127
130
let ModuleDeclStrip {
@@ -156,7 +159,7 @@ where
156
159
) ;
157
160
158
161
stmts. extend ( n. body . take ( ) . into_iter ( ) . filter ( |item| match item {
159
- ModuleItem :: Stmt ( stmt) => !stmt. is_directive ( ) ,
162
+ ModuleItem :: Stmt ( stmt) => !stmt. is_empty ( ) ,
160
163
_ => false ,
161
164
} ) ) ;
162
165
0 commit comments