Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incremental provided exports should rebuild clean exports info #8221

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
Loading