Skip to content

Commit

Permalink
fix: dynamic import as entry (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Nov 22, 2023
1 parent 6f2b75a commit 8d33829
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
12 changes: 8 additions & 4 deletions crates/rolldown/src/bundler/module_loader/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,21 @@ impl<T: FileSystem + 'static + Default> ModuleLoader<T> {

self.intermediate_modules.reserve(user_defined_entries.len() + 1 /* runtime */);

// Store the already consider as entry module
let mut entry_module_set = FxHashSet::default();
let mut entries = user_defined_entries
.iter()
.map(|(name, info)| EntryPoint {
name: name.clone(),
module_id: self.try_spawn_new_task(info, true),
kind: EntryPointKind::UserSpecified,
})
.inspect(|e| {
entry_module_set.insert(e.module_id);
})
.collect::<Vec<_>>();

let mut dynamic_entries = FxHashSet::default();
let mut dynamic_entries = vec![];

let mut runtime_brief: Option<RuntimeModuleBrief> = None;

Expand All @@ -167,8 +172,8 @@ impl<T: FileSystem + 'static + Default> ModuleLoader<T> {
.map(|(raw_rec, info)| {
let id = self.try_spawn_new_task(&info, false);
// dynamic import as extra entries if enable code splitting
if raw_rec.kind == ImportKind::DynamicImport {
dynamic_entries.insert(EntryPoint {
if raw_rec.kind == ImportKind::DynamicImport && !entry_module_set.contains(&id) {
dynamic_entries.push(EntryPoint {
name: Some(info.path.unique(&self.input_options.cwd)),
module_id: id,
kind: EntryPointKind::DynamicImport,
Expand Down Expand Up @@ -203,7 +208,6 @@ impl<T: FileSystem + 'static + Default> ModuleLoader<T> {

let modules = self.intermediate_modules.into_iter().map(Option::unwrap).collect();

let mut dynamic_entries = Vec::from_iter(dynamic_entries);
dynamic_entries.sort_unstable_by(|a, b| a.name.cmp(&b.name));
entries.extend(dynamic_entries);
Ok(ModuleLoaderOutput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,16 @@ input_file: crates/rolldown/tests/esbuild/splitting/dynamic_import_issue_272
---
# Assets

## 3.mjs

```js
// b.js
var b_default = 1
export { b_default };
```
## a.mjs

```js
// a.js
import('./3.mjs')
import('./b.mjs')
```
## b.mjs

```js
import { b_default } from "./3.mjs";
export { b_default as default };
```
## b_js.mjs

```js
import { b_default } from "./3.mjs";
// b.js
var b_default = 1
export { b_default as default };
```

0 comments on commit 8d33829

Please sign in to comment.