@@ -111,6 +111,9 @@ impl<'a> IsolatedDeclarations<'a> {
111
111
& mut self ,
112
112
stmts : & oxc_allocator:: Vec < ' a , Statement < ' a > > ,
113
113
) -> oxc_allocator:: Vec < ' a , Statement < ' a > > {
114
+ // https://github.com/microsoft/TypeScript/pull/58912
115
+ let mut need_empty_export_marker = true ;
116
+
114
117
let mut new_stmts = Vec :: new ( ) ;
115
118
let mut variables_declarations = VecDeque :: new ( ) ;
116
119
let mut variable_transformed_indexes = VecDeque :: new ( ) ;
@@ -140,13 +143,14 @@ impl<'a> IsolatedDeclarations<'a> {
140
143
new_stmts. push ( stmt) ;
141
144
}
142
145
match_module_declaration ! ( Statement ) => {
143
- transformed_indexes. push ( new_stmts. len ( ) ) ;
144
146
match stmt. to_module_declaration ( ) {
145
147
ModuleDeclaration :: ExportDefaultDeclaration ( decl) => {
148
+ transformed_indexes. push ( new_stmts. len ( ) ) ;
146
149
if let Some ( ( var_decl, new_decl) ) =
147
150
self . transform_export_default_declaration ( decl)
148
151
{
149
152
if let Some ( var_decl) = var_decl {
153
+ need_empty_export_marker = false ;
150
154
self . scope . visit_variable_declaration ( & var_decl) ;
151
155
new_stmts. push ( Statement :: VariableDeclaration (
152
156
self . ast . alloc ( var_decl) ,
@@ -161,10 +165,12 @@ impl<'a> IsolatedDeclarations<'a> {
161
165
continue ;
162
166
}
163
167
168
+ need_empty_export_marker = false ;
164
169
self . scope . visit_export_default_declaration ( decl) ;
165
170
}
166
171
167
172
ModuleDeclaration :: ExportNamedDeclaration ( decl) => {
173
+ transformed_indexes. push ( new_stmts. len ( ) ) ;
168
174
if let Some ( new_decl) = self . transform_export_named_declaration ( decl) {
169
175
self . scope . visit_declaration (
170
176
new_decl. declaration . as_ref ( ) . unwrap_or_else ( || unreachable ! ( ) ) ,
@@ -175,10 +181,14 @@ impl<'a> IsolatedDeclarations<'a> {
175
181
) ) ;
176
182
continue ;
177
183
}
178
-
184
+ need_empty_export_marker = false ;
179
185
self . scope . visit_export_named_declaration ( decl) ;
180
186
}
187
+ ModuleDeclaration :: ImportDeclaration ( _) => {
188
+ // We must transform this in the end, because we need to know all references
189
+ }
181
190
module_declaration => {
191
+ transformed_indexes. push ( new_stmts. len ( ) ) ;
182
192
self . scope . visit_module_declaration ( module_declaration) ;
183
193
}
184
194
}
@@ -190,6 +200,7 @@ impl<'a> IsolatedDeclarations<'a> {
190
200
}
191
201
192
202
// 5. Transform statements until no more transformation can be done
203
+ let last_transformed_len = transformed_indexes. len ( ) ;
193
204
let mut last_reference_len = 0 ;
194
205
while last_reference_len != self . scope . references_len ( ) {
195
206
last_reference_len = self . scope . references_len ( ) ;
@@ -259,6 +270,7 @@ impl<'a> IsolatedDeclarations<'a> {
259
270
) ,
260
271
) ;
261
272
new_ast_stmts. push ( Statement :: VariableDeclaration ( variables_declaration) ) ;
273
+ transformed_indexes. push ( index) ;
262
274
}
263
275
}
264
276
Statement :: UsingDeclaration ( decl) => {
@@ -280,6 +292,7 @@ impl<'a> IsolatedDeclarations<'a> {
280
292
) ,
281
293
) ;
282
294
new_ast_stmts. push ( Statement :: VariableDeclaration ( variable_declaration) ) ;
295
+ transformed_indexes. push ( index) ;
283
296
}
284
297
}
285
298
Statement :: ImportDeclaration ( decl) => {
@@ -294,6 +307,19 @@ impl<'a> IsolatedDeclarations<'a> {
294
307
}
295
308
}
296
309
310
+ if last_transformed_len == transformed_indexes. len ( ) {
311
+ need_empty_export_marker = false ;
312
+ }
313
+
314
+ if need_empty_export_marker {
315
+ let specifiers = self . ast . new_vec ( ) ;
316
+ let kind = ImportOrExportKind :: Value ;
317
+ let empty_export =
318
+ self . ast . export_named_declaration ( SPAN , None , specifiers, None , kind, None ) ;
319
+ new_ast_stmts
320
+ . push ( Statement :: from ( ModuleDeclaration :: ExportNamedDeclaration ( empty_export) ) ) ;
321
+ }
322
+
297
323
new_ast_stmts
298
324
}
299
325
0 commit comments