Skip to content

Commit

Permalink
fix: incremental provided exports should rebuild clean exports info
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Oct 25, 2024
1 parent e9ba1ba commit 65f9477
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 1 deletion.
34 changes: 34 additions & 0 deletions crates/rspack_core/src/exports_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ impl ExportsInfo {
info.other_exports_info
}

pub fn redirect_to(&self, mg: &ModuleGraph) -> Option<ExportsInfo> {
self.as_exports_info(mg).redirect_to
}

pub fn side_effects_only_info(&self, mg: &ModuleGraph) -> ExportInfo {
self.as_exports_info(mg).side_effects_only_info
}

pub fn as_exports_info<'a>(&self, mg: &'a ModuleGraph) -> &'a ExportsInfoData {
mg.get_exports_info_by_id(self)
}
Expand Down Expand Up @@ -105,6 +113,21 @@ impl ExportsInfo {
false
}

// TODO: remove this, we should refactor ExportInfo into ExportName and ExportProvideInfo and ExportUsedInfo
// ExportProvideInfo is created by FlagDependencyExportsPlugin, and should not mutate after create
// ExportUsedInfo is created by FlagDependencyUsagePlugin or Plugin::finish_modules, and should not mutate after create
pub fn reset_provide_info(&self, mg: &mut ModuleGraph) {
let exports: Vec<_> = self.exports(mg).collect();
for export_info in exports {
export_info.reset_provide_info(mg);
}
self.side_effects_only_info(mg).reset_provide_info(mg);
if let Some(redirect_to) = self.redirect_to(mg) {
redirect_to.reset_provide_info(mg);
}
self.other_exports_info(mg).reset_provide_info(mg);
}

/// # Panic
/// it will panic if you provide a export info that does not exists in the module graph
pub fn set_has_provide_info(&self, mg: &mut ModuleGraph) {
Expand Down Expand Up @@ -814,6 +837,17 @@ impl ExportInfo {
Self(NEXT_EXPORT_INFO_UKEY.fetch_add(1, Relaxed).into())
}

pub fn reset_provide_info(&self, mg: &mut ModuleGraph) {
let data = self.as_export_info_mut(mg);
data.provided = None;
data.can_mangle_provide = None;
data.exports_info_owned = false;
data.exports_info = None;
data.target_is_set = false;
data.target.clear();
data.terminal_binding = false;
}

pub fn name<'a>(&self, mg: &'a ModuleGraph) -> Option<&'a Atom> {
self.as_export_info(mg).name.as_ref()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ impl<'a> FlagDependencyExportsState<'a> {
.module_graph_module_by_identifier(&module_id)
.expect("mgm should exist");
let exports_info = mgm.exports;
// Reset exports provide info back to initial
exports_info.reset_provide_info(self.mg);

let module = self
.mg
.module_by_identifier(&mgm.module_identifier)
.module_by_identifier(&module_id)
.expect("should have module");
let is_module_without_exports = if let Some(build_meta) = module.build_meta() {
build_meta.exports_type == BuildMetaExportsType::Unset
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./b";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./c";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var x0 = "0";
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as a from "./a";

const nsObj = m => {
Object.defineProperty(m, Symbol.toStringTag, { value: "Module" });
return m;
};

it("should have to correct exports", () => {
expect(a).toStrictEqual(nsObj({
[`x${WATCH_STEP}`]: WATCH_STEP
}));
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var x1 = "1";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./c";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var x2 = "2";

0 comments on commit 65f9477

Please sign in to comment.