Skip to content

Commit 2de09a7

Browse files
autofix-ci[bot]IWANABETHATGUY
authored andcommitted
[autofix.ci] apply automated fixes
1 parent 47b7cc3 commit 2de09a7

File tree

19 files changed

+125
-33
lines changed

19 files changed

+125
-33
lines changed

crates/rolldown/src/module_finalizers/mod.rs

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'me, 'ast> ScopeHoistingFinalizer<'me, 'ast> {
163163
} else {
164164
// Importee is not included (barrel module) — traverse its import records
165165
// to find included importees transitively.
166-
for rec in importee.import_records.iter() {
166+
for rec in &importee.import_records {
167167
if let Some(sub_importee_idx) = rec.resolved_module {
168168
self.generate_transitive_esm_init(sub_importee_idx, body);
169169
}
@@ -1317,23 +1317,31 @@ impl<'me, 'ast> ScopeHoistingFinalizer<'me, 'ast> {
13171317
.for_each(|((_top_stmt_idx, mut top_stmt), (stmt_info_idx, _stmt_info))| {
13181318
let is_stmt_included = self.ctx.linking_info.stmt_info_included.has_bit(stmt_info_idx);
13191319

1320-
// In strict execution order with ESM wrapping, excluded import/export
1321-
// declarations still need init calls for correct initialization order.
1322-
// Let them pass through to the import/export handling below.
1323-
let rescue_for_esm_init = !is_stmt_included
1324-
&& self.ctx.options.is_strict_execution_order_enabled()
1325-
&& matches!(self.ctx.linking_info.wrap_kind(), WrapKind::Esm);
1326-
1327-
if !is_stmt_included && !rescue_for_esm_init {
1320+
if !is_stmt_included {
1321+
// In strict execution order with ESM wrapping, excluded re-export
1322+
// statements still need init calls for correct initialization order.
1323+
if self.ctx.options.is_strict_execution_order_enabled()
1324+
&& matches!(self.ctx.linking_info.wrap_kind(), WrapKind::Esm)
1325+
{
1326+
let rec_idx = if let Some(export_all) = top_stmt.as_export_all_declaration() {
1327+
Some(self.ctx.module.imports[&export_all.span])
1328+
} else if let Some(named_decl) = top_stmt.as_export_named_declaration() {
1329+
named_decl.source.as_ref().map(|_| self.ctx.module.imports[&named_decl.span])
1330+
} else {
1331+
None
1332+
};
1333+
if let Some(importee_idx) =
1334+
rec_idx.and_then(|idx| self.ctx.module.import_records[idx].resolved_module)
1335+
{
1336+
self.generate_transitive_esm_init(importee_idx, &mut program.body);
1337+
}
1338+
}
13281339
return;
13291340
}
13301341

13311342
let is_module_decl = is_stmt_included && top_stmt.is_module_declaration_with_source();
13321343

13331344
if let Some(import_decl) = top_stmt.as_import_declaration() {
1334-
if !is_stmt_included {
1335-
return;
1336-
}
13371345
let span = import_decl.span;
13381346
let rec_idx = self.ctx.module.imports[&import_decl.span];
13391347
if self.transform_or_remove_import_export_stmt(&mut top_stmt, rec_idx) {
@@ -1349,14 +1357,6 @@ impl<'me, 'ast> ScopeHoistingFinalizer<'me, 'ast> {
13491357
}
13501358
} else if let Some(export_all_decl) = top_stmt.as_export_all_declaration() {
13511359
let rec_idx = self.ctx.module.imports[&export_all_decl.span];
1352-
if rescue_for_esm_init {
1353-
if let Some(importee_idx) =
1354-
self.ctx.module.import_records[rec_idx].resolved_module
1355-
{
1356-
self.generate_transitive_esm_init(importee_idx, &mut program.body);
1357-
}
1358-
return;
1359-
}
13601360
// "export * as ns from 'path'"
13611361
if let Some(_alias) = &export_all_decl.exported {
13621362
if self.transform_or_remove_import_export_stmt(&mut top_stmt, rec_idx) {
@@ -1614,25 +1614,12 @@ impl<'me, 'ast> ScopeHoistingFinalizer<'me, 'ast> {
16141614
} else {
16151615
// `export { foo } from 'path'`
16161616
let rec_idx = self.ctx.module.imports[&named_decl.span];
1617-
if rescue_for_esm_init {
1618-
if let Some(importee_idx) =
1619-
self.ctx.module.import_records[rec_idx].resolved_module
1620-
{
1621-
self.generate_transitive_esm_init(importee_idx, &mut program.body);
1622-
}
1623-
return;
1624-
}
16251617
if self.transform_or_remove_import_export_stmt(&mut top_stmt, rec_idx) {
16261618
return;
16271619
}
16281620
}
16291621
}
16301622

1631-
// Excluded non-import/export statements should not be emitted.
1632-
if !is_stmt_included {
1633-
return;
1634-
}
1635-
16361623
if self.ctx.options.top_level_var {
16371624
if let Statement::VariableDeclaration(var_decl) = &mut top_stmt {
16381625
var_decl.kind = ast::VariableDeclarationKind::Var;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"config": {
3+
"strictExecutionOrder": true,
4+
"minify": false
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import assert from 'node:assert';
2+
import { star } from './dist/main.js';
3+
4+
assert.strictEqual(star.foo, 1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let one;
2+
3+
one = 1;
4+
5+
export { one };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { foo } from './leaf.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { one } from './dep.js';
2+
3+
let foo;
4+
5+
foo = one;
6+
7+
export { foo };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { unused } from './unused.js';
2+
3+
export { star } from './outer.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as star from './inner.js';
2+
3+
export { star };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { star } from './ns.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"sideEffects": false
3+
}

0 commit comments

Comments
 (0)