Skip to content

Commit

Permalink
fix: duplicated module import info
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Dec 17, 2024
1 parent 786b6d2 commit 321e261
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
13 changes: 5 additions & 8 deletions crates/rolldown/src/ecmascript/ecma_module_view_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rolldown_common::{
use rolldown_ecmascript::EcmaAst;
use rolldown_error::BuildResult;
use rolldown_std_utils::PathExt;
use rolldown_utils::ecmascript::legitimize_identifier_name;
use rolldown_utils::{ecmascript::legitimize_identifier_name, indexmap::FxIndexSet};
use rustc_hash::FxHashMap;
use sugar_path::SugarPath;

Expand Down Expand Up @@ -120,9 +120,6 @@ pub async fn create_ecma_view<'any>(
}
ctx.warnings.extend(scan_warnings);

let imported_ids = vec![];
let dynamically_imported_ids = vec![];

// The side effects priority is:
// 1. Hook side effects
// 2. Package.json side effects
Expand Down Expand Up @@ -197,10 +194,10 @@ pub async fn create_ecma_view<'any>(
def_format: ctx.resolved_id.module_def_format,
sourcemap_chain: args.sourcemap_chain,
import_records: IndexVec::default(),
importers: vec![],
dynamic_importers: vec![],
imported_ids,
dynamically_imported_ids,
importers: FxIndexSet::default(),
dynamic_importers: FxIndexSet::default(),
imported_ids: FxIndexSet::default(),
dynamically_imported_ids: FxIndexSet::default(),
side_effects,
ast_usage,
self_referenced_class_decl_symbol_ids,
Expand Down
13 changes: 7 additions & 6 deletions crates/rolldown/src/module_loader/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use rolldown_error::{BuildDiagnostic, BuildResult};
use rolldown_fs::OsFileSystem;
use rolldown_plugin::SharedPluginDriver;
use rolldown_utils::ecmascript::legitimize_identifier_name;
use rolldown_utils::indexmap::FxIndexSet;
use rolldown_utils::rustc_hash::FxHashSetExt;
use rustc_hash::{FxHashMap, FxHashSet};
use std::sync::Arc;
Expand Down Expand Up @@ -184,10 +185,10 @@ impl ModuleLoader {
code: None,
id,
is_entry: false,
importers: vec![],
dynamic_importers: vec![],
imported_ids: vec![],
dynamically_imported_ids: vec![],
importers: FxIndexSet::default(),
dynamic_importers: FxIndexSet::default(),
imported_ids: FxIndexSet::default(),
dynamically_imported_ids: FxIndexSet::default(),
exports: vec![],
}),
);
Expand Down Expand Up @@ -421,9 +422,9 @@ impl ModuleLoader {
let importers = std::mem::take(&mut self.intermediate_normal_modules.importers[id]);
for importer in &importers {
if importer.kind.is_static() {
module.importers.push(importer.importer_path.clone());
module.importers.insert(importer.importer_path.clone());
} else {
module.dynamic_importers.push(importer.importer_path.clone());
module.dynamic_importers.insert(importer.importer_path.clone());
}
}
if !importers.is_empty() {
Expand Down
13 changes: 7 additions & 6 deletions crates/rolldown/src/module_loader/module_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rolldown_std_utils::PathExt;
use rolldown_utils::{
concat_string,
ecmascript::{self, legitimize_identifier_name},
indexmap::FxIndexSet,
};
use std::sync::Arc;
use sugar_path::SugarPath;
Expand Down Expand Up @@ -98,10 +99,10 @@ impl ModuleTask {
code: None,
id: id.clone(),
is_entry: self.is_user_defined_entry,
importers: vec![],
dynamic_importers: vec![],
imported_ids: vec![],
dynamically_imported_ids: vec![],
importers: FxIndexSet::default(),
dynamic_importers: FxIndexSet::default(),
imported_ids: FxIndexSet::default(),
dynamically_imported_ids: FxIndexSet::default(),
exports: vec![],
}),
);
Expand Down Expand Up @@ -229,10 +230,10 @@ impl ModuleTask {
for (record, info) in raw_import_records.iter().zip(&resolved_deps) {
match record.kind {
ImportKind::Import | ImportKind::Require | ImportKind::NewUrl => {
ecma_view.imported_ids.push(ArcStr::clone(&info.id).into());
ecma_view.imported_ids.insert(ArcStr::clone(&info.id).into());
}
ImportKind::DynamicImport => {
ecma_view.dynamically_imported_ids.push(ArcStr::clone(&info.id).into());
ecma_view.dynamically_imported_ids.insert(ArcStr::clone(&info.id).into());
}
// for a none css module, we should not have `at-import` or `url-import`
ImportKind::AtImport | ImportKind::UrlImport => unreachable!(),
Expand Down
9 changes: 5 additions & 4 deletions crates/rolldown/src/module_loader/runtime_module_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rolldown_common::{
};
use rolldown_ecmascript::{EcmaAst, EcmaCompiler};
use rolldown_error::BuildResult;
use rolldown_utils::indexmap::FxIndexSet;
use rustc_hash::{FxHashMap, FxHashSet};

use crate::{
Expand Down Expand Up @@ -110,10 +111,10 @@ impl RuntimeModuleTask {
import_records: IndexVec::default(),
sourcemap_chain: vec![],
// The internal runtime module `importers/imported` should be skip.
importers: vec![],
dynamic_importers: vec![],
imported_ids: vec![],
dynamically_imported_ids: vec![],
importers: FxIndexSet::default(),
dynamic_importers: FxIndexSet::default(),
imported_ids: FxIndexSet::default(),
dynamically_imported_ids: FxIndexSet::default(),
side_effects: DeterminedSideEffects::Analyzed(false),
named_imports,
named_exports,
Expand Down
9 changes: 5 additions & 4 deletions crates/rolldown_common/src/ecmascript/ecma_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bitflags::bitflags;
use oxc::{semantic::SymbolId, span::Span};
use oxc_index::IndexVec;
use rolldown_rstr::Rstr;
use rolldown_utils::indexmap::FxIndexSet;
use rustc_hash::{FxHashMap, FxHashSet};

use crate::{
Expand Down Expand Up @@ -108,13 +109,13 @@ pub struct EcmaView {
pub default_export_ref: SymbolRef,
pub sourcemap_chain: Vec<rolldown_sourcemap::SourceMap>,
// the ids of all modules that statically import this module
pub importers: Vec<ModuleId>,
pub importers: FxIndexSet<ModuleId>,
// the ids of all modules that import this module via dynamic import()
pub dynamic_importers: Vec<ModuleId>,
pub dynamic_importers: FxIndexSet<ModuleId>,
// the module ids statically imported by this module
pub imported_ids: Vec<ModuleId>,
pub imported_ids: FxIndexSet<ModuleId>,
// the module ids imported by this module via dynamic import()
pub dynamically_imported_ids: Vec<ModuleId>,
pub dynamically_imported_ids: FxIndexSet<ModuleId>,
pub side_effects: DeterminedSideEffects,
pub ast_usage: EcmaModuleAstUsage,
pub self_referenced_class_decl_symbol_ids: FxHashSet<SymbolId>,
Expand Down
9 changes: 5 additions & 4 deletions crates/rolldown_common/src/types/module_info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use arcstr::ArcStr;
use rolldown_utils::indexmap::FxIndexSet;

use crate::ModuleId;

Expand All @@ -7,9 +8,9 @@ pub struct ModuleInfo {
pub code: Option<ArcStr>,
pub id: ModuleId,
pub is_entry: bool,
pub importers: Vec<ModuleId>,
pub dynamic_importers: Vec<ModuleId>,
pub imported_ids: Vec<ModuleId>,
pub dynamically_imported_ids: Vec<ModuleId>,
pub importers: FxIndexSet<ModuleId>,
pub dynamic_importers: FxIndexSet<ModuleId>,
pub imported_ids: FxIndexSet<ModuleId>,
pub dynamically_imported_ids: FxIndexSet<ModuleId>,
pub exports: Vec<ArcStr>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export default defineTest({
expect(moduleInfo.importedIds).toStrictEqual([
'external',
path.join(import.meta.dirname, 'static.js'),
// TODO: should be duplicated
path.join(import.meta.dirname, 'static.js'),
])
expect(moduleInfo.dynamicallyImportedIds).toStrictEqual([
path.join(import.meta.dirname, 'dynamic.js'),
Expand All @@ -53,8 +51,6 @@ export default defineTest({
expect(moduleInfo.dynamicallyImportedIds).toStrictEqual([])
expect(moduleInfo.importers).toStrictEqual([
path.join(import.meta.dirname, 'main.js'),
// TODO: should be duplicated
path.join(import.meta.dirname, 'main.js'),
])
expect(moduleInfo.dynamicImporters).toStrictEqual([])
break
Expand Down

0 comments on commit 321e261

Please sign in to comment.