From 25edcdcedb96dd81ba2a098d3b31034a51afa1d3 Mon Sep 17 00:00:00 2001 From: Fy <1114550440@qq.com> Date: Wed, 22 May 2024 17:02:24 +0800 Subject: [PATCH] chore: remove old treeshaking (#6549) * chore: remove old treeshaking * chore: remove builtin option --- crates/node_binding/binding.d.ts | 3 +- .../rspack_binding_options/src/options/mod.rs | 10 +- .../raw_builtins/raw_to_be_deprecated.rs | 1 - .../src/options/raw_experiments.rs | 11 +- .../src/build_chunk_graph/code_splitter.rs | 10 +- .../rspack_core/src/compiler/compilation.rs | 43 +- crates/rspack_core/src/compiler/make/mod.rs | 58 +- .../src/compiler/make/repair/add.rs | 13 +- .../src/compiler/make/repair/build.rs | 5 - .../src/compiler/make/repair/mod.rs | 7 +- crates/rspack_core/src/compiler/mod.rs | 101 +- .../src/dependency/runtime_template.rs | 5 +- crates/rspack_core/src/module.rs | 2 - crates/rspack_core/src/module_graph/mod.rs | 30 +- .../rspack_core/src/normal_module_factory.rs | 41 +- crates/rspack_core/src/options/builtins.rs | 51 - .../src/options/compiler_options.rs | 4 - crates/rspack_core/src/options/experiments.rs | 5 +- crates/rspack_core/src/tree_shaking/mod.rs | 1 - .../rspack_core/src/tree_shaking/optimizer.rs | 2280 ----------------- .../rspack_core/src/tree_shaking/visitor.rs | 16 +- crates/rspack_plugin_asset/src/lib.rs | 51 +- .../harmony_export_expression_dependency.rs | 18 +- ...ny_export_imported_specifier_dependency.rs | 114 +- .../harmony_export_specifier_dependency.rs | 10 +- .../esm/harmony_import_dependency.rs | 49 +- .../harmony_import_specifier_dependency.rs | 91 +- .../src/dependency/export_info_api_dep.rs | 16 +- .../src/parser_and_generator/mod.rs | 66 +- ...harmony_import_dependency_parser_plugin.rs | 5 - .../src/plugin/side_effects_flag_plugin.rs | 2 - .../rspack_plugin_javascript/src/runtime.rs | 5 - .../src/assign_library_plugin.rs | 13 - .../src/module_library_plugin.rs | 45 +- diffcases/arco-pro/rspack.config.js | 5 +- packages/rspack-cli/src/rspack-cli.ts | 1 - .../rspack-test-tools/src/case/builtin.ts | 3 +- .../src/processor/builtin.ts | 16 +- .../rspack-test-tools/src/processor/config.ts | 5 - .../rspack-test-tools/src/processor/hook.ts | 5 - .../rspack-test-tools/src/processor/normal.ts | 4 - .../tests/__snapshots__/Defaults.test.js.snap | 2 - .../ancestor-has-all-modules/rspack.config.js | 5 - .../concatenate-modules/rspack.config.js | 5 - .../cycle-dynamic-entry/rspack.config.js | 5 - .../samples/cycle-entry/rspack.config.js | 5 - .../samples/intersection/rspack.config.js | 5 - .../samples/mangle-exports/rspack.config.js | 5 - .../rspack.config.js | 5 - .../samples/self-import/rspack.config.js | 5 - .../samples/simple/rspack.config.js | 5 - .../esm/__snapshots__/output.snap.txt | 2 +- .../ts/__snapshots__/output.snap.txt | 2 +- .../rspack.config.js | 5 - .../rspack.config.js | 4 +- .../rspack.config.js | 4 +- .../rspack.config.js | 4 +- .../chunk-loading/issue-4800/rspack.config.js | 4 +- .../cjs-interop/rspack.config.js | 5 - .../export-require-bailout/rspack.config.js | 5 - .../export-require-unused/rspack.config.js | 5 - .../rspack-issue-5282/rspack.config.js | 5 - .../with-css/rspack.config.js | 3 - .../0-container-full/rspack.config.js | 3 - .../1-container-full/rspack.config.js | 3 - .../2-container-full/rspack.config.js | 5 - .../2-transitive-overriding/rspack.config.js | 5 - .../rspack.config.js | 5 - .../rspack.config.js | 4 +- .../duplicate-module-library/rspack.config.js | 3 - .../library/esm-external/rspack.config.js | 3 - .../codegen-cache/rspack.config.js | 5 - .../loader-import-module/css/rspack.config.js | 5 - .../recursive-import-module/rspack.config.js | 5 - .../rspack.config.js | 3 - .../module/rspack-issue-5548/rspack.config.js | 5 - .../rspack-issue-4784/rspack.config.js | 3 - .../schemes/data-imports/rspack.config.js | 3 - .../rspack.config.js | 4 +- .../tree-shaking/assets1/rspack.config.js | 3 - .../rspack.config.js | 5 - .../export-default-alias/rspack.config.js | 9 +- .../rspack.config.js | 4 +- .../import-by-name-json/rspack.config.js | 5 - .../inner-graph-static-block/rspack.config.js | 5 - .../tree-shaking/issue-5782/rspack.config.js | 5 - .../json-empty-array/rspack.config.js | 5 - .../rspack.config.js | 4 +- .../rspack.config.js | 4 +- .../rspack.config.js | 4 +- .../tree-shaking/new-url/rspack.config.js | 4 +- .../side-effects-rule/rspack.config.js | 4 +- .../used-exports-global/rspack.config.js | 5 - .../used-exports-true/rspack.config.js | 5 - .../export_star_error/rspack.config.js | 5 - .../export_star_error/test.filter.js | 1 + .../tests/errorCases/warning-test-push.js | 2 +- .../tests/errorCases/warning-test-shift.js | 2 +- .../tests/errorCases/warning-test-splice-1.js | 2 +- .../tests/errorCases/warning-test-splice-2.js | 2 +- .../auto-reexport/rspack.config.js | 3 - .../rspack.config.js | 5 - .../module-esm-export/rspack.config.js | 5 - .../module-esm-import/rspack.config.js | 5 - .../module-esmodule-usage/rspack.config.js | 5 - .../tests/statsAPICases/exports.js | 5 - .../css-concat-error/rspack.config.js | 3 - .../runtime-specific-exports/rspack.config.js | 5 - .../side-effects-bailouts/rspack.config.js | 5 - .../array-side-effects/rspack.config.js | 3 +- .../issues_3198/rspack.config.js | 4 +- .../__snapshots__/treeshaking.snap.txt | 8 +- .../__snapshots__/treeshaking.snap.txt | 8 +- packages/rspack/etc/api.md | 33 - packages/rspack/src/Compiler.ts | 14 +- .../src/builtin-plugin/css-extract/loader.ts | 13 - packages/rspack/src/config/adapter.ts | 11 +- packages/rspack/src/config/defaults.ts | 1 - packages/rspack/src/config/normalization.ts | 7 +- packages/rspack/src/config/zod.ts | 7 - packages/rspack/src/rspackOptionsApply.ts | 42 +- plugin-test/css-extract/TestCache.test.js | 11 +- plugin-test/css-extract/TestCases.test.js | 6 - .../rspack.config.js | 3 - plugin-test/css-extract/emitOption.test.js | 9 - .../css-extract/helpers/getCompiler.js | 3 - .../css-extract/ignoreOrderOption.test.js | 6 - webpack-test/ConfigTestCases.template.js | 5 - webpack-test/TestCases.template.js | 4 - .../cjs-to-esm/test.config.js | 5 +- .../esModule-getter/test.config.js | 5 +- .../esm-to-cjs/test.config.js | 5 +- .../cjs-tree-shaking/exports/test.config.js | 5 +- .../cjs-tree-shaking/importing/test.config.js | 5 +- .../cases/cjs-tree-shaking/mjs/test.config.js | 5 +- .../cjs-tree-shaking/namespace/test.config.js | 5 +- .../non-root-this/test.config.js | 5 +- .../test.config.js | 5 +- .../cjs-tree-shaking/objects/test.config.js | 5 +- .../cjs-tree-shaking/parsing/test.config.js | 5 +- .../cjs-tree-shaking/reexports/test.config.js | 5 +- .../transpiled/test.config.js | 5 +- .../weird-names/test.config.js | 5 +- .../cases/inner-graph/circular/test.config.js | 5 +- .../inner-graph/circular2/test.config.js | 5 +- .../class-dynamic-props/test.config.js | 5 +- .../export-default-named/test.config.js | 5 +- .../inner-graph/extend-class/test.config.js | 7 +- .../inner-graph/extend-class2/test.config.js | 6 - .../no-side-effects/test.config.js | 6 - .../pure-in-removed/test.config.js | 6 - .../test.config.js | 8 +- .../cases/inner-graph/simple/test.config.js | 8 +- .../static-of-class/test.config.js | 8 +- .../cases/inner-graph/switch/test.config.js | 8 +- .../inner-graph/try-globals/test.config.js | 8 +- .../concat-star-import/test.config.js | 8 +- .../optimize/many-exports-100/test.config.js | 8 +- .../optimize/many-exports-120/test.config.js | 8 +- .../optimize/many-exports-40/test.config.js | 8 +- .../test.config.js | 8 +- .../side-effects-all-used/test.config.js | 8 +- .../test.config.js | 8 +- .../side-effects-root-unused/test.config.js | 8 +- .../test.config.js | 8 +- .../side-effects-simple-unused/test.config.js | 8 +- .../test.config.js | 8 +- .../tree-shaking-commonjs/test.config.js | 8 +- .../optimize/tree-shaking-star/test.config.js | 8 +- .../tree-shaking-star2/test.config.js | 8 +- .../cases/parsing/issue-7519/test.config.js | 5 - .../async-keyword-5615/test.config.js | 6 +- .../chained-reexport/test.config.js | 6 +- .../circular-external/test.config.js | 6 +- .../circular-namespace-object/test.config.js | 6 +- .../delete-issue-10831/test.config.js | 6 +- .../scope-hoisting/esModule/test.config.js | 6 +- .../export-namespace/test.config.js | 6 +- .../external-root/test.config.js | 6 +- .../import-order-11617/test.config.js | 5 - .../import-order/test.config.js | 5 - .../indirect-reexport/test.config.js | 5 - .../inside-class/test.config.js | 5 - .../intra-references/test.config.js | 5 - .../scope-hoisting/issue-10308/test.config.js | 5 - .../scope-hoisting/issue-10409/test.config.js | 5 - .../scope-hoisting/issue-11840/test.config.js | 5 - .../scope-hoisting/issue-11897/test.config.js | 5 - .../issue-5020-minimal/test.config.js | 5 - .../scope-hoisting/issue-5020/test.config.js | 5 - .../scope-hoisting/issue-5096/test.config.js | 5 - .../scope-hoisting/issue-5314/test.config.js | 5 - .../scope-hoisting/issue-5443/test.config.js | 5 - .../scope-hoisting/issue-5481/test.config.js | 5 - .../scope-hoisting/issue-6407/test.config.js | 5 - .../scope-hoisting/issue-7930/test.config.js | 5 - .../json-reexport-6700/test.config.js | 5 - .../name-conflicts/test.config.js | 5 - .../order-without-side-effects/test.config.js | 5 - .../scope-hoisting/orphan/test.config.js | 5 - .../reexport-cjs/test.config.js | 5 - .../reexport-exposed-cjs/test.config.js | 5 - .../test.config.js | 5 - .../reexport-exposed-harmony/test.config.js | 5 - .../reexport-star-exposed-cjs/test.config.js | 5 - .../reexport-star-external-cjs/test.config.js | 5 - .../renaming-4967/test.config.js | 5 - .../renaming-shorthand-5027/test.config.js | 5 - .../require-root-5604/test.config.js | 5 - .../side-effects-11662/test.config.js | 5 - .../side-effects-11990-star/test.config.js | 5 - .../side-effects-11990/test.config.js | 5 - .../side-effects-9159/test.config.js | 6 +- .../scope-hoisting/simple/test.config.js | 6 +- .../this-in-import/test.config.js | 6 +- .../dynamic-reexports/test.config.js | 8 +- .../side-effects/empty-modules/test.config.js | 8 +- .../side-effects/issue-11673/test.config.js | 8 +- .../side-effects/issue-12071/test.config.js | 8 +- .../side-effects/issue-12114/test.config.js | 8 +- .../issue-12570-second-try/test.config.js | 8 +- .../side-effects/issue-12570/test.config.js | 8 +- .../missing-module-7499/test.config.js | 8 +- .../order-issue-7665/test.config.js | 8 +- .../wrong-module-10146/test.config.js | 8 +- .../webpack.config.js | 5 - .../class-naming/rspack.config.js | 5 - website/docs/en/config/experiments.mdx | 7 +- website/docs/zh/config/experiments.mdx | 7 +- 229 files changed, 291 insertions(+), 4020 deletions(-) delete mode 100644 crates/rspack_core/src/tree_shaking/optimizer.rs create mode 100644 packages/rspack-test-tools/tests/diagnosticsCases/factorize/export_star_error/test.filter.js diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 418f13bb4d9..6c6439a3ad9 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -1134,7 +1134,6 @@ export interface RawOptions { node?: RawNodeOption profile: boolean bail: boolean - builtins: RawBuiltins } export interface RawOutputOptions { @@ -1282,7 +1281,7 @@ export interface RawResolveTsconfigOptions { } export interface RawRspackFuture { - newTreeshaking: boolean + } export interface RawRuleSetCondition { diff --git a/crates/rspack_binding_options/src/options/mod.rs b/crates/rspack_binding_options/src/options/mod.rs index d572c9603d0..532e03cb511 100644 --- a/crates/rspack_binding_options/src/options/mod.rs +++ b/crates/rspack_binding_options/src/options/mod.rs @@ -1,7 +1,7 @@ use napi_derive::napi; use rspack_core::{ CacheOptions, CompilerOptions, Context, Experiments, IncrementalRebuild, - IncrementalRebuildMakeState, ModuleOptions, OutputOptions, Target, TreeShaking, + IncrementalRebuildMakeState, ModuleOptions, OutputOptions, Target, }; mod raw_builtins; @@ -58,7 +58,6 @@ pub struct RawOptions { pub node: Option, pub profile: bool, pub bail: bool, - pub builtins: RawBuiltins, } impl TryFrom for CompilerOptions { @@ -90,11 +89,6 @@ impl TryFrom for CompilerOptions { let snapshot = value.snapshot.into(); let node = value.node.map(|n| n.into()); - let mut builtins = value.builtins.apply()?; - if experiments.rspack_future.new_treeshaking { - builtins.tree_shaking = TreeShaking::False; - } - Ok(CompilerOptions { context, mode, @@ -112,7 +106,7 @@ impl TryFrom for CompilerOptions { dev_server: Default::default(), profile: value.profile, bail: value.bail, - builtins, + builtins: Default::default(), }) } } diff --git a/crates/rspack_binding_options/src/options/raw_builtins/raw_to_be_deprecated.rs b/crates/rspack_binding_options/src/options/raw_builtins/raw_to_be_deprecated.rs index 85188523b91..b91d524db8f 100644 --- a/crates/rspack_binding_options/src/options/raw_builtins/raw_to_be_deprecated.rs +++ b/crates/rspack_binding_options/src/options/raw_builtins/raw_to_be_deprecated.rs @@ -148,7 +148,6 @@ impl RawBuiltins { Ok(Builtins { define: Default::default(), provide: Default::default(), - tree_shaking: self.tree_shaking.into(), }) } } diff --git a/crates/rspack_binding_options/src/options/raw_experiments.rs b/crates/rspack_binding_options/src/options/raw_experiments.rs index 9a249f885e7..5c7dc567e0a 100644 --- a/crates/rspack_binding_options/src/options/raw_experiments.rs +++ b/crates/rspack_binding_options/src/options/raw_experiments.rs @@ -1,11 +1,10 @@ use napi_derive::napi; use rspack_core::RspackFuture; +#[allow(clippy::empty_structs_with_brackets)] #[derive(Debug, Default)] #[napi(object)] -pub struct RawRspackFuture { - pub new_treeshaking: bool, -} +pub struct RawRspackFuture {} #[derive(Debug, Default)] #[napi(object)] @@ -15,9 +14,7 @@ pub struct RawExperiments { } impl From for RspackFuture { - fn from(value: RawRspackFuture) -> Self { - Self { - new_treeshaking: value.new_treeshaking, - } + fn from(_value: RawRspackFuture) -> Self { + Self {} } } diff --git a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs index 56d145b0f49..05163a61c67 100644 --- a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs +++ b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs @@ -1382,11 +1382,11 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on let modules = map .get_mut(&block_id) .expect("should have modules in block_modules_runtime_map"); - let active_state = if self.compilation.options.is_new_tree_shaking() { - get_active_state_of_connections(&connections, runtime, &self.compilation.get_module_graph()) - } else { - ConnectionState::Bool(true) - }; + let active_state = get_active_state_of_connections( + &connections, + runtime, + &self.compilation.get_module_graph(), + ); modules.push((module_identifier, active_state, connections)); } } diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index d7e71459eb8..2a48895df13 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -10,7 +10,7 @@ use dashmap::{DashMap, DashSet}; use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; use rayon::prelude::*; -use rspack_error::{error, Diagnostic, Result, Severity, TWithDiagnosticArray}; +use rspack_error::{error, Diagnostic, Result, Severity}; use rspack_futures::FuturesResults; use rspack_hash::{RspackHash, RspackHashDigest}; use rspack_hook::define_hook; @@ -25,12 +25,13 @@ use super::{ make::{make_module_graph, update_module_graph, MakeArtifact, MakeParam}, module_executor::ModuleExecutor, }; +use crate::ExecuteModuleId; use crate::{ build_chunk_graph::build_chunk_graph, cache::{use_code_splitting_cache, Cache, CodeSplittingCache}, get_chunk_from_ukey, get_mut_chunk_from_ukey, is_source_equal, prepare_get_exports_type, to_identifier, - tree_shaking::{optimizer, visitor::SymbolRef, BailoutFlag, OptimizeDependencyResult}, + tree_shaking::visitor::SymbolRef, BoxDependency, BoxModule, CacheCount, CacheOptions, Chunk, ChunkByUkey, ChunkContentHash, ChunkGraph, ChunkGroupByUkey, ChunkGroupUkey, ChunkKind, ChunkUkey, CodeGenerationResults, CompilationLogger, CompilationLogging, CompilerOptions, DependencyId, DependencyType, Entry, @@ -39,7 +40,6 @@ use crate::{ ResolverFactory, RuntimeGlobals, RuntimeModule, RuntimeSpec, SharedPluginDriver, SourceType, Stats, }; -use crate::{tree_shaking::visitor::OptimizeAnalyzeResult, ExecuteModuleId}; pub type BuildDependency = ( DependencyId, @@ -159,8 +159,6 @@ pub struct Compilation { pub(crate) named_chunk_groups: HashMap, /// Collecting all used export symbol pub used_symbol_ref: HashSet, - /// Collecting all module that need to skip in tree-shaking ast modification phase - pub bailout_module_identifiers: IdentifierMap, pub code_generation_results: CodeGenerationResults, pub code_generated_modules: IdentifierSet, @@ -170,7 +168,6 @@ pub struct Compilation { // lazy compilation visit module pub lazy_visit_modules: std::collections::HashSet, pub used_chunk_ids: HashSet, - pub include_module_ids: IdentifierSet, pub file_dependencies: IndexSet>, pub context_dependencies: IndexSet>, @@ -247,7 +244,6 @@ impl Compilation { named_chunks: Default::default(), named_chunk_groups: Default::default(), used_symbol_ref: HashSet::default(), - bailout_module_identifiers: IdentifierMap::default(), code_generation_results: Default::default(), code_generated_modules: Default::default(), @@ -263,7 +259,6 @@ impl Compilation { build_dependencies: Default::default(), side_effects_free_modules: IdentifierSet::default(), module_item_map: IdentifierMap::default(), - include_module_ids: IdentifierSet::default(), import_var_map: DashMap::new(), @@ -696,12 +691,10 @@ impl Compilation { ) .await?; - if self.options.is_new_tree_shaking() { - let logger = self.get_logger("rspack.Compilation"); - let start = logger.time("finish module"); - self.finish(self.plugin_driver.clone()).await?; - logger.time_end(start); - } + let logger = self.get_logger("rspack.Compilation"); + let start = logger.time("finish module"); + self.finish(self.plugin_driver.clone()).await?; + logger.time_end(start); let module_graph = self.get_module_graph(); Ok(f(module_identifiers @@ -725,8 +718,7 @@ impl Compilation { ) -> Result<()> { // If the runtime optimization is not opt out, a module codegen should be executed for each runtime. // Else, share same codegen result for all runtimes. - let used_exports_optimization = compilation.options.is_new_tree_shaking() - && compilation.options.optimization.used_exports.is_true(); + let used_exports_optimization = compilation.options.optimization.used_exports.is_true(); let results = compilation.code_generation_modules( codegen_cache_counter, used_exports_optimization, @@ -950,16 +942,6 @@ impl Compilation { Ok(()) } - pub async fn optimize_dependency( - &mut self, - ) -> Result> { - let logger = self.get_logger("rspack.Compilation"); - let start = logger.time("optimize dependencies"); - let result = optimizer::CodeSizeOptimizer::new(self).run().await; - logger.time_end(start); - result - } - pub fn entry_modules(&self) -> IdentifierSet { self.make_artifact.entry_module_identifiers.clone() } @@ -1633,15 +1615,6 @@ impl Compilation { pub fn has_module_import_export_change(&self) -> bool { self.make_artifact.has_module_graph_change } - - // TODO remove it after remove old treeshaking - pub fn optimize_analyze_result_map(&self) -> &IdentifierMap { - &self.make_artifact.optimize_analyze_result_map - } - // TODO remove it after remove old treeshaking - pub fn optimize_analyze_result_map_mut(&mut self) -> &mut IdentifierMap { - &mut self.make_artifact.optimize_analyze_result_map - } } pub type CompilationAssets = HashMap; diff --git a/crates/rspack_core/src/compiler/make/mod.rs b/crates/rspack_core/src/compiler/make/mod.rs index 6b89df5386f..f8762d11ce2 100644 --- a/crates/rspack_core/src/compiler/make/mod.rs +++ b/crates/rspack_core/src/compiler/make/mod.rs @@ -4,16 +4,13 @@ pub mod repair; use std::path::PathBuf; -use rayon::prelude::*; use rspack_error::{Diagnostic, Result}; -use rspack_identifier::{IdentifierMap, IdentifierSet}; +use rspack_identifier::IdentifierSet; use rustc_hash::FxHashSet as HashSet; use self::{cutout::Cutout, file_counter::FileCounter, repair::repair}; use crate::{ - tree_shaking::{visitor::OptimizeAnalyzeResult, BailoutFlag}, - BuildDependency, Compilation, DependencyId, DependencyType, ModuleGraph, ModuleGraphPartial, - ModuleIdentifier, + BuildDependency, Compilation, DependencyId, ModuleGraph, ModuleGraphPartial, ModuleIdentifier, }; #[derive(Debug, Default)] @@ -27,7 +24,6 @@ pub struct MakeArtifact { pub module_graph_partial: ModuleGraphPartial, entry_dependencies: HashSet, pub entry_module_identifiers: IdentifierSet, - pub optimize_analyze_result_map: IdentifierMap, pub file_dependencies: FileCounter, pub context_dependencies: FileCounter, pub missing_dependencies: FileCounter, @@ -124,11 +120,6 @@ pub fn make_module_graph( artifact = update_module_graph_with_artifact(compilation, artifact, params)?; - if compilation.options.builtins.tree_shaking.enable() { - let module_graph = artifact.get_module_graph(); - compilation.bailout_module_identifiers = calc_bailout_module_identifiers(&module_graph); - } - compilation.push_batch_diagnostic(std::mem::take(&mut artifact.diagnostics)); Ok(artifact) } @@ -142,11 +133,6 @@ pub async fn update_module_graph( artifact = update_module_graph_with_artifact(compilation, artifact, params)?; - if compilation.options.builtins.tree_shaking.enable() { - let module_graph = artifact.get_module_graph(); - compilation.bailout_module_identifiers = calc_bailout_module_identifiers(&module_graph); - } - compilation.push_batch_diagnostic(std::mem::take(&mut artifact.diagnostics)); compilation.swap_make_artifact(&mut artifact); Ok(()) @@ -163,43 +149,3 @@ pub fn update_module_graph_with_artifact( cutout.fix_artifact(&mut artifact); Ok(artifact) } - -// TODO remove after remove old_treeshaking -fn calc_bailout_module_identifiers(module_graph: &ModuleGraph) -> IdentifierMap { - // Avoid to introduce too much overhead, - // until we find a better way to align with webpack hmr behavior - - // add context module and context element module to bailout_module_identifiers - module_graph - .dependencies() - .values() - .par_bridge() - .filter_map(|dep| { - if dep.as_context_dependency().is_some() - && let Some(module) = module_graph.get_module_by_dependency_id(dep.id()) - { - let mut values = vec![(module.identifier(), BailoutFlag::CONTEXT_MODULE)]; - if let Some(dependencies) = module_graph.get_module_all_dependencies(&module.identifier()) { - for dependency in dependencies { - if let Some(dependency_module) = - module_graph.module_identifier_by_dependency_id(dependency) - { - values.push((*dependency_module, BailoutFlag::CONTEXT_MODULE)); - } - } - } - - Some(values) - } else if matches!( - dep.dependency_type(), - DependencyType::ContainerExposed | DependencyType::ProvideModuleForShared - ) && let Some(module) = module_graph.get_module_by_dependency_id(dep.id()) - { - Some(vec![(module.identifier(), BailoutFlag::CONTAINER_EXPOSED)]) - } else { - None - } - }) - .flatten() - .collect() -} diff --git a/crates/rspack_core/src/compiler/make/repair/add.rs b/crates/rspack_core/src/compiler/make/repair/add.rs index 8ece49a7d09..aeeb9b59407 100644 --- a/crates/rspack_core/src/compiler/make/repair/add.rs +++ b/crates/rspack_core/src/compiler/make/repair/add.rs @@ -27,7 +27,6 @@ impl Task for AddTask { } let module_identifier = self.module.identifier(); - let is_new_treeshaking = context.compiler_options.is_new_tree_shaking(); let module_graph = &mut MakeTaskContext::get_module_graph_mut(&mut context.module_graph_partial); @@ -43,7 +42,6 @@ impl Task for AddTask { self.original_module_identifier, self.dependencies, *issuer, - is_new_treeshaking, )?; // reused module @@ -59,7 +57,6 @@ impl Task for AddTask { self.original_module_identifier, self.dependencies, module_identifier, - is_new_treeshaking, )?; // reused module @@ -73,7 +70,6 @@ impl Task for AddTask { self.original_module_identifier, self.dependencies, module_identifier, - is_new_treeshaking, )?; if self.is_entry { @@ -102,16 +98,9 @@ fn set_resolved_module( original_module_identifier: Option, dependencies: Vec, module_identifier: ModuleIdentifier, - // TODO: removed when new treeshaking is stable - is_new_treeshaking: bool, ) -> Result<()> { for dependency in dependencies { - module_graph.set_resolved_module( - original_module_identifier, - dependency, - module_identifier, - is_new_treeshaking, - )?; + module_graph.set_resolved_module(original_module_identifier, dependency, module_identifier)?; } Ok(()) } diff --git a/crates/rspack_core/src/compiler/make/repair/build.rs b/crates/rspack_core/src/compiler/make/repair/build.rs index 5f9e1379229..2fe7fe68888 100644 --- a/crates/rspack_core/src/compiler/make/repair/build.rs +++ b/crates/rspack_core/src/compiler/make/repair/build.rs @@ -116,11 +116,6 @@ impl Task for BuildResultTask { let module_graph = &mut MakeTaskContext::get_module_graph_mut(&mut context.module_graph_partial); - if context.compiler_options.builtins.tree_shaking.enable() { - context - .optimize_analyze_result_map - .insert(module.identifier(), build_result.analyze_result); - } if !diagnostics.is_empty() { context.make_failed_module.insert(module.identifier()); diff --git a/crates/rspack_core/src/compiler/make/repair/mod.rs b/crates/rspack_core/src/compiler/make/repair/mod.rs index 31abb45d92e..9e6aa26168f 100644 --- a/crates/rspack_core/src/compiler/make/repair/mod.rs +++ b/crates/rspack_core/src/compiler/make/repair/mod.rs @@ -6,14 +6,13 @@ pub mod process_dependencies; use std::sync::Arc; use rspack_error::{Diagnostic, Result}; -use rspack_identifier::{IdentifierMap, IdentifierSet}; +use rspack_identifier::IdentifierSet; use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; use super::{file_counter::FileCounter, MakeArtifact}; use crate::{ cache::Cache, module_graph::{ModuleGraph, ModuleGraphPartial}, - tree_shaking::visitor::OptimizeAnalyzeResult, utils::task_loop::{run_task_loop, Task}, BuildDependency, Compilation, CompilerOptions, DependencyId, DependencyType, Module, ModuleFactory, ModuleIdentifier, ModuleProfile, NormalModuleSource, ResolverFactory, @@ -43,7 +42,6 @@ pub struct MakeTaskContext { entry_dependencies: HashSet, entry_module_identifiers: IdentifierSet, diagnostics: Vec, - optimize_analyze_result_map: IdentifierMap, file_dependencies: FileCounter, context_dependencies: FileCounter, missing_dependencies: FileCounter, @@ -74,7 +72,6 @@ impl MakeTaskContext { entry_dependencies: artifact.entry_dependencies, entry_module_identifiers: artifact.entry_module_identifiers, - optimize_analyze_result_map: artifact.optimize_analyze_result_map, file_dependencies: artifact.file_dependencies, context_dependencies: artifact.context_dependencies, missing_dependencies: artifact.missing_dependencies, @@ -90,7 +87,6 @@ impl MakeTaskContext { make_failed_module, diagnostics, entry_module_identifiers, - optimize_analyze_result_map, file_dependencies, context_dependencies, missing_dependencies, @@ -106,7 +102,6 @@ impl MakeTaskContext { diagnostics, entry_dependencies, entry_module_identifiers, - optimize_analyze_result_map, file_dependencies, context_dependencies, missing_dependencies, diff --git a/crates/rspack_core/src/compiler/mod.rs b/crates/rspack_core/src/compiler/mod.rs index 80e47cd46a7..a9c99e2c156 100644 --- a/crates/rspack_core/src/compiler/mod.rs +++ b/crates/rspack_core/src/compiler/mod.rs @@ -3,8 +3,6 @@ mod hmr; mod make; mod module_executor; -use std::collections::hash_map::Entry; -use std::ops::Deref; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -12,20 +10,16 @@ use rspack_error::Result; use rspack_fs::AsyncWritableFileSystem; use rspack_futures::FuturesResults; use rspack_hook::define_hook; -use rspack_identifier::{IdentifierMap, IdentifierSet}; use rspack_sources::BoxSource; use rustc_hash::FxHashMap as HashMap; -use swc_core::ecma::atoms::Atom; use tracing::instrument; pub use self::compilation::*; pub use self::hmr::{collect_changed_modules, CompilationRecords}; pub use self::module_executor::{ExecuteModuleId, ModuleExecutor}; use crate::cache::Cache; -use crate::tree_shaking::symbol::{IndirectType, StarSymbolKind, DEFAULT_JS_WORD}; -use crate::tree_shaking::visitor::SymbolRef; +use crate::BoxPlugin; use crate::{fast_set, CompilerOptions, Logger, PluginDriver, ResolverFactory, SharedPluginDriver}; -use crate::{BoxPlugin, ExportInfo, UsageState}; use crate::{ContextModuleFactory, NormalModuleFactory}; // should be SyncHook, but rspack need call js hook @@ -86,7 +80,6 @@ where let loader_resolver_factory = Arc::new(ResolverFactory::new(options.resolve_loader.clone())); let (plugin_driver, options) = PluginDriver::new(options, plugins, resolver_factory.clone()); let cache = Arc::new(Cache::new(options.clone())); - assert!(!(options.is_new_tree_shaking() && options.builtins.tree_shaking.enable()), "Can't enable builtins.tree_shaking and `experiments.rspack_future.new_treeshaking` at the same time"); let module_executor = ModuleExecutor::default(); Self { options: options.clone(), @@ -166,7 +159,6 @@ where .await?; let logger = self.compilation.get_logger("rspack.Compiler"); - let option = self.options.clone(); let make_start = logger.time("make"); let make_hook_start = logger.time("make hook"); if let Some(e) = self @@ -195,97 +187,6 @@ where let start = logger.time("finish compilation"); self.compilation.finish(self.plugin_driver.clone()).await?; logger.time_end(start); - // by default include all module in final chunk - self.compilation.include_module_ids = self - .compilation - .get_module_graph() - .modules() - .keys() - .cloned() - .collect::(); - - if option.builtins.tree_shaking.enable() - || option - .output - .enabled_library_types - .as_ref() - .map(|types| { - types - .iter() - .any(|item| item == "module" || item == "commonjs-static") - }) - .unwrap_or(false) - { - let (mut analyze_result, diagnostics) = self - .compilation - .optimize_dependency() - .await? - .split_into_parts(); - if !diagnostics.is_empty() { - self.compilation.push_batch_diagnostic(diagnostics); - } - self.compilation.used_symbol_ref = analyze_result.used_symbol_ref; - let mut exports_info_map: IdentifierMap> = IdentifierMap::default(); - self.compilation.used_symbol_ref.iter().for_each(|item| { - let (importer, name) = match item { - SymbolRef::Declaration(d) => (d.src(), d.exported()), - SymbolRef::Indirect(i) => match i.ty { - IndirectType::Import(_, _) => (i.src(), i.indirect_id()), - IndirectType::ImportDefault(_) => (i.src(), DEFAULT_JS_WORD.deref()), - IndirectType::ReExport(_, _) => (i.importer(), i.id()), - _ => return, - }, - SymbolRef::Star(s) => match s.ty() { - StarSymbolKind::ReExportAllAs => (s.module_ident(), s.binding()), - _ => return, - }, - SymbolRef::Usage(_, _, _) => return, - SymbolRef::Url { .. } => return, - SymbolRef::Worker { .. } => return, - }; - match exports_info_map.entry(importer) { - Entry::Occupied(mut occ) => { - let export_info = ExportInfo::new(Some(name.clone()), UsageState::Used, None); - occ.get_mut().insert(name.clone(), export_info); - } - Entry::Vacant(vac) => { - let mut map = HashMap::default(); - let export_info = ExportInfo::new(Some(name.clone()), UsageState::Used, None); - map.insert(name.clone(), export_info); - vac.insert(map); - } - } - }); - { - let mut module_graph = self.compilation.get_module_graph_mut(); - for (module_identifier, exports_map) in exports_info_map.into_iter() { - let exports_id = module_graph - .module_graph_module_by_identifier(&module_identifier) - .map(|mgm| mgm.exports); - if let Some(exports_id) = &exports_id { - for (name, export_info) in exports_map { - let exports = module_graph.get_exports_info_mut_by_id(exports_id); - let export_id = export_info.id; - exports.exports.insert(name, export_id); - module_graph.set_export_info(export_id, export_info); - } - } - } - } - - self.compilation.bailout_module_identifiers = analyze_result.bail_out_module_identifiers; - self.compilation.side_effects_free_modules = analyze_result.side_effects_free_modules; - self.compilation.module_item_map = analyze_result.module_item_map; - if self.options.builtins.tree_shaking.enable() - && self.options.optimization.side_effects.is_enable() - { - self.compilation.include_module_ids = analyze_result.include_module_ids; - } - std::mem::swap( - self.compilation.optimize_analyze_result_map_mut(), - &mut analyze_result.analyze_results, - ); - } let start = logger.time("seal compilation"); self.compilation.seal(self.plugin_driver.clone()).await?; logger.time_end(start); diff --git a/crates/rspack_core/src/dependency/runtime_template.rs b/crates/rspack_core/src/dependency/runtime_template.rs index 5c4ceab212c..1df8583a3a2 100644 --- a/crates/rspack_core/src/dependency/runtime_template.rs +++ b/crates/rspack_core/src/dependency/runtime_template.rs @@ -119,7 +119,6 @@ pub fn export_from_import( else { return missing_module(request); }; - let is_new_treeshaking = compilation.options.is_new_tree_shaking(); let exports_type = get_exports_type(&compilation.get_module_graph(), id, &module.identifier()); @@ -178,7 +177,7 @@ pub fn export_from_import( } if !export_name.is_empty() { - let used_name = if is_new_treeshaking { + let used_name: Cow> = { let exports_info_id = compilation .get_module_graph() .get_exports_info(&module_identifier) @@ -200,8 +199,6 @@ pub fn export_from_import( to_normal_comment(&property_access(&export_name, 0)) ); } - } else { - Cow::Borrowed(&export_name) }; let comment = if *used_name != export_name { to_normal_comment(&property_access(&export_name, 0)) diff --git a/crates/rspack_core/src/module.rs b/crates/rspack_core/src/module.rs index 23ad9e33c7a..85ff0cd0341 100644 --- a/crates/rspack_core/src/module.rs +++ b/crates/rspack_core/src/module.rs @@ -161,8 +161,6 @@ pub struct BuildResult { #[derive(Debug, Default, Clone)] pub struct FactoryMeta { pub side_effect_free: Option, - /// For old tree shaking - pub side_effect_free_old: Option, } pub type ModuleIdentifier = Identifier; diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index a83c5b26c72..b874d387d03 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -782,21 +782,15 @@ impl<'a> ModuleGraph<'a> { original_module_identifier: Option, dependency_id: DependencyId, module_identifier: ModuleIdentifier, - // TODO: removed when new treeshaking is stable - is_new_treeshaking: bool, ) -> Result<()> { let dependency = self .dependency_by_id(&dependency_id) .expect("should have dependency"); let is_module_dependency = dependency.as_module_dependency().is_some() || dependency.as_context_dependency().is_some(); - let condition = if is_new_treeshaking { - dependency - .as_module_dependency() - .and_then(|dep| dep.get_condition()) - } else { - None - }; + let condition = dependency + .as_module_dependency() + .and_then(|dep| dep.get_condition()); let Some(active_partial) = &mut self.active else { panic!("should have active partial"); }; @@ -929,24 +923,6 @@ impl<'a> ModuleGraph<'a> { }) } - /// # Deprecated!!! - /// # Don't use this anymore!!! - /// A module is a DependenciesBlock, which means it has some Dependencies and some AsyncDependenciesBlocks - /// a static import is a Dependency, but a dynamic import is a AsyncDependenciesBlock - /// AsyncDependenciesBlock means it is a code-splitting point, and will create a ChunkGroup in code-splitting - /// and AsyncDependenciesBlock also is DependenciesBlock, so it can has some Dependencies and some AsyncDependenciesBlocks - /// so if you want get a module's dependencies and its blocks' dependencies (all dependencies) - /// just use module.get_dependencies() and module.get_blocks().map(|b| b.get_dependencyes()) - /// you don't need this one - pub(crate) fn get_module_all_dependencies( - &self, - module_identifier: &ModuleIdentifier, - ) -> Option<&[DependencyId]> { - self - .module_graph_module_by_identifier(module_identifier) - .map(|m| &*m.__deprecated_all_dependencies) - } - pub fn parent_module_by_dependency_id( &self, dependency_id: &DependencyId, diff --git a/crates/rspack_core/src/normal_module_factory.rs b/crates/rspack_core/src/normal_module_factory.rs index 2f0642d364d..ca8dceb3e44 100644 --- a/crates/rspack_core/src/normal_module_factory.rs +++ b/crates/rspack_core/src/normal_module_factory.rs @@ -10,15 +10,13 @@ use sugar_path::SugarPath; use swc_core::common::Span; use crate::{ - diagnostics::EmptyDependency, - module_rules_matcher, parse_resource, resolve, stringify_loaders_and_resource, - tree_shaking::visitor::{get_side_effects_from_package_json, SideEffects}, - BoxLoader, BoxModule, CompilerContext, CompilerOptions, Context, DependencyCategory, FactoryMeta, - FuncUseCtx, GeneratorOptions, ModuleExt, ModuleFactory, ModuleFactoryCreateData, - ModuleFactoryResult, ModuleIdentifier, ModuleRule, ModuleRuleEnforce, ModuleRuleUse, - ModuleRuleUseLoader, ModuleType, NormalModule, ParserOptions, RawModule, Resolve, ResolveArgs, - ResolveOptionsWithDependencyType, ResolveResult, Resolver, ResolverFactory, ResourceData, - ResourceParsedData, SharedPluginDriver, + diagnostics::EmptyDependency, module_rules_matcher, parse_resource, resolve, + stringify_loaders_and_resource, BoxLoader, BoxModule, CompilerContext, CompilerOptions, Context, + DependencyCategory, FuncUseCtx, GeneratorOptions, ModuleExt, ModuleFactory, + ModuleFactoryCreateData, ModuleFactoryResult, ModuleIdentifier, ModuleRule, ModuleRuleEnforce, + ModuleRuleUse, ModuleRuleUseLoader, ModuleType, NormalModule, ParserOptions, RawModule, Resolve, + ResolveArgs, ResolveOptionsWithDependencyType, ResolveResult, Resolver, ResolverFactory, + ResourceData, ResourceParsedData, SharedPluginDriver, }; define_hook!(NormalModuleFactoryBeforeResolve: AsyncSeriesBail(data: &mut ModuleFactoryCreateData) -> bool); @@ -499,9 +497,6 @@ impl NormalModuleFactory { resolved_generator_options.as_ref(), ); - let resource_path = resource_data.resource_path.clone(); - let resource_description = resource_data.resource_description.clone(); - let mut create_data = { let mut create_data = NormalModuleCreateData { raw_request, @@ -565,28 +560,6 @@ impl NormalModuleFactory { data.add_file_dependency(file_dependency); data.add_missing_dependencies(missing_dependencies); - // Compat for old tree shaking - if !self.options.is_new_tree_shaking() { - if resolved_side_effects.is_some() { - module.set_factory_meta(FactoryMeta { - side_effect_free: None, - side_effect_free_old: resolved_side_effects.map(|has_side_effects| !has_side_effects), - }) - } else if let Some(description) = resource_description.as_ref() - && let Some(side_effects) = SideEffects::from_description(description.json()) - { - let package_path = description.path(); - let relative_path = resource_path.relative(package_path); - module.set_factory_meta(FactoryMeta { - side_effect_free: None, - side_effect_free_old: Some(!get_side_effects_from_package_json( - side_effects, - relative_path, - )), - }) - } - } - Ok(Some(ModuleFactoryResult::new_with_module(module))) } diff --git a/crates/rspack_core/src/options/builtins.rs b/crates/rspack_core/src/options/builtins.rs index 1cc9e77c397..50eb365b8ce 100644 --- a/crates/rspack_core/src/options/builtins.rs +++ b/crates/rspack_core/src/options/builtins.rs @@ -65,63 +65,12 @@ pub struct DecoratorOptions { pub emit_metadata: bool, } -#[derive(Debug, Clone, Default, Copy)] -pub enum TreeShaking { - True, - #[default] - False, - Module, -} - -impl TreeShaking { - pub fn enable(&self) -> bool { - matches!(self, TreeShaking::Module | TreeShaking::True) - } - - /// Returns `true` if the tree shaking is [`True`]. - /// - /// [`True`]: TreeShaking::True - #[must_use] - pub fn is_true(&self) -> bool { - matches!(self, Self::True) - } - - /// Returns `true` if the tree shaking is [`False`]. - /// - /// [`False`]: TreeShaking::False - #[must_use] - pub fn is_false(&self) -> bool { - matches!(self, Self::False) - } - - /// Returns `true` if the tree shaking is [`Module`]. - /// - /// [`Module`]: TreeShaking::Module - #[must_use] - pub fn is_module(&self) -> bool { - matches!(self, Self::Module) - } -} - -impl From for TreeShaking { - fn from(value: String) -> Self { - match value.as_ref() { - "true" => TreeShaking::True, - "false" => TreeShaking::False, - "module" => TreeShaking::Module, - _ => panic!("Unknown tree shaking option, please use one of `true`, `false` and `module`"), - } - } -} - #[derive(Debug, Clone, Default)] pub struct Builtins { // TODO: refactor to string-replacement based pub define: Define, // TODO: refactor to string-replacement based pub provide: Provide, - // TODO: refactoring - pub tree_shaking: TreeShaking, } #[derive(Debug, Clone, Default)] diff --git a/crates/rspack_core/src/options/compiler_options.rs b/crates/rspack_core/src/options/compiler_options.rs index dc5ae725429..12664f5a0a1 100644 --- a/crates/rspack_core/src/options/compiler_options.rs +++ b/crates/rspack_core/src/options/compiler_options.rs @@ -38,8 +38,4 @@ impl CompilerOptions { pub fn is_incremental_rebuild_emit_asset_enabled(&self) -> bool { self.experiments.incremental_rebuild.emit_asset } - - pub fn is_new_tree_shaking(&self) -> bool { - self.experiments.rspack_future.new_treeshaking - } } diff --git a/crates/rspack_core/src/options/experiments.rs b/crates/rspack_core/src/options/experiments.rs index 57fffa39fb4..2648e89442b 100644 --- a/crates/rspack_core/src/options/experiments.rs +++ b/crates/rspack_core/src/options/experiments.rs @@ -21,10 +21,9 @@ impl IncrementalRebuildMakeState { } } +#[allow(clippy::empty_structs_with_brackets)] #[derive(Debug, Default)] -pub struct RspackFuture { - pub new_treeshaking: bool, -} +pub struct RspackFuture {} #[derive(Debug, Default)] pub struct Experiments { diff --git a/crates/rspack_core/src/tree_shaking/mod.rs b/crates/rspack_core/src/tree_shaking/mod.rs index f0978325287..f42aa8b1bf8 100644 --- a/crates/rspack_core/src/tree_shaking/mod.rs +++ b/crates/rspack_core/src/tree_shaking/mod.rs @@ -10,7 +10,6 @@ pub mod analyzer; pub mod asset_module; pub mod debug_helper; pub mod js_module; -pub mod optimizer; pub mod symbol; pub mod symbol_graph; pub mod utils; diff --git a/crates/rspack_core/src/tree_shaking/optimizer.rs b/crates/rspack_core/src/tree_shaking/optimizer.rs deleted file mode 100644 index 880f454044f..00000000000 --- a/crates/rspack_core/src/tree_shaking/optimizer.rs +++ /dev/null @@ -1,2280 +0,0 @@ -use std::{ - borrow::BorrowMut, - collections::{hash_map::Entry, VecDeque}, -}; - -use petgraph::{ - algo, - prelude::{DiGraphMap, GraphMap}, - stable_graph::NodeIndex, - visit::{Bfs, Dfs, EdgeRef}, - Directed, -}; -use rspack_error::{ - errors_to_diagnostics, Error, InternalError, IntoTWithDiagnosticArray, Result, Severity, - TWithDiagnosticArray, -}; -use rspack_identifier::{Identifier, IdentifierLinkedSet, IdentifierMap, IdentifierSet}; -use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; -use swc_core::{common::SyntaxContext, ecma::atoms::Atom}; - -use super::{ - symbol::{ - BetterId, IndirectTopLevelSymbol, IndirectType, SerdeSymbol, StarSymbol, StarSymbolKind, - Symbol, SymbolType, - }, - visitor::ModuleIdOrDepId, -}; -use super::{ - symbol_graph::SymbolGraph, - visitor::{OptimizeAnalyzeResult, SymbolRef}, - BailoutFlag, ModuleUsedType, OptimizeDependencyResult, SideEffectType, -}; -use crate::{ - contextify, join_string_component, - tree_shaking::{utils::ConvertModulePath, visitor::ModuleRefAnalyze}, - Compilation, DependencyId, DependencyType, ModuleGraph, ModuleIdentifier, ModuleType, - NormalModuleSource, -}; - -pub struct CodeSizeOptimizer<'a> { - compilation: &'a mut Compilation, - bailout_modules: IdentifierMap, - side_effects_free_modules: IdentifierSet, - symbol_graph: SymbolGraph, -} - -enum ReExportConnectionStatus { - Vacant(Vec>), - Occupied(Vec), -} - -enum EntryLikeType { - Entry, - Bailout, -} - -#[derive(Debug)] -struct ModuleEliminator { - export_used: bool, - is_bailout: bool, - side_effects_free: bool, - is_entry: bool, - /// used for debugging - #[allow(unused)] - module_identifier: ModuleIdentifier, -} - -type SymbolRefWithMemberChain = (SymbolRef, Vec); - -impl ModuleEliminator { - fn could_be_skipped(&self) -> bool { - !self.export_used && !self.is_bailout && self.side_effects_free && !self.is_entry - } -} - -impl<'a> CodeSizeOptimizer<'a> { - pub fn new(compilation: &'a mut Compilation) -> Self { - Self { - bailout_modules: compilation.bailout_module_identifiers.clone(), - symbol_graph: SymbolGraph::default(), - side_effects_free_modules: IdentifierSet::default(), - compilation, - } - } - - pub async fn run(&mut self) -> Result> { - // let is_incremental_rebuild = self - // .compilation - // .options - // .is_incremental_rebuild_make_enabled(); - // let mut analyze_result_map = par_analyze_module(self.compilation).await; - // let mut finalized_result_map = if is_incremental_rebuild { - // if is_first_time_analyze { - // analyze_result_map - // } else { - // for (ident, result) in analyze_result_map.into_iter() { - // self - // .compilation - // .optimize_analyze_result_map - // .insert(ident, result); - // } - // // Merge new analyze result with previous in incremental_rebuild mode - // std::mem::take(&mut self.compilation.optimize_analyze_result_map) - // } - // } else { - // analyze_result_map - // }; - let mut optimize_analyze_result_map = - std::mem::take(self.compilation.optimize_analyze_result_map_mut()); - let module_graph = self.compilation.get_module_graph(); - optimize_analyze_result_map.iter_mut().for_each( - |(module_identifier, optimize_analyze_result)| { - if let Some(factory_meta_side_effects) = module_graph - .module_by_identifier(module_identifier) - .and_then(|m| ModuleRefAnalyze::get_side_effects_from_config(m.factory_meta())) - { - optimize_analyze_result.side_effects = factory_meta_side_effects; - } - }, - ); - std::mem::swap( - &mut optimize_analyze_result_map, - self.compilation.optimize_analyze_result_map_mut(), - ); - // We will set it back and return the analyze result, take is safe here. - let mut finalized_result_map = - std::mem::take(self.compilation.optimize_analyze_result_map_mut()); - let mut evaluated_used_symbol_ref: HashSet = HashSet::default(); - let mut evaluated_module_identifiers = IdentifierSet::default(); - let side_effects_options = self - .compilation - .options - .optimization - .side_effects - .is_enable(); - let mut side_effect_map: IdentifierMap = IdentifierMap::default(); - for analyze_result in finalized_result_map.values() { - side_effect_map.insert( - analyze_result.module_identifier, - analyze_result.side_effects, - ); - // if `side_effects` is disabled, then force every module has side_effects - let forced_side_effects = !side_effects_options - || self - .compilation - .entry_modules() - .contains(&analyze_result.module_identifier); - // side_effects: true - if forced_side_effects - || !matches!( - analyze_result.side_effects, - SideEffectType::Configuration(false) - ) - { - evaluated_module_identifiers.insert(analyze_result.module_identifier); - evaluated_used_symbol_ref.extend(analyze_result.used_symbol_refs.iter().cloned()); - } - // merge bailout module identifier - for (module_identifier, &reason) in analyze_result.bail_out_module_identifiers.iter() { - self.merge_bailout_modules_reason(module_identifier, reason); - } - } - tracing::debug!(side_effect_map = format!("{:#?}", side_effect_map)); - - self.side_effects_free_modules = self.get_side_effects_free_modules(side_effect_map); - - let inherit_export_ref_graph = get_inherit_export_ref_graph( - &mut finalized_result_map, - &self.compilation.get_module_graph(), - ); - let mut errors = vec![]; - let mut used_symbol_ref = HashSet::default(); - let mut used_export_module_identifiers: IdentifierMap = - IdentifierMap::default(); - let mut traced_tuple = HashMap::default(); - // Marking used symbol and all reachable export symbol from the used symbol for each module - - let mut visited_symbol_ref: HashSet = HashSet::default(); - - self.mark_used_symbol_with( - &finalized_result_map, - VecDeque::from_iter( - evaluated_used_symbol_ref - .into_iter() - .map(|item| (item, vec![])), - ), - &mut evaluated_module_identifiers, - &mut used_export_module_identifiers, - &inherit_export_ref_graph, - &mut traced_tuple, - &mut visited_symbol_ref, - &mut errors, - ); - - // We considering all export symbol in each entry module as used for now - self.mark_entry_symbol( - &finalized_result_map, - &mut evaluated_module_identifiers, - &mut used_export_module_identifiers, - &inherit_export_ref_graph, - &mut traced_tuple, - &mut visited_symbol_ref, - &mut errors, - ); - - // All lazy imported module will be treadted as entry module, which means - // Its export symbol will be marked as used - // let mut bailout_entry_module_identifiers = IdentifierSet::default(); - self.mark_bailout_module( - &finalized_result_map, - evaluated_module_identifiers, - &mut used_export_module_identifiers, - inherit_export_ref_graph, - traced_tuple, - &mut visited_symbol_ref, - &mut errors, - ); - // let debug_graph = generate_debug_symbol_graph( - // &self.symbol_graph, - // &self.compilation.get_module_graph(), - // &self.compilation.options.context.as_str().to_owned(), - // ); - // let res = serde_json::to_string(&debug_graph).unwrap(); - // println!("{}", res); - self.check_symbol_query(); - - let dead_nodes_index = HashSet::default(); - // dependency_replacement(); - let include_module_ids = self.finalize_symbol( - side_effects_options, - used_export_module_identifiers, - &mut used_symbol_ref, - &dead_nodes_index, - ); - Ok( - OptimizeDependencyResult { - used_symbol_ref, - analyze_results: finalized_result_map, - bail_out_module_identifiers: std::mem::take(&mut self.bailout_modules), - side_effects_free_modules: std::mem::take(&mut self.side_effects_free_modules), - module_item_map: IdentifierMap::default(), - include_module_ids, - } - .with_diagnostic(errors_to_diagnostics(errors)), - ) - } - - fn merge_bailout_modules_reason(&mut self, k: &ModuleIdOrDepId, v: BailoutFlag) { - let mg = &self.compilation.get_module_graph(); - let normalized_module_id = match k { - ModuleIdOrDepId::ModuleId(module_id) => *module_id, - ModuleIdOrDepId::DepId(dep_id) => { - if let Some(module_id) = mg.module_identifier_by_dependency_id(dep_id) { - *module_id - } else { - return; - } - } - }; - match self.bailout_modules.entry(normalized_module_id) { - Entry::Occupied(mut occ) => { - *occ.get_mut() |= v; - } - Entry::Vacant(vac) => { - vac.insert(v); - } - } - } - - fn check_symbol_query(&self) { - let symbol_list = match &std::env::var("SYMBOL_QUERY_PATH") { - Ok(relative_path) => { - let log = std::env::current_dir().expect("Can't get cwd"); - let ab_path = log.join(relative_path); - let file = - std::fs::read_to_string(ab_path).expect("Failed to read target file into string"); - serde_json::from_str::>(&file) - .expect("Can't convert to symbol from sourcefile") - } - Err(_) => { - vec![] - } - }; - - let get_node_index_from_serde_symbol = |serde_symbol: &SerdeSymbol| { - for symbol_ref in self.symbol_graph.symbol_refs() { - match symbol_ref { - SymbolRef::Declaration(direct) => { - if direct.id().atom != serde_symbol.id || !direct.src().contains(&serde_symbol.uri) { - continue; - } - } - SymbolRef::Indirect(_) | SymbolRef::Star(_) => { - continue; - } - SymbolRef::Url { .. } | SymbolRef::Worker { .. } => continue, - SymbolRef::Usage(_, _, _) => continue, - } - let index = self - .symbol_graph - .get_node_index(symbol_ref) - .unwrap_or_else(|| panic!("Can't find NodeIndex for symbol {symbol_ref:?}",)); - return Some(*index); - } - None - }; - - let symbol_graph = self.symbol_graph.clone().reverse_graph(); - - for symbol in symbol_list { - // get_symbol_path() - match get_node_index_from_serde_symbol(&symbol) { - Some(node_index) => { - let paths = get_symbol_path(&symbol_graph, node_index); - println!("Reason of Included Symbol symbol{symbol:?}",); - for p in paths { - let normalized_symbols = p - .into_iter() - .map(|symbol| { - symbol - .convert_module_identifier_to_module_path(&self.compilation.get_module_graph()) - }) - .collect::>(); - println!("{normalized_symbols:#?}",); - } - } - None => { - eprintln!("Can't find symbol {symbol:?} in symbolGraph",); - } - } - } - } - - #[allow(clippy::too_many_arguments)] - fn mark_bailout_module( - &mut self, - analyze_result_map: &IdentifierMap, - mut evaluated_module_identifiers: IdentifierSet, - used_export_module_identifiers: &mut IdentifierMap, - inherit_export_ref_graph: GraphMap, - mut traced_tuple: HashMap<(Identifier, Identifier), Vec>, - visited_symbol_ref: &mut HashSet, - errors: &mut Vec, - ) { - let bailout_entry_modules = self.bailout_modules.keys().copied().collect::>(); - for module_id in bailout_entry_modules { - self.collect_from_entry_like( - analyze_result_map, - module_id, - &mut evaluated_module_identifiers, - used_export_module_identifiers, - &inherit_export_ref_graph, - &mut traced_tuple, - EntryLikeType::Bailout, - visited_symbol_ref, - errors, - ); - } - } - - #[allow(clippy::too_many_arguments)] - fn mark_entry_symbol( - &mut self, - analyze_result_map: &IdentifierMap, - evaluated_module_identifiers: &mut IdentifierSet, - used_export_module_identifiers: &mut IdentifierMap, - inherit_export_ref_graph: &GraphMap, - traced_tuple: &mut HashMap<(Identifier, Identifier), Vec>, - visited_symbol_ref: &mut HashSet, - errors: &mut Vec, - ) { - for entry in self.compilation.entry_modules() { - self.collect_from_entry_like( - analyze_result_map, - entry, - evaluated_module_identifiers, - used_export_module_identifiers, - inherit_export_ref_graph, - traced_tuple, - EntryLikeType::Entry, - visited_symbol_ref, - errors, - ); - } - } - - fn finalize_symbol( - &mut self, - side_effects_analyze: bool, - used_export_module_identifiers: IdentifierMap, - used_symbol_ref: &mut HashSet, - dead_node_index: &HashSet, - ) -> IdentifierSet { - let symbol_graph = &self.symbol_graph; - let visited_symbol_ref = symbol_graph - .symbol_to_index - .keys() - .cloned() - .collect::>(); - let mut include_module_ids = IdentifierSet::default(); - - if side_effects_analyze { - let mut module_visited_symbol_ref: IdentifierMap> = IdentifierMap::default(); - for symbol in visited_symbol_ref { - let module_identifier = symbol.importer(); - match module_visited_symbol_ref.entry(module_identifier) { - Entry::Occupied(mut occ) => { - occ.get_mut().push(symbol); - } - Entry::Vacant(vac) => { - vac.insert(vec![symbol]); - } - } - } - // pruning - let mut visited_symbol_node_index: HashSet = HashSet::default(); - let mut visited = IdentifierSet::default(); - let mut q = VecDeque::from_iter( - self.compilation.entry_modules(), // - ); - while let Some(module_identifier) = q.pop_front() { - if visited.contains(&module_identifier) { - continue; - } else { - visited.insert(module_identifier); - } - let eliminator = ModuleEliminator { - export_used: used_export_module_identifiers.contains_key(&module_identifier), - is_bailout: self.bailout_modules.contains_key(&module_identifier), - side_effects_free: self.side_effects_free_modules.contains(&module_identifier), - is_entry: self - .compilation - .entry_modules() - .contains(&module_identifier), - module_identifier, - }; - - if eliminator.could_be_skipped() { - continue; - } - - let mut reachable_dependency_identifier = IdentifierSet::default(); - - // let mgm = self - // .compilation - // .get_module_graph() - // .module_graph_module_by_identifier(&module_identifier) - // .unwrap_or_else(|| panic!("Failed to get mgm by module identifier {module_identifier}")); - include_module_ids.insert(module_identifier); - if let Some(symbol_ref_list) = module_visited_symbol_ref.get(&module_identifier) { - for symbol_ref in symbol_ref_list { - update_reachable_dependency( - symbol_ref, - &mut reachable_dependency_identifier, - symbol_graph, - ); - let node_index = symbol_graph - .get_node_index(symbol_ref) - .expect("Can't get NodeIndex of SymbolRef"); - if !visited_symbol_node_index.contains(node_index) { - let mut bfs = Bfs::new(&symbol_graph.graph, *node_index); - while let Some(node_index) = bfs.next(&symbol_graph.graph) { - update_reachable_symbol(dead_node_index, node_index, &mut visited_symbol_node_index) - } - } - } - } - - // reachable_dependency_identifier.extend(analyze_result.inherit_export_maps.keys()); - let module_graph = self.compilation.get_module_graph(); - for dependency_id in module_graph - .get_module_all_dependencies(&module_identifier) - .unwrap_or_else(|| { - panic!("Failed to get ModuleGraphModule by module identifier {module_identifier}") - }) - .iter() - { - let dep = module_graph - .dependency_by_id(dependency_id) - .expect("should have dependency"); - - if dep.as_module_dependency().is_none() && dep.as_context_dependency().is_none() { - continue; - } - let module_id_by_dep_id = - match module_graph.module_identifier_by_dependency_id(dependency_id) { - Some(module_identifier) => module_identifier, - None => { - let module = module_graph.module_by_identifier(&module_identifier); - - if module - .and_then(|module| module.as_context_module()) - .is_some() - { - // If the referenced module of context dependency is not found, then it might be failed to factorize in the first place. So let's skip it. - continue; - } - match module - .and_then(|module| module.as_normal_module()) - .map(|normal_module| normal_module.source()) - { - Some(NormalModuleSource::Unbuild) => { - panic!("Failed to build module {module_identifier}"); - } - Some(_) => { - // If module is failed to build, we know that the build output can't run, so it is alright to generate a wrong tree-shaking result. - // Also, if the referenced module of the dependency is not found, then it might failed to factorize in the first place. So let's skip it. - continue; - } - None => { - panic!("Failed to get normal module of {module_identifier}"); - } - }; - } - }; - let dependency = match module_graph.dependency_by_id(dependency_id) { - Some(dep) => dep, - None => { - // It means this dependency has been removed before - continue; - } - }; - let need_bailout = matches!( - dependency.dependency_type(), - DependencyType::CommonJSRequireContext - | DependencyType::RequireContext - | DependencyType::DynamicImport - | DependencyType::CjsRequire - | DependencyType::CjsExportRequire - | DependencyType::ImportContext - | DependencyType::ContainerExposed - | DependencyType::ProvideModuleForShared - ); - - if self.side_effects_free_modules.contains(module_id_by_dep_id) - && !reachable_dependency_identifier.contains(module_id_by_dep_id) - && !need_bailout - { - continue; - } - - // we need to push either dependencies of context module instead of only its self, context module doesn't have ast, - // which imply it will be treated as a external module in analyze phase - if matches!( - dependency.dependency_type(), - DependencyType::CommonJSRequireContext - | DependencyType::RequireContext - | DependencyType::ImportContext - ) { - let deps_module_id_of_context_module = self - .compilation - .get_module_graph() - .get_module_all_dependencies(module_id_by_dep_id) - .map(|deps| { - deps - .iter() - .filter_map(|dep| { - self - .compilation - .get_module_graph() - .module_identifier_by_dependency_id(dep) - .cloned() - }) - .collect::>() - }) - .unwrap_or_default(); - q.extend(deps_module_id_of_context_module); - } - q.push_back(*module_id_by_dep_id); - } - } - - for node_index in visited_symbol_node_index { - used_symbol_ref.insert( - self - .symbol_graph - .get_symbol(&node_index) - .expect("Can't get SymbolRef of NodeIndex") - .clone(), - ); - } - } else { - *used_symbol_ref = visited_symbol_ref; - } - include_module_ids - } - - fn get_side_effects_free_modules( - &self, - mut side_effect_map: IdentifierMap, - ) -> IdentifierSet { - // normalize side_effects, there are two kinds of `side_effects` one from configuration and another from analyze ast - for entry_module_ident in self.compilation.entry_modules() { - Self::normalize_side_effects( - entry_module_ident, - &self.compilation.get_module_graph(), - &mut IdentifierSet::default(), - &mut side_effect_map, - ); - } - - let side_effects_free_modules = side_effect_map - .iter() - .filter_map(|(k, v)| { - let side_effect = match v { - SideEffectType::Configuration(value) => value, - SideEffectType::Analyze(value) => value, - }; - if !side_effect { - Some(*k) - } else { - None - } - }) - .collect::(); - side_effects_free_modules - } - - fn normalize_side_effects( - cur: Identifier, - module_graph: &ModuleGraph, - visited_module: &mut IdentifierSet, - side_effects_map: &mut IdentifierMap, - ) { - if visited_module.contains(&cur) { - return; - } - visited_module.insert(cur); - let mut module_ident_list = vec![]; - for dep in module_graph - .get_module_all_dependencies(&cur) - .unwrap_or_else(|| panic!("Failed to get mgm by module identifier {cur}")) - .iter() - { - let dependency = module_graph - .dependency_by_id(dep) - .expect("should have dependency"); - if dependency.as_module_dependency().is_none() && dependency.as_context_dependency().is_none() - { - continue; - } - let Some(&module_ident) = module_graph.module_identifier_by_dependency_id(dep) else { - let module = module_graph.module_by_identifier(&cur); - - if module - .and_then(|module| module.as_context_module()) - .is_some() - { - // If the referenced module of context dependency is not found, then it might be failed to factorize in the first place. So let's skip it. - continue; - } - let ast_or_source = module - .and_then(|module| module.as_normal_module()) - .map(|normal_module| normal_module.source()) - .unwrap_or_else(|| panic!("Failed to get normal module of {}", cur)); - - if matches!(ast_or_source, NormalModuleSource::Unbuild) { - panic!("Failed to build module {cur}"); - } else { - // If module is failed to build, we know that the build output can't run, so it is alright to generate a wrong tree-shaking result. - // Also, if the referenced module of the dependency is not found, then it might failed to factorize in the first place. So let's skip it. - continue; - } - }; - module_ident_list.push(module_ident); - Self::normalize_side_effects(module_ident, module_graph, visited_module, side_effects_map); - } - // visited_module.remove(&cur); - - let need_change_to_side_effects_true = match side_effects_map.get(&cur) { - // skip no deps or user already specified side effect in package.json - Some(SideEffectType::Configuration(_)) | None => false, - // already marked as side-effectful - Some(SideEffectType::Analyze(true)) => false, - Some(SideEffectType::Analyze(false)) => { - let mut side_effect_list = module_ident_list.into_iter().filter(|ident| { - matches!( - side_effects_map.get(ident), - Some(SideEffectType::Analyze(true)) | Some(SideEffectType::Configuration(true)) - ) - }); - side_effect_list.next().is_some() - // uncomment below for debugging side_effect_list - // let side_effect_list = side_effect_list.collect::>(); - // side_effect_list.is_empty() - } - }; - - if need_change_to_side_effects_true { - if let Some(cur) = side_effects_map.get_mut(&cur) { - *cur = SideEffectType::Analyze(true); - } - } - } - - #[allow(clippy::too_many_arguments)] - fn mark_used_symbol_with( - &mut self, - analyze_map: &IdentifierMap, - mut init_queue: VecDeque, - evaluated_module_identifiers: &mut IdentifierSet, - used_export_module_identifiers: &mut IdentifierMap, - inherit_extend_graph: &GraphMap, - traced_tuple: &mut HashMap<(ModuleIdentifier, ModuleIdentifier), Vec>, - visited_symbol_ref: &mut HashSet, - errors: &mut Vec, - ) { - while let Some(sym_ref) = init_queue.pop_front() { - self.mark_symbol( - sym_ref, - analyze_map, - &mut init_queue, - evaluated_module_identifiers, - used_export_module_identifiers, - inherit_extend_graph, - traced_tuple, - visited_symbol_ref, - errors, - ); - } - } - - #[allow(clippy::too_many_arguments)] - fn mark_symbol( - &mut self, - mut current_symbol_ref_with_member_chain: SymbolRefWithMemberChain, - analyze_map: &IdentifierMap, - symbol_queue: &mut VecDeque, - evaluated_module_identifiers: &mut IdentifierSet, - used_export_module_identifiers: &mut IdentifierMap, - inherit_extend_graph: &GraphMap, - traced_tuple: &mut HashMap<(ModuleIdentifier, ModuleIdentifier), Vec>, - visited_symbol_ref: &mut HashSet, - errors: &mut Vec, - ) { - current_symbol_ref_with_member_chain.0 = current_symbol_ref_with_member_chain - .0 - .update_src_from_dep_id(&self.compilation.get_module_graph()); - if visited_symbol_ref.contains(¤t_symbol_ref_with_member_chain) { - return; - } else { - visited_symbol_ref.insert(current_symbol_ref_with_member_chain.clone()); - } - let (current_symbol_ref, member_chain) = current_symbol_ref_with_member_chain; - - if !evaluated_module_identifiers.contains(¤t_symbol_ref.importer()) { - evaluated_module_identifiers.insert(current_symbol_ref.importer()); - if let Some(module_result) = analyze_map.get(¤t_symbol_ref.importer()) { - for used_symbol in module_result.used_symbol_refs.iter() { - // graph.add_edge(¤t_symbol_ref, used_symbol); - symbol_queue.push_back((used_symbol.clone(), vec![])); - } - }; - } - self.symbol_graph.add_node(¤t_symbol_ref); - // We don't need mark the symbol usage if it is from a bailout module because - // bailout module will skipping tree-shaking anyway - // let is_bailout_module_identifier = self.bailout_modules.contains_key(¤t_symbol_ref.src()); - match ¤t_symbol_ref { - SymbolRef::Declaration(symbol) => { - merge_used_export_type( - used_export_module_identifiers, - symbol.src(), - ModuleUsedType::DIRECT, - ); - } - SymbolRef::Indirect(IndirectTopLevelSymbol { - ty: IndirectType::ReExport(_, _), - src, - .. - }) => { - merge_used_export_type( - used_export_module_identifiers, - *src, - ModuleUsedType::REEXPORT, - ); - } - SymbolRef::Indirect(IndirectTopLevelSymbol { - ty: IndirectType::Temp(_) | IndirectType::Import(_, _) | IndirectType::ImportDefault(_), - src, - .. - }) => { - merge_used_export_type( - used_export_module_identifiers, - *src, - ModuleUsedType::INDIRECT, - ); - } - SymbolRef::Star(StarSymbol { - ty: StarSymbolKind::ReExportAll, - module_ident, - .. - }) - | SymbolRef::Star(StarSymbol { - ty: StarSymbolKind::ReExportAllAs, - module_ident, - .. - }) => { - merge_used_export_type( - used_export_module_identifiers, - *module_ident, - ModuleUsedType::EXPORT_ALL, - ); - } - SymbolRef::Url { src, .. } => { - merge_used_export_type(used_export_module_identifiers, *src, ModuleUsedType::DIRECT); - } - _ => {} - }; - match current_symbol_ref { - SymbolRef::Declaration(ref symbol) => { - let module_result = analyze_map.get(&symbol.src()).expect("TODO:"); - if let Some(set) = module_result - .reachable_import_of_export - .get(symbol.exported()) - { - for symbol_ref_ele in set.iter() { - self - .symbol_graph - .add_edge(¤t_symbol_ref, symbol_ref_ele); - let is_imported = module_result.import_map.get(&symbol.id().atom).is_some(); - let next_member_chain = if is_imported { - // Considering following scenario, so we need to replace first name with local id - // instead of exported name - // import * as _Lib from "./lib"; - // export { _Lib as Lib }; - let mut normalized_member_chain = vec![symbol.id().atom.clone()]; - normalized_member_chain.extend(member_chain.iter().skip(1).cloned()); - normalized_member_chain - } else { - vec![] - }; - - symbol_queue.push_back((symbol_ref_ele.clone(), next_member_chain)); - } - }; - - // Assume the module name is app.js - // ```js - // import {myanswer, secret} from './lib' - // export {myanswer as m, secret as s} - // ``` - // In such scenario there are two `myanswer` binding would create - // one for `app.js`, one for `lib.js` - // the binding in `app.js` used for shake the `export {xxx}` - // In other words, we need two binding for supporting indirect redirect. - // if let Some(import_symbol_ref) = module_result.import_map.get(&symbol.id().atom) { - // dbg!(&symbol); - // dbg!(&member_chain); - // dbg!(&import_symbol_ref); - // self - // .symbol_graph - // .add_edge(¤t_symbol_ref, import_symbol_ref); - // - // symbol_queue.push_back((import_symbol_ref.clone(), member_chain)); - // - // dbg!(&symbol_queue); - // } - } - SymbolRef::Indirect(ref indirect_symbol) => { - let _importer = indirect_symbol.importer(); - let module_result = match analyze_map.get(&indirect_symbol.src) { - Some(module_result) => module_result, - None => { - // eprintln!( - // "Can't get optimize dep result for module {}", - // indirect_symbol.uri, - // ); - return; - } - }; - - match module_result.export_map.get(indirect_symbol.indirect_id()) { - Some(symbol) => match symbol { - SymbolRef::Indirect(IndirectTopLevelSymbol { - ty: IndirectType::ReExport(_, _), - .. - }) => { - // This only happen when a bailout module have reexport statement, e.g. crates/rspack/tests/tree-shaking/ts-target-es5 - let is_same_symbol = ¤t_symbol_ref == symbol; - if !is_same_symbol { - self.symbol_graph.add_edge(¤t_symbol_ref, symbol); - } - symbol_queue.push_back((symbol.clone(), member_chain.clone())); - // if a bailout module has reexport symbol - if let Some(set) = module_result - .reachable_import_of_export - .get(indirect_symbol.indirect_id()) - { - for symbol_ref_ele in set.iter() { - self.symbol_graph.add_edge(symbol, symbol_ref_ele); - symbol_queue.push_back((symbol_ref_ele.clone(), member_chain.clone())); - } - }; - } - _ => { - self.symbol_graph.add_edge(¤t_symbol_ref, symbol); - symbol_queue.push_back((symbol.clone(), member_chain)); - } - }, - - None => { - // TODO: better diagnostic and handle if multiple extends_map has export same symbol - let mut ret = vec![]; - // Checking if any inherit export map is belong to a bailout module - let mut bailout_module_identifiers = HashSet::default(); - let mut is_first_result = true; - for (inherit_module_identifier, extends_export_map) in - module_result.inherit_export_maps.iter() - { - // - // ```js - // // index.js - // import {a} from './a.js' - // a - // // a.js - // export * from './b.js' - // export * from './c.js' - // //b.js - // export * from './d.js' - // //c.js - // export const c = 10; - // //d.js - // export const a = 3; - // ``` - // the path is a.js -> b.js -> d.js - if let Some(value) = extends_export_map.get(indirect_symbol.indirect_id()) { - ret.push((inherit_module_identifier, value)); - if is_first_result { - let tuple = (indirect_symbol.src, *inherit_module_identifier); - let connection_stats = match traced_tuple.entry(tuple) { - Entry::Occupied(occ) => ReExportConnectionStatus::Occupied(occ.get().clone()), - Entry::Vacant(vac) => { - let mut reexport_paths = vec![]; - for path in algo::all_simple_paths::, _>( - &inherit_extend_graph, - indirect_symbol.src, - *inherit_module_identifier, - 0, - None, - ) { - let mut reexport_path = vec![]; - // TODO: use real dependencyID - for i in 0..path.len() - 1 { - let star_symbol = StarSymbol::new( - path[i + 1], - Default::default(), - path[i], - StarSymbolKind::ReExportAll, - DependencyId::default(), - ); - - let reexport_ref = SymbolRef::Star(star_symbol); - reexport_path.push(reexport_ref); - } - reexport_paths.push(reexport_path); - } - let first_reexport_of_each_path = reexport_paths - .iter() - .filter_map(|path| path.first().cloned()) - .collect::>(); - vac.insert(first_reexport_of_each_path); - ReExportConnectionStatus::Vacant(reexport_paths) - } - }; - match connection_stats { - ReExportConnectionStatus::Vacant(reexport_paths) => { - for reexport_path in reexport_paths { - let mut pre = ¤t_symbol_ref; - for reexport_ref in reexport_path.iter() { - self.symbol_graph.add_edge(pre, reexport_ref); - pre = reexport_ref; - if !evaluated_module_identifiers.contains(&reexport_ref.importer()) { - evaluated_module_identifiers.insert(reexport_ref.importer()); - if let Some(module_result) = analyze_map.get(&reexport_ref.importer()) { - for used_symbol in module_result.used_symbol_refs.iter() { - symbol_queue.push_back((used_symbol.clone(), vec![])); - } - }; - } - merge_used_export_type( - used_export_module_identifiers, - reexport_ref.importer(), - ModuleUsedType::EXPORT_ALL, - ); - } - self.symbol_graph.add_edge(pre, value); - } - } - ReExportConnectionStatus::Occupied(ref first_reexport_of_each_path) => { - for reexport in first_reexport_of_each_path { - self.symbol_graph.add_edge(¤t_symbol_ref, reexport); - } - } - } - is_first_result = false; - } - } - if self.bailout_modules.contains_key(inherit_module_identifier) { - bailout_module_identifiers.insert(*inherit_module_identifier); - } - } - - let selected_symbol = match ret.len() { - 0 if !bailout_module_identifiers.is_empty() => { - for mi in bailout_module_identifiers { - let mid = SymbolRef::Star(StarSymbol { - src: mi, - binding: Default::default(), - module_ident: indirect_symbol.src(), - ty: StarSymbolKind::ReExportAll, - dep_id: DependencyId::default(), - }); - - self.symbol_graph.add_edge(¤t_symbol_ref, &mid); - self.symbol_graph.add_edge( - &mid, - &SymbolRef::Declaration(Symbol::new( - mi, - BetterId { - ctxt: SyntaxContext::empty(), - atom: indirect_symbol.indirect_id().clone(), - }, - SymbolType::Temp, - None, - )), - ); - - merge_used_export_type( - used_export_module_identifiers, - mi, - ModuleUsedType::DIRECT, - ); - } - return; - } - 0 => { - self.symbol_graph.add_edge( - ¤t_symbol_ref, - &SymbolRef::Declaration(Symbol::new( - module_result.module_identifier, - BetterId { - ctxt: SyntaxContext::empty(), - atom: indirect_symbol.indirect_id().clone(), - }, - SymbolType::Temp, - None, - )), - ); - merge_used_export_type( - used_export_module_identifiers, - current_symbol_ref.src(), - ModuleUsedType::INDIRECT, - ); - return; - - // Only report diagnostic when following conditions are satisfied: - // 1. src module is not a bailout module and src module using ESM syntax to export some symbols. - // 2. src module has no reexport or any reexport src module is not bailouted - // let should_diagnostic = !is_bailout_module_identifier - // && module_result.module_syntax == ModuleSyntax::ESM - // && (module_result.inherit_export_maps.is_empty() - // || !has_bailout_module_identifiers); - // if should_diagnostic { - // let module_path = self - // .compilation - // .get_module_graph() - // .normal_module_source_path_by_identifier(&module_result.module_identifier); - // let importer_module_path = self - // .compilation - // .get_module_graph() - // .normal_module_source_path_by_identifier(&indirect_symbol.importer()); - // if let (Some(module_path), Some(importer_module_path)) = - // (module_path, importer_module_path) - // { - // let error_message = format!( - // "{} did not export `{}`, imported by {}", - // contextify(&self.compilation.options.context, &module_path), - // indirect_symbol.indirect_id(), - // contextify(&self.compilation.options.context, &importer_module_path), - // ); - // errors.push(Error::InternalError(InternalError { - // error_message, - // severity: Severity::Warn, - // })); - // } - // return; - // } else { - // // TODO: This branch should be remove after we analyze module.exports - // // If one of inherit module is a bailout module, that most probably means that module has some common js export - // // which we don't analyze yet, we just pass it. It is alright because we don't modified the ast of bailout module - // return; - // } - } - 1 => ret[0].1.clone(), - // multiple export candidate in reexport - // mark the first symbol_ref as used, align to webpack - _ => { - let mut error_message = format!( - "Conflicting star exports for the name '{}' in ", - indirect_symbol.indirect_id() - ); - // let cwd = std::env::current_dir(); - let module_graph = self.compilation.get_module_graph(); - let module_identifier_list = ret - .iter() - .filter_map(|(module_identifier, _)| { - module_graph.normal_module_source_path_by_identifier(module_identifier) - }) - .map(|identifier| { - contextify(self.compilation.options.context.clone(), &identifier) - }) - .collect::>(); - error_message += &join_string_component(module_identifier_list); - errors.push(InternalError::new(error_message, Severity::Warn).into()); - ret[0].1.clone() - } - }; - symbol_queue.push_back((selected_symbol, member_chain)); - } - }; - // graph.add_edge(¤t_symbol_ref, &symbol); - - // symbol_queue.push_back(symbol); - } - SymbolRef::Star(ref star_symbol) => { - // If a star ref is used. e.g. - // ```js - // import * as all from './test.js' - // all - // ``` - // then, all the exports in `test.js` including - // export defined in `test.js` and all related - // reexport should be marked as used - let src_module_identifier: Identifier = star_symbol.src(); - let analyze_result = match analyze_map.get(&src_module_identifier) { - Some(analyze_result) => analyze_result, - None => { - let module_graph = self.compilation.get_module_graph(); - if is_js_like_uri(&src_module_identifier) { - let module_path = - module_graph.normal_module_source_path_by_identifier(&star_symbol.src()); - if let Some(module_path) = module_path { - let error_message = format!("Can't get analyze result of {module_path}"); - errors.push(InternalError::new(error_message, Severity::Warn).into()); - } - } - return; - } - }; - - let (include_default_export, next_member_chain) = match star_symbol.ty() { - StarSymbolKind::ReExportAllAs => { - let next_member_chain = if let Some(name) = member_chain.first() - && name == star_symbol.binding() - { - member_chain[1..].to_vec() - } else { - vec![] - }; - (true, next_member_chain) - } - StarSymbolKind::ImportAllAs => { - let next_member_chain = if let Some(name) = member_chain.first() - && name == star_symbol.binding() - { - member_chain[1..].to_vec() - } else { - vec![] - }; - (true, next_member_chain) - } - StarSymbolKind::ReExportAll => (false, vec![]), - }; - - // try to access first member expr element - if let Some(name) = next_member_chain.first() { - if let Some(export_symbol_ref) = analyze_result.export_map.get(name) { - self - .symbol_graph - .add_edge(¤t_symbol_ref, export_symbol_ref); - symbol_queue.push_back((export_symbol_ref.clone(), next_member_chain.to_vec())); - return; - } - - for (inherit_module_identifier, extends_export_map) in - analyze_result.inherit_export_maps.iter() - { - if let Some(value) = extends_export_map.get(name) { - let tuple = (star_symbol.src, *inherit_module_identifier); - let connection_stats = match traced_tuple.entry(tuple) { - Entry::Occupied(occ) => { - // self.symbol_graph.add_edge(¤t_symbol_ref, to); - ReExportConnectionStatus::Occupied(occ.get().clone()) - } - Entry::Vacant(vac) => { - let mut reexport_paths = vec![]; - for path in algo::all_simple_paths::, _>( - &inherit_extend_graph, - star_symbol.src, - *inherit_module_identifier, - 0, - None, - ) { - let mut reexport_path = vec![]; - for i in 0..path.len() - 1 { - // TODO: use real dependency id, currently we don't have - let star_symbol = StarSymbol::new( - path[i + 1], - Default::default(), - path[i], - StarSymbolKind::ReExportAll, - DependencyId::default(), - ); - - let reexport_ref = SymbolRef::Star(star_symbol); - reexport_path.push(reexport_ref); - } - reexport_paths.push(reexport_path); - } - let first_reexport_of_each_path = reexport_paths - .iter() - .filter_map(|path| path.first().cloned()) - .collect::>(); - vac.insert(first_reexport_of_each_path); - ReExportConnectionStatus::Vacant(reexport_paths) - } - }; - match connection_stats { - ReExportConnectionStatus::Vacant(reexport_paths) => { - for reexport_path in reexport_paths { - let mut pre = ¤t_symbol_ref; - for reexport_ref in reexport_path.iter() { - self.symbol_graph.add_edge(pre, reexport_ref); - pre = reexport_ref; - if !evaluated_module_identifiers.contains(&reexport_ref.importer()) { - evaluated_module_identifiers.insert(reexport_ref.importer()); - if let Some(module_result) = analyze_map.get(&reexport_ref.importer()) { - for used_symbol in module_result.used_symbol_refs.iter() { - symbol_queue.push_back((used_symbol.clone(), vec![])); - } - }; - } - merge_used_export_type( - used_export_module_identifiers, - reexport_ref.importer(), - ModuleUsedType::EXPORT_ALL, - ); - } - self.symbol_graph.add_edge(pre, value); - } - } - ReExportConnectionStatus::Occupied(ref first_reexport_of_each_path) => { - for reexport in first_reexport_of_each_path { - self.symbol_graph.add_edge(¤t_symbol_ref, reexport); - } - } - } - - symbol_queue.push_back((value.clone(), next_member_chain)); - return; - } - // has_bailout_module_identifiers = has_bailout_module_identifiers - // || self.bailout_modules.contains_key(module_identifier); - } - } - - if !matches!(star_symbol.ty(), StarSymbolKind::ReExportAll) { - // It means the module has not export or reexport target reference, maybe the src module - // is a empty module, we should avoid to eliminate the module even it is a sideEffects - // free module - merge_used_export_type( - used_export_module_identifiers, - src_module_identifier, - ModuleUsedType::EXPORT_ALL, - ); - } - // Failed to look up a specific element, connect all - for (key, export_symbol_ref) in analyze_result.export_map.iter() { - if !include_default_export && key == "default" { - } else { - self - .symbol_graph - .add_edge(¤t_symbol_ref, export_symbol_ref); - symbol_queue.push_back((export_symbol_ref.clone(), vec![])); - } - } - - for (key, _) in analyze_result.inherit_export_maps.iter() { - let export_all = SymbolRef::Star(StarSymbol::new( - *key, - Default::default(), - src_module_identifier, - StarSymbolKind::ReExportAll, - DependencyId::default(), - )); - self.symbol_graph.add_edge(¤t_symbol_ref, &export_all); - symbol_queue.push_back((export_all.clone(), vec![])); - } - } - SymbolRef::Url { .. } | SymbolRef::Worker { .. } => {} - SymbolRef::Usage(ref binding, ref member_chain, ref src) => { - let analyze_result = analyze_map.get(src).expect("Should have analyze result"); - if let Some(import_symbol_ref) = analyze_result.import_map.get(binding) { - self - .symbol_graph - .add_edge(¤t_symbol_ref, import_symbol_ref); - let mut next_member_chain = vec![binding.clone()]; - next_member_chain.extend(member_chain.iter().cloned()); - symbol_queue.push_back((import_symbol_ref.clone(), next_member_chain)); - } - } - } - } - #[allow(clippy::too_many_arguments)] - fn collect_from_entry_like( - &mut self, - analyze_map: &IdentifierMap, - entry_identifier: ModuleIdentifier, - evaluated_module_identifiers: &mut IdentifierSet, - used_export_module_identifiers: &mut IdentifierMap, - inherit_extend_graph: &GraphMap, - traced_tuple: &mut HashMap<(ModuleIdentifier, ModuleIdentifier), Vec>, - entry_type: EntryLikeType, - visited_symbol_ref: &mut HashSet, - errors: &mut Vec, - ) { - let mut q = VecDeque::new(); - let entry_module_result = match analyze_map.get(&entry_identifier) { - Some(result) => result, - None => { - // TODO: checking if it is none js type - return; - // panic!("Can't get analyze result from entry_identifier {}", entry_identifier); - } - }; - - // by default webpack will not mark the `export *` as used in entry module - if matches!(entry_type, EntryLikeType::Bailout) { - let inherit_export_symbols = get_inherit_export_symbol_ref(entry_module_result); - if !inherit_export_symbols.is_empty() { - // transitive bailout - inherit_export_symbols.iter().for_each(|item| { - q.push_back(( - SymbolRef::Star(StarSymbol::new( - item.src(), - Default::default(), - entry_identifier, - StarSymbolKind::ReExportAll, - DependencyId::default(), - )), - vec![], - )); - }); - } - q.extend( - inherit_export_symbols - .into_iter() - .map(|item| (item, vec![])), - ); - q.extend( - entry_module_result - .used_symbol_refs - .iter() - .cloned() - .map(|item| (item, vec![])), - ); - } - - for item in entry_module_result.export_map.values() { - self.mark_symbol( - (item.clone(), vec![]), - analyze_map, - &mut q, - evaluated_module_identifiers, - used_export_module_identifiers, - inherit_extend_graph, - traced_tuple, - visited_symbol_ref, - errors, - ); - } - - while let Some(symbol_ref) = q.pop_front() { - self.mark_symbol( - symbol_ref, - analyze_map, - &mut q, - evaluated_module_identifiers, - used_export_module_identifiers, - inherit_extend_graph, - traced_tuple, - visited_symbol_ref, - errors, - ); - } - } -} - -// TODO: dep replacement -// fn dependency_replacement() { -// let module_item_map = if side_effects_options { -// // let start = Instant::now(); -// // let dependency_replacement = update_dependency( -// // &symbol_graph, -// // &used_export_module_identifiers, -// // &bailout_module_identifiers, -// // &side_effects_free_modules, -// // &compilation.entry_module_identifiers, -// // ); - -// // // dbg!(&dependency_replacement); - -// // // apply replacement start -// // // let mut module_item_map = IdentifierMap::default(); -// // let module_item_map = compilation.apply_dependency_replacement( -// // dependency_replacement, -// // &mut dead_nodes_index, -// // &mut symbol_graph, -// // ); - -// // // dbg!(&module_item_map.keys().collect::>()); -// // dbg!(&start.elapsed()); -// // // module_item_map -// IdentifierMap::default() -// } else { -// IdentifierMap::default() -// }; -// } - -fn get_inherit_export_ref_graph( - analyze_result_map: &mut IdentifierMap, - mg: &ModuleGraph, -) -> GraphMap { - // calculate relation of module that has `export * from 'xxxx'` - let inherit_export_ref_graph = create_inherit_graph(&*analyze_result_map, mg); - // key is the module_id of module that potential have reexport all symbol from other module - // value is the set which contains several module_id the key related module need to inherit - let map_of_inherit_map = get_extends_map(&inherit_export_ref_graph); - - for (module_id, inherit_export_module_id) in map_of_inherit_map.iter() { - // This is just a work around for rustc checker, because we have immutable and mutable borrow at the same time. - let mut inherit_export_maps = { - let main_module = if let Some(result) = analyze_result_map.get_mut(module_id) { - result - } else { - tracing::warn!("Can't get analyze result of {}", module_id); - continue; - }; - std::mem::take(&mut main_module.inherit_export_maps) - }; - for inherit_export_module_identifier in inherit_export_module_id { - let inherit_export_map = if let Some(inherit_export_map) = analyze_result_map - .get(inherit_export_module_identifier) - .map(|analyze_result| { - analyze_result - .export_map - .iter() - .filter_map(|(k, v)| { - // export * should not reexport default export - if k == "default" { - None - } else { - Some((k.clone(), v.clone())) - } - }) - .collect::>() - }) { - inherit_export_map - } else { - tracing::warn!( - "Can't get analyze result of {}", - inherit_export_module_identifier - ); - HashMap::default() - }; - - inherit_export_maps.insert(*inherit_export_module_identifier, inherit_export_map); - } - analyze_result_map - .get_mut(module_id) - .unwrap_or_else(|| panic!("Module({module_id:?}) not found")) - .inherit_export_maps = inherit_export_maps; - } - inherit_export_ref_graph -} - -// async fn par_analyze_module(compilation: &mut Compilation) -> IdentifierMap { -// let analyze_results = { -// compilation -// .get_module_graph() -// .get_module_graph()_modules() -// .par_iter() -// .filter_map(|(module_identifier, mgm)| { -// let optimize_analyze_result = if mgm.module_type.is_js_like() { -// match compilation -// .get_module_graph() -// .module_by_identifier(&mgm.module_identifier) -// .and_then(|module| module.as_normal_module().and_then(|m| m.ast())) -// // A module can missing its AST if the module is failed to build -// .and_then(|ast| ast.as_javascript()) -// { -// Some(ast) => JsModule::new( -// ast, -// &mgm -// .dependencies -// .iter() -// .filter_map(|id| compilation.get_module_graph().dependency_by_id(id).cloned()) -// .collect::>(), -// *module_identifier, -// &compilation.options, -// ) -// .analyze(), -// None => { -// return None; -// } -// } -// } else { -// AssetModule::new(*module_identifier).analyze() -// }; - -// // dbg_matches!( -// // &module_identifier.as_str(), -// // &optimize_analyze_result.reachable_import_of_export, -// // &optimize_analyze_result.used_symbol_refs, -// // &optimize_analyze_result.export_map, -// // &optimize_analyze_result.import_map, -// // &optimize_analyze_result.side_effects -// // ); - -// Some((*module_identifier, optimize_analyze_result)) -// }) -// .collect::>() -// }; -// analyze_results -// } - -fn update_reachable_dependency( - symbol_ref: &SymbolRef, - reachable_dependency_identifier: &mut IdentifierSet, - symbol_graph: &SymbolGraph, -) { - let root_module_identifier = symbol_ref.importer(); - let node_index = *symbol_graph - .get_node_index(symbol_ref) - .unwrap_or_else(|| panic!("Can't get NodeIndex of {symbol_ref:?}")); - let mut q = VecDeque::from_iter([node_index]); - let mut visited = HashSet::default(); - while let Some(cur) = q.pop_front() { - if visited.contains(&cur) { - continue; - } else { - visited.insert(cur); - } - let symbol = symbol_graph - .get_symbol(&cur) - .expect("Can't get Symbol of NodeIndex"); - let module_identifier = symbol.src(); - if module_identifier == root_module_identifier { - for ele in symbol_graph - .graph - .edges_directed(node_index, petgraph::Direction::Outgoing) - { - let target_node_index = ele.target(); - q.push_back(target_node_index); - } - } else { - reachable_dependency_identifier.insert(module_identifier); - } - } -} - -fn update_reachable_symbol( - dead_node_index: &HashSet, - symbol_node_index: NodeIndex, - visited_symbol_node_index: &mut HashSet, -) { - if dead_node_index.contains(&symbol_node_index) { - return; - } - visited_symbol_node_index.insert(symbol_node_index); -} - -fn is_js_like_uri(uri: &str) -> bool { - fn resolve_module_type_by_uri(uri: &str) -> Option { - let uri = std::path::Path::new(uri); - let ext = uri.extension()?.to_str()?; - Some(ModuleType::from(ext)) - } - match resolve_module_type_by_uri(uri) { - Some(module_type) => matches!( - module_type, - crate::ModuleType::Js | crate::ModuleType::JsDynamic | crate::ModuleType::JsEsm - ), - None => false, - } -} - -fn get_extends_map( - export_all_ref_graph: &GraphMap, -) -> IdentifierMap { - let mut map = IdentifierMap::default(); - for node in export_all_ref_graph.nodes() { - let reachable_set = get_reachable(node, export_all_ref_graph); - map.insert(node, reachable_set); - } - map -} - -fn get_reachable( - start: ModuleIdentifier, - g: &GraphMap, -) -> IdentifierLinkedSet { - let mut dfs = Dfs::new(&g, start); - - let mut reachable_module_id = IdentifierLinkedSet::default(); - while let Some(next) = dfs.next(g) { - // reachable inherit export map should not include self. - if reachable_module_id.contains(&next) || next == start { - continue; - } else { - reachable_module_id.insert(next); - } - } - reachable_module_id -} - -fn create_inherit_graph( - analyze_map: &IdentifierMap, - mg: &ModuleGraph, -) -> GraphMap { - let mut g = DiGraphMap::new(); - for (module_id, result) in analyze_map.iter() { - for export_all_dep_id in result.export_all_dep_id.iter().rev() { - if let Some(export_all_module_id) = mg.module_identifier_by_dependency_id(export_all_dep_id) { - g.add_edge(*module_id, *export_all_module_id, ()); - } - } - } - g -} - -pub fn merge_used_export_type( - used_export_map: &mut IdentifierMap, - module_id: ModuleIdentifier, - ty: ModuleUsedType, -) { - match used_export_map.entry(module_id) { - Entry::Occupied(mut occ) => { - occ.borrow_mut().get_mut().insert(ty); - } - Entry::Vacant(vac) => { - vac.insert(ty); - } - } -} - -fn get_inherit_export_symbol_ref(entry_module_result: &OptimizeAnalyzeResult) -> Vec { - let mut export_atom = HashSet::default(); - let mut inherit_export_symbols = vec![]; - // All the reexport star symbol should be included in the bundle - // TODO: webpack will emit an warning, we should align to them - for inherit_map in entry_module_result.inherit_export_maps.values() { - for (atom, symbol_ref) in inherit_map.iter() { - if export_atom.contains(atom) { - continue; - } else { - export_atom.insert(atom.clone()); - inherit_export_symbols.push(symbol_ref.clone()); - } - } - } - inherit_export_symbols -} - -fn get_symbol_path(symbol_graph: &SymbolGraph, cur: NodeIndex) -> Vec> { - fn recursive( - symbol_graph: &SymbolGraph, - cur_path: &mut Vec, - paths: &mut Vec>, - visited_node: &mut HashSet, - cur: NodeIndex, - ) { - if visited_node.contains(&cur) { - return; - } - cur_path.push(cur); - visited_node.insert(cur); - let mut has_outgoing = false; - for edge in symbol_graph - .graph - .edges_directed(cur, petgraph::Direction::Outgoing) - { - has_outgoing = true; - let to = edge.target(); - recursive(symbol_graph, cur_path, paths, visited_node, to); - } - visited_node.remove(&cur); - if !has_outgoing { - paths.push(cur_path.clone()); - } - } - let mut cur_path = vec![]; - let mut paths = vec![]; - let mut visited_node = HashSet::default(); - recursive( - symbol_graph, - &mut cur_path, - &mut paths, - &mut visited_node, - cur, - ); - paths - .into_iter() - .map(|path| { - path - .into_iter() - .map(|node_index| { - symbol_graph - .get_symbol(&node_index) - .cloned() - .expect("Can't get nodeIndex of SymbolRef") - }) - .collect::>() - }) - .collect::>() -} -// TODO: dep replacement -// fn update_dependency( -// symbol_graph: &SymbolGraph, -// used_export_module_identifiers: &IdentifierMap, -// bail_out_module_identifiers: &IdentifierMap, -// side_effects_free_modules: &IdentifierSet, -// entry_modules_identifier: &IdentifierSet, -// ) -> Vec { -// // dbg!(&used_export_module_identifiers); -// let mut exported_symbol_set = HashSet::default(); -// let mut dependency_replacement_list = vec![]; -// let directed_symbol_node_set = symbol_graph -// .symbol_to_index -// .iter() -// .filter_map(|(k, v)| { -// if matches!(k, SymbolRef::Direct(_)) { -// Some(*v) -// } else { -// None -// } -// }) -// .collect::>(); -// for (symbol_ref, node_index) in symbol_graph.symbol_to_index.iter() { -// // println!("----------------"); -// if !matches!(symbol_ref, SymbolRef::Direct(_)) { -// continue; -// } - -// let mut paths = Vec::new(); -// recursive_visited( -// symbol_graph, -// &mut vec![], -// &mut paths, -// &mut HashSet::default(), -// *node_index, -// &directed_symbol_node_set, -// ); -// let symbol_paths = paths -// .into_par_iter() -// .map(|path| { -// path -// .iter() -// .map(|node_index| symbol_graph.get_symbol(node_index).unwrap().clone()) -// .collect::>() -// }) -// .collect::>(); -// // dbg!(&symbol_paths); -// // sliding window -// for symbol_path in symbol_paths { -// // dbg!(&symbol_path); -// let mut start = 0; -// let mut end = 0; -// init_sliding_window(&mut start, &mut end, &symbol_path); - -// while end < symbol_path.len() { -// let end_symbol = &symbol_path[end]; -// // let is_reexport = end_symbol.is_star() -// let owner_module_identifier = end_symbol.module_identifier(); -// // let is_owner_module_export_used = used_export_module_identifiers -// // .get(&owner_module_identifier) -// // .map(|flag| flag.contains(ModuleUsedType::DIRECT)) -// // .unwrap_or(false); - -// // TODO: optimize export * -// // safe to process -// // if is_owner_module_export_used -// // || bail_out_module_identifiers.contains_key(&owner_module_identifier) -// // || !side_effects_free_modules.contains(&owner_module_identifier) -// // || entry_modules_identifier.contains(&owner_module_identifier) -// // { -// // if end - start > 1 { -// // println!("cant removed: {start}, {end}"); -// // validate_and_insert_replacement( -// // false, -// // &mut dependency_replacement_list, -// // &symbol_path, -// // end - 1, -// // start, -// // used_export_module_identifiers, -// // ); -// // // dependency_replacement_list.push(DependencyReplacement { -// // // from: symbol_path[end].clone(), -// // // replacement: symbol_path[start].clone(), -// // // }) -// // } -// // init_sliding_window(&mut start, &mut end, &symbol_path); -// // continue; -// // } - -// if !end_symbol.is_skipable_symbol() && end != symbol_path.len() - 1 { -// if end - start > 1 { -// // println!("none reexport: {start}, {end}"); -// validate_and_insert_replacement( -// false, -// &mut dependency_replacement_list, -// &symbol_path, -// end - if end_symbol.is_indirect() { 0 } else { 1 }, -// start, -// used_export_module_identifiers, -// &mut exported_symbol_set, -// ); -// } - -// init_sliding_window(&mut start, &mut end, &symbol_path); - -// continue; -// } -// end += 1; -// } -// // because last window range is [start, end - 1] -// if end - start > 1 { -// // println!("end check: {start}, {end}"); -// validate_and_insert_replacement( -// true, -// &mut dependency_replacement_list, -// &symbol_path, -// end - 1, -// start, -// used_export_module_identifiers, -// &mut exported_symbol_set, -// ); -// } -// } -// // println!("end ----------------"); -// } -// // dbg!(&exported_symbol_set); -// dependency_replacement_list -// } - -// TODO: dep replacement -// fn validate_and_insert_replacement( -// end_check: bool, -// dependency_replacement_list: &mut Vec, -// symbol_path: &Vec, -// end: usize, -// start: usize, -// used_export_module_identifiers: &IdentifierMap, -// used_export_symbol_set: &mut HashSet, -// ) { -// enum CheckResult { -// Valid, -// Invalid, -// Wrong, -// } -// // println!( -// // "{:#?}, \n{:#?}, {}", -// // &symbol_path[start], &symbol_path[end], end_check -// // ); - -// let unused_export_symbol = symbol_path[start..=end] -// .iter() -// .filter(|symbol| { -// used_export_module_identifiers -// .get(&symbol.module_identifier()) -// .map(|ty| !ty.contains(ModuleUsedType::DIRECT)) -// .unwrap_or(false) -// }) -// .map(|s| s.module_identifier()) -// .collect::>(); - -// used_export_symbol_set.extend(unused_export_symbol.iter().cloned()); - -// // dbg!(&unused_export_symbol); -// let is_valid_path = match (&symbol_path[start], &symbol_path[end]) { -// (SymbolRef::Direct(_), SymbolRef::Direct(_)) => false, -// (SymbolRef::Direct(replace), SymbolRef::Indirect(original)) => { -// // validate if we this path point to same symbol -// // we know that start must be has `SymbolType == Define` -// if end - start > 1 { -// // dbg!(&&symbol_path[start..=end]); -// } -// is_same_symbol(original, end, start, symbol_path, replace) -// } -// (SymbolRef::Direct(_), SymbolRef::Star(_)) => false, -// (SymbolRef::Indirect(_), SymbolRef::Direct(_)) => false, -// (SymbolRef::Indirect(replace), SymbolRef::Indirect(_)) => { -// matches!(replace.ty, IndirectType::ReExport(_, _)) -// } -// (SymbolRef::Indirect(_), SymbolRef::Star(_)) => { -// // todo!() -// // TODO: -// false -// } -// (SymbolRef::Star(_), SymbolRef::Direct(_)) => todo!(), -// (SymbolRef::Star(replace), SymbolRef::Indirect(_)) => { -// replace.ty == StarSymbolKind::ReExportAll -// // dbg!(&symbol_path[start]); -// // dbg!(&symbol_path[end]); -// // todo!() -// } -// (SymbolRef::Star(_), SymbolRef::Star(_)) => todo!(), -// }; -// if unused_export_symbol.len() > 0 && is_valid_path && end - start > 1 { -// if symbol_path[start..=end].len() > 3 { -// // dbg!(&symbol_path[start..=end]); -// } -// dependency_replacement_list.push(DependencyReplacement { -// original: symbol_path[end].clone(), -// to: symbol_path[end - 1].clone(), -// replacement: symbol_path[start].clone(), -// unused_export_symbol_count: unused_export_symbol.len(), -// }) -// } else { -// if !is_valid_path && !end_check { -// println!( -// "{:#?}, \n{:#?}, {}", -// &symbol_path[start], &symbol_path[end], end_check -// ); -// } -// } -// // if has_unused_export_symbol { -// // } -// } - -// TODO: dep replacement -// fn is_same_symbol( -// original: &IndirectTopLevelSymbol, -// end: usize, -// start: usize, -// symbol_path: &Vec, -// replace: &Symbol, -// ) -> bool { -// // dbg!(&symbol_path); -// let mut pre = match original.ty { -// IndirectType::ReExport(ref original, ref exported) => original.clone(), -// _ => original.indirect_id().clone(), -// }; -// let mut i = end - 1; -// while i > start { -// let cur = &symbol_path[i]; -// let next_id = match cur { -// SymbolRef::Direct(_) => unreachable!(), -// SymbolRef::Indirect(indirect) => match &indirect.ty { -// IndirectType::Temp(ref id) => { -// if id != &pre { -// return false; -// } -// id.clone() -// } -// IndirectType::ReExport(original, _) => { -// // let exported = indirect.id(); -// if &pre != indirect.id() { -// return false; -// } -// original.clone() -// } -// IndirectType::Import(..) => { -// unreachable!() -// } -// IndirectType::ImportDefault(_) => { -// unreachable!() -// } -// }, -// SymbolRef::Star(_) => pre, -// }; -// pre = next_id; -// i -= 1; -// } -// pre == replace.id().atom -// } - -// fn init_sliding_window(start: &mut usize, end: &mut usize, symbol_path: &Vec) { -// // println!("{start}, {end}"); -// *start = *end; -// while *start < symbol_path.len() && !could_be_start_of_path(&symbol_path[*start]) { -// *start += 1; -// } -// *end = *start + 1; -// loop { -// if *end >= symbol_path.len() { -// break; -// } -// if symbol_path[*end].module_identifier() != symbol_path[*start].module_identifier() { -// break; -// } -// *end += 1; -// } -// } - -// #[inline] -// pub fn could_be_start_of_path(symbol: &SymbolRef) -> bool { -// match symbol { -// SymbolRef::Direct(direct) => direct.ty() == &SymbolType::Define, -// SymbolRef::Indirect(indirect) => matches!(indirect.ty, IndirectType::ReExport(_, _)), -// SymbolRef::Star(star) => star.ty == StarSymbolKind::ReExportAll, -// } -// } - -// TODO: dep replacement -// fn apply_dependency_replacement( -// &mut self, -// dependency_replacement: Vec, -// dead_nodes_index: &mut HashSet, -// symbol_graph: &mut SymbolGraph, -// ) -> IdentifierMap> { -// let mut module_item_map: IdentifierMap> = IdentifierMap::default(); -// // let mut dead_nodes: HashSet = HashSet::new(); -// let temp_global = Default::default(); -// GLOBALS.set(&temp_global, || { -// let top_level_mark = Mark::new(); -// for replace in dependency_replacement { -// let DependencyReplacement { -// original, -// to, -// replacement, -// .. -// } = replace; -// // dbg!(&t); -// symbol_graph.remove_edge(&original, &to); -// symbol_graph.add_edge(&original, &replacement); -// let original_node_index = symbol_graph.get_node_index(&original).cloned().unwrap(); -// dead_nodes_index.insert(original_node_index); - -// let replace_src_module_id = replacement.module_identifier(); -// let contextify_src = contextify(&self.options.context, &replace_src_module_id); -// // TODO: Consider multiple replacement points to same original [SymbolRef] -// let (module_decl, module_ident) = match (original, to) { -// (SymbolRef::Indirect(ref indirect), to) => { -// let importer = indirect.importer(); -// let local_binding = match &indirect.ty { -// IndirectType::Temp(_) => todo!(), -// IndirectType::ReExport(original, exported) => match exported { -// Some(exported) => exported, -// None => original, -// }, -// IndirectType::Import(local, imported) => local, -// IndirectType::ImportDefault(binding) => binding, -// }; -// let import_binding = match replacement { -// SymbolRef::Direct(direct) => Some(direct.id().atom.clone()), -// SymbolRef::Indirect(indirect) => Some(indirect.indirect_id().clone()), -// SymbolRef::Star(_) => None, -// }; -// let module_decl = match (import_binding, local_binding) { -// (Some(import_binding), local_binding) => { -// let is_reexport_all = matches!(indirect.ty, IndirectType::ReExport(_, _)); -// if is_reexport_all { -// let specifier = ExportSpecifier::Named(ExportNamedSpecifier { -// span: DUMMY_SP, -// exported: if local_binding == &import_binding { -// None -// } else { -// // TODO: Considering another export name type -// Some(ModuleExportName::Ident(Ident::new( -// local_binding.clone(), -// DUMMY_SP, -// ))) -// }, -// orig: ModuleExportName::Ident(Ident::new(import_binding.clone(), DUMMY_SP)), -// is_type_only: false, -// }); -// let export = NamedExport { -// span: DUMMY_SP, -// specifiers: vec![specifier], -// src: Some(Box::new(Str { -// span: DUMMY_SP, -// value: contextify_src.into(), -// raw: None, -// })), -// type_only: false, -// asserts: None, -// }; -// ModuleDecl::ExportNamed(export) -// } else if &import_binding == "default" { -// let specifier = ImportSpecifier::Default(ImportDefaultSpecifier { -// span: DUMMY_SP, -// local: Ident::new( -// local_binding.clone(), -// DUMMY_SP.with_ctxt(SyntaxContext::empty().apply_mark(top_level_mark)), -// ), -// }); -// let import = ImportDecl { -// span: DUMMY_SP, -// specifiers: vec![specifier], -// src: Box::new(Str { -// span: DUMMY_SP, -// value: contextify_src.into(), -// raw: None, -// }), -// type_only: false, -// asserts: None, -// }; -// ModuleDecl::Import(import) -// } else { -// let specifier = ImportSpecifier::Named(ImportNamedSpecifier { -// span: DUMMY_SP, -// local: Ident::new( -// local_binding.clone(), -// DUMMY_SP.with_ctxt(SyntaxContext::empty().apply_mark(top_level_mark)), -// ), -// imported: if &import_binding == local_binding { -// None -// } else { -// // TODO: Consider ModuleExportName is `Str` -// Some(ModuleExportName::Ident(Ident::new( -// import_binding, -// DUMMY_SP, -// ))) -// }, -// is_type_only: false, -// }); -// let import = ImportDecl { -// span: DUMMY_SP, -// specifiers: vec![specifier], -// src: Box::new(Str { -// span: DUMMY_SP, -// value: contextify_src.into(), -// raw: None, -// }), -// type_only: false, -// asserts: None, -// }; -// ModuleDecl::Import(import) -// } -// } -// (None, _) => { -// match &indirect.ty { -// IndirectType::Temp(_) => todo!(), -// IndirectType::ReExport(_, _) => todo!(), -// IndirectType::Import(local, imported) => { -// let specifier = ImportSpecifier::Named(ImportNamedSpecifier { -// span: DUMMY_SP, -// local: Ident::new( -// local.clone(), -// DUMMY_SP.with_ctxt(SyntaxContext::empty().apply_mark(top_level_mark)), -// ), -// imported: imported.as_ref().map(|imported| { -// // TODO: Consider ModuleExportName is `Str` -// ModuleExportName::Ident(Ident::new(imported.clone(), DUMMY_SP)) -// }), -// is_type_only: false, -// }); -// let import = ImportDecl { -// span: DUMMY_SP, -// specifiers: vec![specifier], -// src: Box::new(Str { -// span: DUMMY_SP, -// value: contextify_src.into(), -// raw: None, -// }), -// type_only: false, -// asserts: None, -// }; -// ModuleDecl::Import(import) -// } -// IndirectType::ImportDefault(binding) => { -// let specifier = ImportSpecifier::Default(ImportDefaultSpecifier { -// span: DUMMY_SP, -// local: Ident::new( -// binding.clone(), -// DUMMY_SP.with_ctxt(SyntaxContext::empty().apply_mark(top_level_mark)), -// ), -// }); -// let import = ImportDecl { -// span: DUMMY_SP, -// specifiers: vec![specifier], -// src: Box::new(Str { -// span: DUMMY_SP, -// value: contextify_src.into(), -// raw: None, -// }), -// type_only: false, -// asserts: None, -// }; -// ModuleDecl::Import(import) -// } -// } -// } -// }; -// (module_decl, importer) -// } -// _ => todo!(), -// }; -// match module_item_map.entry(module_ident.into()) { -// Entry::Occupied(mut occ) => { -// let module_item = ModuleItem::ModuleDecl(module_decl); -// occ.borrow_mut().get_mut().push(module_item); -// } -// Entry::Vacant(occ) => { -// let module_item = ModuleItem::ModuleDecl(module_decl); -// occ.insert(vec![module_item]); -// } -// }; -// } -// module_item_map -// }) -// } - -// TODO: dep replacement -// #[derive(Debug, Clone)] -// struct DependencyReplacement { -// original: SymbolRef, -// to: SymbolRef, -// replacement: SymbolRef, -// unused_export_symbol_count: usize, -// } - -// impl DependencyReplacement { -// fn new( -// from: SymbolRef, -// to: SymbolRef, -// replacement: SymbolRef, -// unused_export_symbol_count: usize, -// ) -> Self { -// Self { -// original: from, -// to, -// unused_export_symbol_count, -// replacement, -// } -// } -// } - -// TODO: dep replacement -// fn recursive_visited( -// symbol_graph: &SymbolGraph, -// cur_path: &mut Vec, -// paths: &mut Vec>, -// visited_node: &mut HashSet, -// cur: NodeIndex, -// directed_symbol_node_index: &HashSet, -// ) { -// if visited_node.contains(&cur) { -// return; -// } -// let is_directed = directed_symbol_node_index.contains(&cur) && !cur_path.is_empty(); -// if is_directed { -// paths.push(cur_path.clone()); -// return; -// } -// visited_node.insert(cur); -// cur_path.push(cur); -// let mut has_neighbor = false; -// for ele in symbol_graph -// .graph -// .neighbors_directed(cur, petgraph::Direction::Incoming) -// { -// has_neighbor = true; -// recursive_visited( -// symbol_graph, -// cur_path, -// paths, -// visited_node, -// ele, -// directed_symbol_node_index, -// ); -// } -// if !has_neighbor { -// paths.push(cur_path.clone()); -// } -// cur_path.pop(); -// visited_node.remove(&cur); -// } diff --git a/crates/rspack_core/src/tree_shaking/visitor.rs b/crates/rspack_core/src/tree_shaking/visitor.rs index 633ceb81b81..d6aa4067685 100644 --- a/crates/rspack_core/src/tree_shaking/visitor.rs +++ b/crates/rspack_core/src/tree_shaking/visitor.rs @@ -25,7 +25,7 @@ use super::{ use crate::needs_refactor::WorkerSyntaxList; use crate::{ extract_member_expression_chain, BoxDependency, CompilerOptions, DependencyId, DependencyType, - ErrorSpan, FactoryMeta, ModuleGraph, ModuleIdentifier, ModuleSyntax, + ErrorSpan, ModuleGraph, ModuleIdentifier, ModuleSyntax, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1365,20 +1365,6 @@ impl<'a> ModuleRefAnalyze<'a> { } } } - pub fn get_side_effects_from_config( - factory_meta: Option<&FactoryMeta>, - ) -> Option { - // sideEffects in module.rule has higher priority, - // we could early return if we match a rule. - if let Some(FactoryMeta { - side_effect_free_old: Some(side_effect_free), - .. - }) = factory_meta - { - return Some(SideEffectType::Configuration(!*side_effect_free)); - } - None - } } pub fn get_side_effects_from_package_json( diff --git a/crates/rspack_plugin_asset/src/lib.rs b/crates/rspack_plugin_asset/src/lib.rs index 09515e2ab9a..a81c9da9004 100644 --- a/crates/rspack_plugin_asset/src/lib.rs +++ b/crates/rspack_plugin_asset/src/lib.rs @@ -7,9 +7,7 @@ use rayon::prelude::*; use rkyv::{from_bytes, to_bytes, AlignedVec, Archive, Deserialize, Serialize}; use rspack_core::{ rspack_sources::{BoxSource, RawSource, SourceExt}, - tree_shaking::{ - analyzer::OptimizeAnalyzer, asset_module::AssetModule, visitor::OptimizeAnalyzeResult, - }, + tree_shaking::visitor::OptimizeAnalyzeResult, AssetGeneratorDataUrl, AssetGeneratorDataUrlFnArgs, AssetParserDataUrl, BuildExtraDataType, BuildMetaDefaultObject, BuildMetaExportsType, ChunkGraph, ChunkUkey, CodeGenerationDataAssetInfo, CodeGenerationDataFilename, CodeGenerationDataUrl, Compilation, CompilationRenderManifest, @@ -274,8 +272,6 @@ impl ParserAndGenerator for AssetParserAndGenerator { source, build_meta, build_info, - compiler_options, - module_identifier, .. } = parse_context; build_info.strict = true; @@ -307,11 +303,7 @@ impl ParserAndGenerator for AssetParserAndGenerator { )) } }; - let analyze_result = if compiler_options.builtins.tree_shaking.enable() { - AssetModule::new(module_identifier).analyze() - } else { - OptimizeAnalyzeResult::default() - }; + let analyze_result = OptimizeAnalyzeResult::default(); Ok( rspack_core::ParseResult { @@ -501,43 +493,14 @@ async fn render_manifest( let chunk = compilation.chunk_by_ukey.expect_get(chunk_ukey); let module_graph = compilation.get_module_graph(); - let ordered_modules = compilation - .chunk_graph - .get_chunk_modules(chunk_ukey, &module_graph); + let ordered_modules = compilation.chunk_graph.get_chunk_modules_by_source_type( + chunk_ukey, + SourceType::Asset, + &module_graph, + ); let assets = ordered_modules .par_iter() - .filter(|m| { - let module = module_graph - .module_by_identifier(&m.identifier()) - // FIXME: use result - .expect("Failed to get module"); - - let all_incoming_analyzed = module_graph - .get_incoming_connections(&module.identifier()) - .iter() - .all(|c| { - if let Some(original_module_identifier) = c.original_module_identifier { - module_graph - .module_graph_module_by_identifier(&original_module_identifier) - .map(|original_module| { - !compilation - .bailout_module_identifiers - .contains_key(&original_module.module_identifier) - && original_module.module_type.is_js_like() - }) - .unwrap_or(false) - } else { - false - } - }); - - module.source_types().contains(&SourceType::Asset) - && (!all_incoming_analyzed - || compilation - .include_module_ids - .contains(&module.identifier())) - }) .map(|m| { let code_gen_result = compilation .code_generation_results diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs index 57151bc5aa1..82a7e7ac4cc 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs @@ -103,20 +103,10 @@ impl DependencyTemplate for HarmonyExportExpressionDependency { module_identifier: &Identifier, ) -> Option { let module_graph = compilation.get_module_graph(); - if compilation.options.is_new_tree_shaking() { - module_graph - .get_exports_info(module_identifier) - .id - .get_used_name(&module_graph, *runtime, UsedName::Str(name.into())) - } else if compilation.options.builtins.tree_shaking.is_true() { - module_graph - .get_exports_info(module_identifier) - .old_get_used_exports() - .contains(&name.into()) - .then(|| UsedName::Str(name.into())) - } else { - Some(UsedName::Str(name.into())) - } + module_graph + .get_exports_info(module_identifier) + .id + .get_used_name(&module_graph, *runtime, UsedName::Str(name.into())) } if let Some(declaration) = &self.declaration { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs index 6b243914c3e..89e3d3e1521 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs @@ -1,13 +1,13 @@ use std::hash::BuildHasherDefault; -use std::{collections::HashMap, sync::Arc}; +use std::sync::Arc; use indexmap::IndexSet; use rspack_core::{ - create_exports_object_referenced, create_no_exports_referenced, export_from_import, - get_exports_type, process_export_info, property_access, property_name, string_of_used_name, - AsContextDependency, ConnectionState, Dependency, DependencyCategory, DependencyCondition, - DependencyId, DependencyTemplate, DependencyType, ExportInfoId, ExportInfoProvided, - ExportNameOrSpec, ExportSpec, ExportsInfoId, ExportsOfExportsSpec, ExportsSpec, ExportsType, + create_exports_object_referenced, create_no_exports_referenced, get_exports_type, + process_export_info, property_access, property_name, string_of_used_name, AsContextDependency, + ConnectionState, Dependency, DependencyCategory, DependencyCondition, DependencyId, + DependencyTemplate, DependencyType, ExportInfoId, ExportInfoProvided, ExportNameOrSpec, + ExportSpec, ExportsInfoId, ExportsOfExportsSpec, ExportsSpec, ExportsType, ExtendedReferencedExport, HarmonyExportInitFragment, InitFragmentExt, InitFragmentKey, InitFragmentStage, ModuleDependency, ModuleGraph, ModuleIdentifier, NormalInitFragment, RuntimeGlobals, RuntimeSpec, Template, TemplateContext, TemplateReplaceSource, UsageState, @@ -843,7 +843,6 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { ) { let TemplateContext { compilation, - module, runtime, concatenation_scope, .. @@ -861,103 +860,10 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { return; } - let module = module_graph - .module_by_identifier(&module.identifier()) - .expect("should have module graph module"); - - let import_var = compilation.get_import_var(&self.id); - let is_new_treeshaking = compilation.options.is_new_tree_shaking(); - - let mut used_exports = if is_new_treeshaking { - let exports_info_id = module_graph.get_exports_info(&module.identifier()).id; - let res = self - .ids - .iter() - .filter_map(|(local, _)| { - exports_info_id - .get_used_name(&module_graph, *runtime, UsedName::Str(local.clone())) - .map(|item| match item { - UsedName::Str(str) => (local.clone(), vec![str]), - UsedName::Vec(strs) => (local.clone(), strs), - }) - }) - .collect::>(); - Some(res) - } else if compilation.options.builtins.tree_shaking.is_true() { - Some( - module_graph - .get_exports_info(&module.identifier()) - .old_get_used_exports() - .into_iter() - .map(|item| (item.clone(), vec![item])) - .collect::>(), - ) - } else { - None - }; - - if is_new_treeshaking { - // dbg!(&mode, self.request()); - if !matches!(mode.ty, ExportModeType::Unused | ExportModeType::EmptyStar) { - harmony_import_dependency_apply(self, self.source_order, code_generatable_context); - self.add_export_fragments(code_generatable_context, mode); - } - return; - } - - let mut exports = vec![]; - for id in &self.ids { - if let Some(used_exports) = used_exports.as_mut() { - let Some(item) = used_exports.remove(&id.0) else { - continue; - }; - // in webpack, id.0 is local binding and it doesn't always equal to used name, because it - // maybe mangled - let key = if is_new_treeshaking { - item[0].clone() - } else { - id.0.clone() - }; - // __webpack_require__.d({ - // 'key' / *key maybe mangled**/: ${export_expr} /**value*/ - // }) - exports.push(( - key, - Atom::from(export_from_import( - code_generatable_context, - true, - &self.request, - &import_var, - id.1.clone().map(|i| vec![i]).unwrap_or_default(), - &self.id, - false, - false, - )), - )); - } else { - exports.push(( - id.0.clone(), - Atom::from(export_from_import( - code_generatable_context, - true, - &self.request, - &import_var, - id.1.clone().map(|i| vec![i]).unwrap_or_default(), - &self.id, - false, - false, - )), - )); - } - } - - if !exports.is_empty() { - code_generatable_context - .init_fragments - .push(Box::new(HarmonyExportInitFragment::new( - module.get_exports_argument(), - exports, - ))); + // dbg!(&mode, self.request()); + if !matches!(mode.ty, ExportModeType::Unused | ExportModeType::EmptyStar) { + harmony_import_dependency_apply(self, self.source_order, code_generatable_context); + self.add_export_fragments(code_generatable_context, mode); } } diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs index 6d496b6f18e..571b4e2d7f5 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs @@ -87,7 +87,7 @@ impl DependencyTemplate for HarmonyExportSpecifierDependency { .module_by_identifier(&module.identifier()) .expect("should have module graph module"); - let used_name = if compilation.options.is_new_tree_shaking() { + let used_name = { let exports_info_id = module_graph.get_exports_info(&module.identifier()).id; let used_name = exports_info_id.get_used_name(&module_graph, *runtime, UsedName::Str(self.name.clone())); @@ -99,14 +99,6 @@ impl DependencyTemplate for HarmonyExportSpecifierDependency { vec[0].clone() } }) - } else if compilation.options.builtins.tree_shaking.is_true() { - module_graph - .get_exports_info(&module.identifier()) - .old_get_used_exports() - .contains(&self.name) - .then(|| self.name.clone()) - } else { - Some(self.name.clone()) }; if let Some(used_name) = used_name { init_fragments.push(Box::new(HarmonyExportInitFragment::new( diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs index 342873ec4a1..c83f1574a2e 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs @@ -7,8 +7,7 @@ use rspack_core::{ AwaitDependenciesInitFragment, ConditionalInitFragment, ConnectionState, Dependency, DependencyCategory, DependencyCondition, DependencyId, DependencyTemplate, DependencyType, ErrorSpan, ExtendedReferencedExport, InitFragmentExt, InitFragmentKey, InitFragmentStage, - ModuleDependency, ModuleIdentifier, NormalInitFragment, RuntimeCondition, RuntimeGlobals, - TemplateContext, TemplateReplaceSource, + ModuleDependency, ModuleIdentifier, RuntimeCondition, TemplateContext, TemplateReplaceSource, }; use rspack_core::{ModuleGraph, RuntimeSpec}; use rustc_hash::{FxHashMap, FxHashSet as HashSet}; @@ -97,23 +96,11 @@ pub fn harmony_import_dependency_apply( } = code_generatable_context; // Only available when module factorization is successful. let module_graph = compilation.get_module_graph(); - let ref_mgm = module_graph.module_graph_module_by_dependency_id(module_dependency.id()); - let is_target_active = if compilation.options.is_new_tree_shaking() { - let connection = module_graph.connection_by_dependency(module_dependency.id()); - if let Some(con) = connection { - Some(con.is_target_active(&module_graph, *runtime)) - } else { - Some(true) - } - } else if let Some(ref_mgm) = ref_mgm { - Some( - compilation - .include_module_ids - .contains(&ref_mgm.module_identifier), - ) + let connection = module_graph.connection_by_dependency(module_dependency.id()); + let is_target_active = if let Some(con) = connection { + Some(con.is_target_active(&module_graph, *runtime)) } else { - // This represents if module does not exist. - None + Some(true) }; // Bailout only if the module does exist and not active. if is_target_active.is_some_and(|x| !x) { @@ -139,7 +126,6 @@ pub fn harmony_import_dependency_apply( init_fragments, compilation, module, - runtime_requirements, .. } = code_generatable_context; let ref_module = module_graph.module_identifier_by_dependency_id(module_dependency.id()); @@ -211,31 +197,6 @@ pub fn harmony_import_dependency_apply( runtime_condition, ))); } - - let is_new_tree_shaking = compilation.options.is_new_tree_shaking(); - if module_dependency.is_export_all() == Some(true) && !is_new_tree_shaking { - runtime_requirements.insert(RuntimeGlobals::EXPORT_STAR); - runtime_requirements.insert(RuntimeGlobals::REQUIRE); - let exports_argument = module_graph - .module_by_identifier(&module.identifier()) - .expect("should have mgm") - .get_exports_argument(); - init_fragments.push(Box::new(NormalInitFragment::new( - format!( - "{}.{}({import_var}, {exports_argument});\n", - RuntimeGlobals::REQUIRE, - RuntimeGlobals::EXPORT_STAR, - ), - if is_async_module { - InitFragmentStage::StageAsyncHarmonyImports - } else { - InitFragmentStage::StageHarmonyImports - }, - source_order, - InitFragmentKey::HarmonyExportStar(key.to_string()), - None, - ))); - } } impl Dependency for HarmonyImportSideEffectDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs index 7b8c2c87dd4..22635a11bdd 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs @@ -1,18 +1,15 @@ use rspack_core::{ create_exports_object_referenced, export_from_import, get_dependency_used_by_exports_condition, - get_exports_type, tree_shaking::symbol::DEFAULT_JS_WORD, AsContextDependency, Compilation, - ConnectionState, Dependency, DependencyCategory, DependencyCondition, DependencyId, - DependencyTemplate, DependencyType, ExportsType, ExtendedReferencedExport, ModuleDependency, - ModuleGraph, ModuleGraphModule, ModuleIdentifier, ReferencedExport, RuntimeSpec, TemplateContext, - TemplateReplaceSource, UsedByExports, + get_exports_type, AsContextDependency, ConnectionState, Dependency, DependencyCategory, + DependencyCondition, DependencyId, DependencyTemplate, DependencyType, ExportsType, + ExtendedReferencedExport, ModuleDependency, ModuleGraph, ModuleIdentifier, ReferencedExport, + RuntimeSpec, TemplateContext, TemplateReplaceSource, UsedByExports, }; use rspack_core::{property_access, ModuleReferenceOptions}; use rustc_hash::FxHashSet as HashSet; use swc_core::{common::Span, ecma::atoms::Atom}; -use super::{ - create_resource_identifier_for_esm_dependency, harmony_import_dependency_apply, Specifier, -}; +use super::{create_resource_identifier_for_esm_dependency, harmony_import_dependency_apply}; #[derive(Debug, Clone)] pub struct HarmonyImportSpecifierDependency { @@ -25,7 +22,6 @@ pub struct HarmonyImportSpecifierDependency { ids: Vec, pub(crate) call: bool, direct_import: bool, - specifier: Specifier, used_by_exports: Option, pub namespace_object_as_context: bool, referenced_properties_in_destructuring: Option>, @@ -44,7 +40,6 @@ impl HarmonyImportSpecifierDependency { ids: Vec, call: bool, direct_import: bool, - specifier: Specifier, referenced_properties_in_destructuring: Option>, span_for_on_usage_search: Span, ) -> Self { @@ -59,7 +54,6 @@ impl HarmonyImportSpecifierDependency { ids, call, direct_import, - specifier, used_by_exports: None, namespace_object_as_context: false, referenced_properties_in_destructuring, @@ -68,53 +62,6 @@ impl HarmonyImportSpecifierDependency { } } - // TODO move export_info - pub fn check_used(&self, reference_mgm: &ModuleGraphModule, compilation: &Compilation) -> bool { - if compilation.options.builtins.tree_shaking.is_false() - || compilation - .bailout_module_identifiers - .contains_key(&reference_mgm.module_identifier) - { - return true; - } - if !compilation - .include_module_ids - .contains(&reference_mgm.module_identifier) - { - return false; - } - - if !reference_mgm.module_type.is_js_like() { - return true; - } - let module_graph = compilation.get_module_graph(); - let related_symbol = module_graph - .get_parent_module(&self.id) - .and_then(|parent_module| compilation.optimize_analyze_result_map().get(parent_module)) - .and_then(|analyze_res| { - analyze_res - .harmony_import_specifier_dependency_alias_map - .get(&self.span_for_on_usage_search) - }); - if let Some(related_symbol) = related_symbol - && !compilation.used_symbol_ref.contains(related_symbol) - { - return false; - } - - match &self.specifier { - Specifier::Namespace(_) => true, - Specifier::Default(_) => module_graph - .get_exports_info(&reference_mgm.module_identifier) - .old_get_used_exports() - .contains(&DEFAULT_JS_WORD), - Specifier::Named(local, imported) => module_graph - .get_exports_info(&reference_mgm.module_identifier) - .old_get_used_exports() - .contains(imported.as_ref().unwrap_or(local)), - } - } - pub fn get_referenced_exports_in_destructuring( &self, ids: Option<&Vec>, @@ -156,22 +103,18 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { let module_graph = compilation.get_module_graph(); // Only available when module factorization is successful. let reference_mgm = module_graph.module_graph_module_by_dependency_id(&self.id); - let is_new_treeshaking = compilation.options.is_new_tree_shaking(); - if is_new_treeshaking { - let connection = module_graph.connection_by_dependency(&self.id); - let is_target_active = if let Some(con) = connection { - con.is_target_active(&module_graph, *runtime) - } else { - true - }; - - if !is_target_active { - return; - } + let connection = module_graph.connection_by_dependency(&self.id); + let is_target_active = if let Some(con) = connection { + con.is_target_active(&module_graph, *runtime) + } else { + true }; - let used = - matches!(reference_mgm, Some(reference_mgm) if self.check_used(reference_mgm, compilation)); + if !is_target_active { + return; + } + + let used = reference_mgm.is_some(); if reference_mgm.is_some() && !used { // TODO do this by PureExpressionDependency. let value = format!("/* \"{}\" unused */null", self.request); @@ -223,9 +166,7 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { ) } } else { - if is_new_treeshaking { - harmony_import_dependency_apply(self, self.source_order, code_generatable_context); - } + harmony_import_dependency_apply(self, self.source_order, code_generatable_context); export_from_import( code_generatable_context, true, diff --git a/crates/rspack_plugin_javascript/src/dependency/export_info_api_dep.rs b/crates/rspack_plugin_javascript/src/dependency/export_info_api_dep.rs index 0be9c20b1cb..63463d65bfd 100644 --- a/crates/rspack_plugin_javascript/src/dependency/export_info_api_dep.rs +++ b/crates/rspack_plugin_javascript/src/dependency/export_info_api_dep.rs @@ -62,17 +62,11 @@ impl ExportInfoApiDependency { let id = module.identifier(); let mgm = module_graph.module_graph_module_by_identifier(&id)?; let exports_info = module_graph.get_exports_info_by_id(&mgm.exports); - let info_id = exports_info.exports.get(export_name)?; - let export_info = module_graph.try_get_export_info_by_id(info_id)?; - if compilation.options.is_new_tree_shaking() { - Some(exports_info.get_used( - rspack_core::UsedName::Str(export_name.clone()), - *runtime, - &module_graph, - )) - } else { - Some(export_info.usage_state) - } + Some(exports_info.get_used( + rspack_core::UsedName::Str(export_name.clone()), + *runtime, + &module_graph, + )) } _ => { // TODO: support other prop diff --git a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs index b49a806401f..7168c3b9ed2 100644 --- a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs @@ -5,8 +5,6 @@ use rspack_core::rspack_sources::{ BoxSource, MapOptions, OriginalSource, RawSource, ReplaceSource, Source, SourceExt, SourceMap, SourceMapSource, SourceMapSourceOptions, }; -use rspack_core::tree_shaking::analyzer::OptimizeAnalyzer; -use rspack_core::tree_shaking::js_module::JsModule; use rspack_core::tree_shaking::visitor::OptimizeAnalyzeResult; use rspack_core::{ render_init_fragments, AsyncDependenciesBlockIdentifier, BuildMetaExportsType, ChunkGraph, @@ -215,26 +213,9 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { }; diagnostics.append(&mut warning_diagnostics); let mut side_effects_bailout = None; - let analyze_result = if compiler_options.builtins.tree_shaking.enable() { - let mut all_dependencies = dependencies.clone(); - for mut block in blocks.clone() { - all_dependencies.extend(block.take_dependencies()); - } - JsModule::new( - &ast, - &worker_syntax_list, - &all_dependencies, - module_identifier, - compiler_options, - ) - .analyze() - } else { - OptimizeAnalyzeResult::default() - }; + let analyze_result = OptimizeAnalyzeResult::default(); - if compiler_options.is_new_tree_shaking() - && compiler_options.optimization.side_effects.is_true() - { + if compiler_options.optimization.side_effects.is_true() { ast.transform(|program, context| { let unresolved_ctxt = SyntaxContext::empty().apply_mark(context.unresolved_mark); let mut visitor = SideEffectsFlagPluginVisitor::new( @@ -254,28 +235,27 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { }); } - let inner_graph = - if compiler_options.is_new_tree_shaking() && compiler_options.optimization.inner_graph { - ast.transform(|program, context| { - let unresolved_ctxt = SyntaxContext::empty().apply_mark(context.unresolved_mark); - let top_level_ctxt = SyntaxContext::empty().apply_mark(context.top_level_mark); - let mut plugin = InnerGraphPlugin::new( - &mut dependencies, - unresolved_ctxt, - top_level_ctxt, - &mut usage_span_record, - &import_map, - module_identifier, - program.comments.take(), - ); - plugin.enable(); - program.visit_with(&mut plugin); - program.comments = plugin.comments.take(); - Some(plugin) - }) - } else { - None - }; + let inner_graph = if compiler_options.optimization.inner_graph { + ast.transform(|program, context| { + let unresolved_ctxt = SyntaxContext::empty().apply_mark(context.unresolved_mark); + let top_level_ctxt = SyntaxContext::empty().apply_mark(context.top_level_mark); + let mut plugin = InnerGraphPlugin::new( + &mut dependencies, + unresolved_ctxt, + top_level_ctxt, + &mut usage_span_record, + &import_map, + module_identifier, + program.comments.take(), + ); + plugin.enable(); + program.visit_with(&mut plugin); + program.comments = plugin.comments.take(); + Some(plugin) + }) + } else { + None + }; let source = if let Some(map) = output.map { SourceMapSource::new(SourceMapSourceOptions { diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/harmony_import_dependency_parser_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/harmony_import_dependency_parser_plugin.rs index dcced6a0d0c..3800afc470b 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/harmony_import_dependency_parser_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/harmony_import_dependency_parser_plugin.rs @@ -172,7 +172,6 @@ impl JavascriptParserPlugin for HarmonyImportDependencyParserPlugin { reference.names.clone().map(|f| vec![f]).unwrap_or_default(), false, false, - reference.specifier.clone(), None, ident.span, ))); @@ -193,7 +192,6 @@ impl JavascriptParserPlugin for HarmonyImportDependencyParserPlugin { reference.names.clone().map(|f| vec![f]).unwrap_or_default(), parser.enter_callee && !parser.enter_new_expr, true, // x() - reference.specifier.clone(), parser.properties_in_destructuring.remove(&ident.sym), ident.span, ))); @@ -248,7 +246,6 @@ impl JavascriptParserPlugin for HarmonyImportDependencyParserPlugin { ids, true, direct_import, - reference.specifier.clone(), None, callee.span(), ))); @@ -295,7 +292,6 @@ impl JavascriptParserPlugin for HarmonyImportDependencyParserPlugin { ids, parser.enter_callee && !parser.enter_new_expr, !parser.enter_callee, // x.xx() - reference.specifier.clone(), None, member_expr.span, ))); @@ -371,7 +367,6 @@ impl JavascriptParserPlugin for HarmonyImportDependencyParserPlugin { ids, parser.enter_callee && !parser.enter_new_expr, !parser.enter_callee, // x.xx() - reference.specifier.clone(), None, opt_chain_expr.span, ))); diff --git a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs index 9f4fc0095f4..08104c640c8 100644 --- a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs @@ -525,7 +525,6 @@ async fn nmf_module( if let Some(has_side_effects) = create_data.side_effects { module.set_factory_meta(FactoryMeta { side_effect_free: Some(!has_side_effects), - side_effect_free_old: None, }); return Ok(()); } @@ -542,7 +541,6 @@ async fn nmf_module( let has_side_effects = get_side_effects_from_package_json(side_effects, relative_path); module.set_factory_meta(FactoryMeta { side_effect_free: Some(!has_side_effects), - side_effect_free_old: None, }); Ok(()) } diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index 043778d2db0..9e6617eb477 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -16,13 +16,8 @@ pub fn render_chunk_modules( ordered_modules: Vec<&BoxModule>, all_strict: bool, ) -> Result> { - let include_module_ids = &compilation.include_module_ids; - let mut module_code_array = ordered_modules .par_iter() - .filter(|module| { - compilation.options.is_new_tree_shaking() || include_module_ids.contains(&module.identifier()) - }) .filter_map(|module| { render_module(compilation, chunk_ukey, module, all_strict, true) .transpose() diff --git a/crates/rspack_plugin_library/src/assign_library_plugin.rs b/crates/rspack_plugin_library/src/assign_library_plugin.rs index f67a9a60c21..9b4b3ee1667 100644 --- a/crates/rspack_plugin_library/src/assign_library_plugin.rs +++ b/crates/rspack_plugin_library/src/assign_library_plugin.rs @@ -3,7 +3,6 @@ use std::sync::Arc; use once_cell::sync::Lazy; use regex::Regex; -use rspack_core::tree_shaking::webpack_ext::ExportInfoExt; use rspack_core::{ get_entry_runtime, property_access, ApplyContext, BoxModule, ChunkUkey, CodeGenerationDataTopLevelDeclarations, CompilationFinishModules, CompilationParams, @@ -205,18 +204,6 @@ impl JavascriptModulesPluginPlugin for AssignLibraryJavascriptModulesPluginPlugi .unwrap_or_default(); if matches!(self.options.unnamed, Unnamed::Static) { let export_target = access_with_init(&full_name_resolved, self.options.prefix.len(), true); - if let Some(analyze_results) = args - .compilation - .optimize_analyze_result_map() - .get(&args.module) - { - for info in analyze_results.ordered_exports() { - let name_access = property_access(&vec![info.name], 0); - source.add(RawSource::from(format!( - "{export_target}{name_access} = __webpack_exports__{export_access}{name_access};\n", - ))); - } - } source.add(RawSource::from(format!( "Object.defineProperty({export_target}, '__esModule', {{ value: true }});\n", ))); diff --git a/crates/rspack_plugin_library/src/module_library_plugin.rs b/crates/rspack_plugin_library/src/module_library_plugin.rs index 3eb54068a52..429354d68e4 100644 --- a/crates/rspack_plugin_library/src/module_library_plugin.rs +++ b/crates/rspack_plugin_library/src/module_library_plugin.rs @@ -55,37 +55,20 @@ impl JavascriptModulesPluginPlugin for ModuleLibraryJavascriptModulesPluginPlugi let module_graph = args.compilation.get_module_graph(); source.add(args.source.clone()); let mut exports = vec![]; - if args.compilation.options.is_new_tree_shaking() { - let exports_info = module_graph.get_exports_info(&args.module); - for id in exports_info.get_ordered_exports() { - let info = id.get_export_info(&module_graph); - let chunk = args.compilation.chunk_by_ukey.expect_get(args.chunk); - let info_name = info.name.as_ref().expect("should have name"); - let used_name = info - .get_used_name(info.name.as_ref(), Some(&chunk.runtime)) - .expect("name can't be empty"); - let var_name = format!("__webpack_exports__{}", to_identifier(info_name)); - source.add(RawSource::from(format!( - "var {var_name} = __webpack_exports__{};\n", - property_access(&vec![used_name], 0) - ))); - exports.push(format!("{var_name} as {}", info_name)); - } - } else if let Some(analyze_results) = args - .compilation - .optimize_analyze_result_map() - .get(&args.module) - { - use rspack_core::tree_shaking::webpack_ext::ExportInfoExt; - for info in analyze_results.ordered_exports() { - let name = to_identifier(info.name.as_ref()); - let var_name = format!("__webpack_exports__{}", name); - source.add(RawSource::from(format!( - "var {var_name} = __webpack_exports__{};\n", - property_access(&vec![&info.name], 0) - ))); - exports.push(format!("{var_name} as {}", info.name)); - } + let exports_info = module_graph.get_exports_info(&args.module); + for id in exports_info.get_ordered_exports() { + let info = id.get_export_info(&module_graph); + let chunk = args.compilation.chunk_by_ukey.expect_get(args.chunk); + let info_name = info.name.as_ref().expect("should have name"); + let used_name = info + .get_used_name(info.name.as_ref(), Some(&chunk.runtime)) + .expect("name can't be empty"); + let var_name = format!("__webpack_exports__{}", to_identifier(info_name)); + source.add(RawSource::from(format!( + "var {var_name} = __webpack_exports__{};\n", + property_access(&vec![used_name], 0) + ))); + exports.push(format!("{var_name} as {}", info_name)); } if !exports.is_empty() { source.add(RawSource::from(format!( diff --git a/diffcases/arco-pro/rspack.config.js b/diffcases/arco-pro/rspack.config.js index 69bf74c4610..79f51553e91 100644 --- a/diffcases/arco-pro/rspack.config.js +++ b/diffcases/arco-pro/rspack.config.js @@ -127,10 +127,7 @@ const config = { debug: false }, experiments: { - css: true, - rspackFuture: { - newTreeshaking: true - } + css: true } }; module.exports = config; diff --git a/packages/rspack-cli/src/rspack-cli.ts b/packages/rspack-cli/src/rspack-cli.ts index a07b2423e43..d63050beadc 100644 --- a/packages/rspack-cli/src/rspack-cli.ts +++ b/packages/rspack-cli/src/rspack-cli.ts @@ -176,7 +176,6 @@ export class RspackCLI { if (typeof item.devtool === "undefined") { item.devtool = isBuild ? "source-map" : "cheap-module-source-map"; } - item.builtins = item.builtins || {}; if (isServe) { let installed = (item.plugins ||= []).find( item => item instanceof rspackCore.ProgressPlugin diff --git a/packages/rspack-test-tools/src/case/builtin.ts b/packages/rspack-test-tools/src/case/builtin.ts index 75e401a23d4..2bc25d5b0f4 100644 --- a/packages/rspack-test-tools/src/case/builtin.ts +++ b/packages/rspack-test-tools/src/case/builtin.ts @@ -29,8 +29,7 @@ const creator = new BasicCaseCreator({ name, snapshot: "output.snap.txt", snapshotFileFilter: filter, - compilerType: ECompilerType.Rspack, - configFiles: ["rspack.config.js", "webpack.config.js"] + compilerType: ECompilerType.Rspack }) ]; } diff --git a/packages/rspack-test-tools/src/processor/builtin.ts b/packages/rspack-test-tools/src/processor/builtin.ts index df5d59faacc..180d5bae570 100644 --- a/packages/rspack-test-tools/src/processor/builtin.ts +++ b/packages/rspack-test-tools/src/processor/builtin.ts @@ -125,10 +125,7 @@ export class BuiltinProcessor< }, devtool: false, context: context.getSource(), - plugins: [], - builtins: { - treeShaking: false - } + plugins: [] } as TCompilerOptions; if (compilerType === ECompilerType.Rspack) { @@ -144,23 +141,21 @@ export class BuiltinProcessor< } // TODO: remove builtin compatible code - const defineOptions = (rspackDefaultOptions.builtins as any)?.define; + const defineOptions = (rspackDefaultOptions as any).builtins?.define; if (defineOptions) { rspackDefaultOptions.plugins!.push( new rspack.DefinePlugin(defineOptions) ); - delete (rspackDefaultOptions.builtins as any)?.define; } - const provideOptions = (rspackDefaultOptions.builtins as any)?.provide; + const provideOptions = (rspackDefaultOptions as any).builtins?.provide; if (provideOptions) { rspackDefaultOptions.plugins!.push( new rspack.ProvidePlugin(provideOptions) ); - delete (rspackDefaultOptions.builtins as any)?.provide; } - const htmlOptions = (rspackDefaultOptions.builtins as any)?.html; + const htmlOptions = (rspackDefaultOptions as any).builtins?.html; if (htmlOptions) { if (Array.isArray(htmlOptions)) { for (let item of htmlOptions) { @@ -173,9 +168,10 @@ export class BuiltinProcessor< new rspack.HtmlRspackPlugin(htmlOptions) ); } - delete (rspackDefaultOptions.builtins as any)?.html; } + delete (rspackDefaultOptions as any).builtins; + defaultOptions = rspackDefaultOptions as TCompilerOptions; } diff --git a/packages/rspack-test-tools/src/processor/config.ts b/packages/rspack-test-tools/src/processor/config.ts index 65246a6cc00..5ba476ee4ef 100644 --- a/packages/rspack-test-tools/src/processor/config.ts +++ b/packages/rspack-test-tools/src/processor/config.ts @@ -58,11 +58,6 @@ export class ConfigProcessor< }, optimization: { minimize: false - }, - experiments: { - rspackFuture: { - newTreeshaking: true - } } } as TCompilerOptions; } diff --git a/packages/rspack-test-tools/src/processor/hook.ts b/packages/rspack-test-tools/src/processor/hook.ts index 89bc63faf2d..d20a8f7751c 100644 --- a/packages/rspack-test-tools/src/processor/hook.ts +++ b/packages/rspack-test-tools/src/processor/hook.ts @@ -231,11 +231,6 @@ export class HookTaskProcessor< }, optimization: { minimize: false - }, - experiments: { - rspackFuture: { - newTreeshaking: true - } } } as TCompilerOptions; } diff --git a/packages/rspack-test-tools/src/processor/normal.ts b/packages/rspack-test-tools/src/processor/normal.ts index 4907f3c3023..07c47411b7a 100644 --- a/packages/rspack-test-tools/src/processor/normal.ts +++ b/packages/rspack-test-tools/src/processor/normal.ts @@ -164,10 +164,6 @@ export class NormalProcessor< // backCompat: false, // CHANGE: Rspack enables `css` by default. // Turning off here to fallback to webpack's default css processing logic. - // @ts-ignore - rspackFuture: testConfig?.experiments?.rspackFuture ?? { - newTreeshaking: true - }, css: false, ...(compilerOptions?.module ? { outputModule: true } : {}) } diff --git a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap index 230873cec70..ba305b4025a 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap @@ -3,7 +3,6 @@ exports[`Base Defaults Snapshot should have the correct base config 1`] = ` Object { "bail": false, - "builtins": Object {}, "cache": false, "context": "", "dependencies": undefined, @@ -25,7 +24,6 @@ Object { "force": false, "version": "$version$", }, - "newTreeshaking": true, }, "topLevelAwait": true, }, diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/rspack.config.js b/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/rspack.config.js index f444b396b3f..6b5be13068f 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/rspack.config.js +++ b/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/rspack.config.js @@ -9,9 +9,4 @@ module.exports = { providedExports: true, usedExports: "global" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/rspack.config.js b/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/rspack.config.js index ad002b1c905..daadb1dfdbe 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/rspack.config.js +++ b/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/rspack.config.js @@ -6,11 +6,6 @@ module.exports = { providedExports: true, usedExports: "global" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, builtins: { define: { "process.env.NODE_ENV": "'development'" diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/rspack.config.js b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/rspack.config.js index d18c7209930..3b80891a561 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/rspack.config.js +++ b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/rspack.config.js @@ -5,9 +5,4 @@ module.exports = { providedExports: true, usedExports: "global" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/rspack.config.js b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/rspack.config.js index 03fdcecf0da..01fc1c08f41 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/rspack.config.js +++ b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/rspack.config.js @@ -13,9 +13,4 @@ module.exports = { providedExports: true, usedExports: "global" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/intersection/rspack.config.js b/packages/rspack-test-tools/tests/builtinCases/samples/intersection/rspack.config.js index 03fdcecf0da..01fc1c08f41 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/intersection/rspack.config.js +++ b/packages/rspack-test-tools/tests/builtinCases/samples/intersection/rspack.config.js @@ -13,9 +13,4 @@ module.exports = { providedExports: true, usedExports: "global" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/rspack.config.js b/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/rspack.config.js index 6ec267bb47c..63132b9f45c 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/rspack.config.js +++ b/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/rspack.config.js @@ -5,11 +5,6 @@ module.exports = { providedExports: true, usedExports: "global" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, builtins: { define: { "process.env.NODE_ENV": "'development'" diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/rspack.config.js b/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/rspack.config.js index 73d4d79d6a1..fdb615ccefc 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/rspack.config.js +++ b/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/rspack.config.js @@ -10,9 +10,4 @@ module.exports = { providedExports: true, usedExports: "global" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/self-import/rspack.config.js b/packages/rspack-test-tools/tests/builtinCases/samples/self-import/rspack.config.js index d18c7209930..3b80891a561 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/self-import/rspack.config.js +++ b/packages/rspack-test-tools/tests/builtinCases/samples/self-import/rspack.config.js @@ -5,9 +5,4 @@ module.exports = { providedExports: true, usedExports: "global" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/simple/rspack.config.js b/packages/rspack-test-tools/tests/builtinCases/samples/simple/rspack.config.js index d18c7209930..3b80891a561 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/simple/rspack.config.js +++ b/packages/rspack-test-tools/tests/builtinCases/samples/simple/rspack.config.js @@ -5,9 +5,4 @@ module.exports = { providedExports: true, usedExports: "global" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/builtinCases/swc-loader/esm/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/swc-loader/esm/__snapshots__/output.snap.txt index e25e531c103..6c4dea69444 100644 --- a/packages/rspack-test-tools/tests/builtinCases/swc-loader/esm/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/swc-loader/esm/__snapshots__/output.snap.txt @@ -14,5 +14,5 @@ var __webpack_exports__ = (__webpack_exec__("./index.js")); } ]); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsid2VicGFjazovL19fcnNwYWNrX3Rlc3RfXy8uL2luZGV4LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImNsYXNzIGEge31cblxuZnVuY3Rpb24gQSgpIHtcblx0cmV0dXJuIDxkaXY+MTIzPC9kaXY+O1xufVxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsTUFBTTtBQUFHO0FBRVQsU0FBUztJQUNSLE9BQU8sV0FBUCxHQUFPLG9CQUFDLGFBQUk7QUFDYiJ9 +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsid2VicGFjazovL19fcnNwYWNrX3Rlc3RfXy8uL2luZGV4LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImNsYXNzIGEge31cblxuZnVuY3Rpb24gQSgpIHtcblx0cmV0dXJuIDxkaXY+MTIzPC9kaXY+O1xufVxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsTUFBTTtBQUFHO0FBRVQsU0FBUztJQUNSLHFCQUFPLG9CQUFDLGFBQUk7QUFDYiJ9 ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/builtinCases/swc-loader/ts/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/swc-loader/ts/__snapshots__/output.snap.txt index 0b9e402d94f..5e5cf5e54f3 100644 --- a/packages/rspack-test-tools/tests/builtinCases/swc-loader/ts/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/swc-loader/ts/__snapshots__/output.snap.txt @@ -17,5 +17,5 @@ var __webpack_exports__ = (__webpack_exec__("./index.tsx")); } ]); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsid2VicGFjazovL19fcnNwYWNrX3Rlc3RfXy8uL2luZGV4LnRzeCJdLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBhIHt9XG5cbmZ1bmN0aW9uIEEoKXtcblx0cmV0dXJuIDxkaXY+MTIzPC9kaXY+XG59XG5cbmludGVyZmFjZSBBIHtcblx0YTogbnVtYmVyXG59XG5jb25zdCBiOiBBID0ge2E6MTIzfVxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsTUFBTTtBQUFHO0FBRVQsU0FBUztJQUNSLE9BQU8sV0FBUCxHQUFPLG9CQUFDLGFBQUk7QUFDYjtBQUtBLE1BQU0sSUFBTztJQUFDLEdBQUU7QUFBRyxDQUFDIn0= +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsid2VicGFjazovL19fcnNwYWNrX3Rlc3RfXy8uL2luZGV4LnRzeCJdLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBhIHt9XG5cbmZ1bmN0aW9uIEEoKXtcblx0cmV0dXJuIDxkaXY+MTIzPC9kaXY+XG59XG5cbmludGVyZmFjZSBBIHtcblx0YTogbnVtYmVyXG59XG5jb25zdCBiOiBBID0ge2E6MTIzfVxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsTUFBTTtBQUFHO0FBRVQsU0FBUztJQUNSLHFCQUFPLG9CQUFDLGFBQUk7QUFDYjtBQUtBLE1BQU0sSUFBTztJQUFDLEdBQUU7QUFBRyxDQUFDIn0= ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/builtins/code-generation-keep-comments/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtins/code-generation-keep-comments/rspack.config.js index 1fca9290032..b9ea673a817 100644 --- a/packages/rspack-test-tools/tests/configCases/builtins/code-generation-keep-comments/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtins/code-generation-keep-comments/rspack.config.js @@ -1,8 +1,3 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { - builtins: { - codeGeneration: { - keepComments: true - } - } }; diff --git a/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_export_destructring/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_export_destructring/rspack.config.js index c7f473bbd8b..d17adc44a86 100644 --- a/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_export_destructring/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_export_destructring/rspack.config.js @@ -1,6 +1,4 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { - builtins: { - treeShaking: true - } + }; diff --git a/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_when_commjs_not_export/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_when_commjs_not_export/rspack.config.js index c7f473bbd8b..d17adc44a86 100644 --- a/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_when_commjs_not_export/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_when_commjs_not_export/rspack.config.js @@ -1,6 +1,4 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { - builtins: { - treeShaking: true - } + }; diff --git a/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_when_src_format_is_umd/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_when_src_format_is_umd/rspack.config.js index c7f473bbd8b..d17adc44a86 100644 --- a/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_when_src_format_is_umd/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtins/should_not_warn_when_src_format_is_umd/rspack.config.js @@ -1,6 +1,4 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { - builtins: { - treeShaking: true - } + }; diff --git a/packages/rspack-test-tools/tests/configCases/chunk-loading/issue-4800/rspack.config.js b/packages/rspack-test-tools/tests/configCases/chunk-loading/issue-4800/rspack.config.js index c7f473bbd8b..d17adc44a86 100644 --- a/packages/rspack-test-tools/tests/configCases/chunk-loading/issue-4800/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/chunk-loading/issue-4800/rspack.config.js @@ -1,6 +1,4 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { - builtins: { - treeShaking: true - } + }; diff --git a/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/rspack.config.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/rspack.config.js index 0f19b6ee5bf..1389495d466 100644 --- a/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/rspack.config.js @@ -4,9 +4,4 @@ module.exports = { optimization: { minimize: false }, - experiments: { - rspackFuture: { - newTreeshaking: false - } - } }; diff --git a/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/rspack.config.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/rspack.config.js index 135fc9a1cef..3c832bf08b5 100644 --- a/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/rspack.config.js @@ -4,9 +4,4 @@ module.exports = { optimization: { sideEffects: true }, - experiments: { - rspackFuture: { - newTreeshaking: false - } - } }; diff --git a/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-unused/rspack.config.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-unused/rspack.config.js index 59d80c49123..475dcf83789 100644 --- a/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-unused/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-unused/rspack.config.js @@ -3,9 +3,4 @@ module.exports = { optimization: { usedExports: true }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/rspack-issue-5282/rspack.config.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/rspack-issue-5282/rspack.config.js index d1bc56a6c14..12ac1451916 100644 --- a/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/rspack-issue-5282/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/rspack-issue-5282/rspack.config.js @@ -5,9 +5,4 @@ module.exports = { minimize: false, moduleIds: "named" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/rspack.config.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/rspack.config.js index 8f49975e162..aef175a0a16 100644 --- a/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/rspack.config.js @@ -25,8 +25,5 @@ module.exports = { }, experiments: { css: true, - rspackFuture: { - newTreeshaking: true - } } }; diff --git a/packages/rspack-test-tools/tests/configCases/container-1-5/0-container-full/rspack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-5/0-container-full/rspack.config.js index 7372dc3d8e3..d9b53b743c4 100644 --- a/packages/rspack-test-tools/tests/configCases/container-1-5/0-container-full/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/container-1-5/0-container-full/rspack.config.js @@ -39,9 +39,6 @@ module.exports = [ { experiments: { outputModule: true, - rspackFuture: { - newTreeshaking: true - } }, output: { filename: "module/[name].mjs", diff --git a/packages/rspack-test-tools/tests/configCases/container-1-5/1-container-full/rspack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-5/1-container-full/rspack.config.js index 22b505992e9..92c4e3d6c07 100644 --- a/packages/rspack-test-tools/tests/configCases/container-1-5/1-container-full/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/container-1-5/1-container-full/rspack.config.js @@ -45,9 +45,6 @@ module.exports = [ ...common, experiments: { outputModule: true, - rspackFuture: { - newTreeshaking: true - } }, output: { filename: "module/[name].mjs", diff --git a/packages/rspack-test-tools/tests/configCases/container-1-5/2-container-full/rspack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-5/2-container-full/rspack.config.js index c966fa0d487..64320205be1 100644 --- a/packages/rspack-test-tools/tests/configCases/container-1-5/2-container-full/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/container-1-5/2-container-full/rspack.config.js @@ -5,11 +5,6 @@ module.exports = { output: { uniqueName: "2-container-full" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, plugins: [ new ModuleFederationPlugin({ name: "main", diff --git a/packages/rspack-test-tools/tests/configCases/container-1-5/2-transitive-overriding/rspack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-5/2-transitive-overriding/rspack.config.js index 40b84065619..797457edab9 100644 --- a/packages/rspack-test-tools/tests/configCases/container-1-5/2-transitive-overriding/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/container-1-5/2-transitive-overriding/rspack.config.js @@ -9,11 +9,6 @@ module.exports = { output: { uniqueName: "2-transitive-overriding" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, plugins: [ new ModuleFederationPlugin({ remoteType: "commonjs-module", diff --git a/packages/rspack-test-tools/tests/configCases/container-1-5/module-federation-with-shareScope/rspack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-5/module-federation-with-shareScope/rspack.config.js index ceb31cc529b..03532c0c962 100644 --- a/packages/rspack-test-tools/tests/configCases/container-1-5/module-federation-with-shareScope/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/container-1-5/module-federation-with-shareScope/rspack.config.js @@ -7,11 +7,6 @@ const common = { optimization: { runtimeChunk: "single" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; /** @type {ConstructorParameters[0]} */ diff --git a/packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/rspack.config.js b/packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/rspack.config.js index c7f473bbd8b..d17adc44a86 100644 --- a/packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/rspack.config.js @@ -1,6 +1,4 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { - builtins: { - treeShaking: true - } + }; diff --git a/packages/rspack-test-tools/tests/configCases/library/duplicate-module-library/rspack.config.js b/packages/rspack-test-tools/tests/configCases/library/duplicate-module-library/rspack.config.js index c4e556fe896..ed7c741cd37 100644 --- a/packages/rspack-test-tools/tests/configCases/library/duplicate-module-library/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/duplicate-module-library/rspack.config.js @@ -9,8 +9,5 @@ module.exports = { target: ["es2022"], experiments: { outputModule: true, - rspackFuture: { - newTreeshaking: true, - } } }; diff --git a/packages/rspack-test-tools/tests/configCases/library/esm-external/rspack.config.js b/packages/rspack-test-tools/tests/configCases/library/esm-external/rspack.config.js index de66ba757b2..78d1c9cb55a 100644 --- a/packages/rspack-test-tools/tests/configCases/library/esm-external/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/esm-external/rspack.config.js @@ -9,9 +9,6 @@ module.exports = { }, experiments: { outputModule: true, - rspackFuture: { - newTreeshaking: false - } }, target: "node" }; diff --git a/packages/rspack-test-tools/tests/configCases/loader-import-module/codegen-cache/rspack.config.js b/packages/rspack-test-tools/tests/configCases/loader-import-module/codegen-cache/rspack.config.js index c6bc180587d..84f16143dbc 100644 --- a/packages/rspack-test-tools/tests/configCases/loader-import-module/codegen-cache/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/loader-import-module/codegen-cache/rspack.config.js @@ -13,9 +13,4 @@ module.exports = { } ] }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/configCases/loader-import-module/css/rspack.config.js b/packages/rspack-test-tools/tests/configCases/loader-import-module/css/rspack.config.js index 2c03d3fc7a4..f739cce6ed3 100644 --- a/packages/rspack-test-tools/tests/configCases/loader-import-module/css/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/loader-import-module/css/rspack.config.js @@ -69,9 +69,4 @@ module.exports = { } }) ], - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/configCases/loader-import-module/recursive-import-module/rspack.config.js b/packages/rspack-test-tools/tests/configCases/loader-import-module/recursive-import-module/rspack.config.js index 21f535d2e88..a9d72a0e013 100644 --- a/packages/rspack-test-tools/tests/configCases/loader-import-module/recursive-import-module/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/loader-import-module/recursive-import-module/rspack.config.js @@ -12,9 +12,4 @@ module.exports = { } ] }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/rspack.config.js b/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/rspack.config.js index f72d66c7196..aa2784e4a1a 100644 --- a/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/rspack.config.js @@ -2,9 +2,6 @@ module.exports = { experiments: { css: true, - rspackFuture: { - newTreeshaking: true - } }, optimization: { minimize: false, diff --git a/packages/rspack-test-tools/tests/configCases/module/rspack-issue-5548/rspack.config.js b/packages/rspack-test-tools/tests/configCases/module/rspack-issue-5548/rspack.config.js index ff458f509d1..7191b2f7fa0 100644 --- a/packages/rspack-test-tools/tests/configCases/module/rspack-issue-5548/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/module/rspack-issue-5548/rspack.config.js @@ -11,9 +11,4 @@ module.exports = { } } }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/configCases/output-module/rspack-issue-4784/rspack.config.js b/packages/rspack-test-tools/tests/configCases/output-module/rspack-issue-4784/rspack.config.js index 2d0a70d6208..ebc3aba4449 100644 --- a/packages/rspack-test-tools/tests/configCases/output-module/rspack-issue-4784/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/output-module/rspack-issue-4784/rspack.config.js @@ -21,9 +21,6 @@ module.exports = { }, experiments: { outputModule: true, - rspackFuture: { - newTreeshaking: true - } }, plugins: [ { diff --git a/packages/rspack-test-tools/tests/configCases/schemes/data-imports/rspack.config.js b/packages/rspack-test-tools/tests/configCases/schemes/data-imports/rspack.config.js index d81d7cfa8c5..8b6fed45b25 100644 --- a/packages/rspack-test-tools/tests/configCases/schemes/data-imports/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/schemes/data-imports/rspack.config.js @@ -48,8 +48,5 @@ module.exports = { plugins: [new Plugin()], experiments: { css: true, - rspackFuture: { - newTreeshaking: true - } } }; diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/asset-is-dep-of-css-source/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/asset-is-dep-of-css-source/rspack.config.js index 07954d6bfbd..ae46fdfad6d 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/asset-is-dep-of-css-source/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/asset-is-dep-of-css-source/rspack.config.js @@ -9,9 +9,7 @@ module.exports = { } ] }, - builtins: { - treeShaking: true - }, + optimization: { sideEffects: true }, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/assets1/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/assets1/rspack.config.js index 07954d6bfbd..f8aef392c51 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/assets1/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/assets1/rspack.config.js @@ -9,9 +9,6 @@ module.exports = { } ] }, - builtins: { - treeShaking: true - }, optimization: { sideEffects: true }, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/commonjs-reexport-interop/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/commonjs-reexport-interop/rspack.config.js index 5a59ca6bfab..c50fa74a332 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/commonjs-reexport-interop/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/commonjs-reexport-interop/rspack.config.js @@ -2,11 +2,6 @@ module.exports = { mode: "production", context: __dirname, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, optimization: { moduleIds: "named", minimize: false diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/export-default-alias/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/export-default-alias/rspack.config.js index 818dc5b6245..fe5f552aed1 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/export-default-alias/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/export-default-alias/rspack.config.js @@ -2,14 +2,7 @@ module.exports = { mode: "production", context: __dirname, - builtins: { - treeShaking: true - }, - experiments: { - rspackFuture: { - newTreeshaking: false - } - }, + optimization: { moduleIds: "named", minimize: false diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/export-star-of-external-module/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/export-star-of-external-module/rspack.config.js index 7caf80a5dd1..d3975a4e718 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/export-star-of-external-module/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/export-star-of-external-module/rspack.config.js @@ -4,9 +4,7 @@ module.exports = { module: { rules: [] }, - builtins: { - treeShaking: true - }, + optimization: { sideEffects: true }, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/import-by-name-json/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/import-by-name-json/rspack.config.js index 7ec51493cb0..f6d87d5ba56 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/import-by-name-json/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/import-by-name-json/rspack.config.js @@ -5,11 +5,6 @@ module.exports = { module: { rules: [] }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, optimization: { moduleIds: "named", minimize: false diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/inner-graph-static-block/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/inner-graph-static-block/rspack.config.js index 5a59ca6bfab..c50fa74a332 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/inner-graph-static-block/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/inner-graph-static-block/rspack.config.js @@ -2,11 +2,6 @@ module.exports = { mode: "production", context: __dirname, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, optimization: { moduleIds: "named", minimize: false diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/issue-5782/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/issue-5782/rspack.config.js index 177c33b34b1..36dc53961bd 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/issue-5782/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/issue-5782/rspack.config.js @@ -1,11 +1,6 @@ /**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, optimization: { innerGraph: true, sideEffects: true, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/json-empty-array/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/json-empty-array/rspack.config.js index 177c33b34b1..36dc53961bd 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/json-empty-array/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/json-empty-array/rspack.config.js @@ -1,11 +1,6 @@ /**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, optimization: { innerGraph: true, sideEffects: true, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/member-expr-computed-prop/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/member-expr-computed-prop/rspack.config.js index 37a6000837d..0d36cfdf170 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/member-expr-computed-prop/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/member-expr-computed-prop/rspack.config.js @@ -1,9 +1,7 @@ /**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, - builtins: { - treeShaking: true - }, + optimization: { sideEffects: true } diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-export-side-effect/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-export-side-effect/rspack.config.js index 154b79c4b06..066c90544e5 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-export-side-effect/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-export-side-effect/rspack.config.js @@ -3,9 +3,7 @@ const { DefinePlugin } = require("@rspack/core"); /**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, - builtins: { - treeShaking: true - }, + optimization: { sideEffects: true }, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-import-side-effect/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-import-side-effect/rspack.config.js index 154b79c4b06..066c90544e5 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-import-side-effect/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-import-side-effect/rspack.config.js @@ -3,9 +3,7 @@ const { DefinePlugin } = require("@rspack/core"); /**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, - builtins: { - treeShaking: true - }, + optimization: { sideEffects: true }, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/new-url/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/new-url/rspack.config.js index b3ad2a660c8..24731b581db 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/new-url/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/new-url/rspack.config.js @@ -10,9 +10,7 @@ module.exports = { } ] }, - builtins: { - treeShaking: true - }, + optimization: { sideEffects: true }, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-rule/rspack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-rule/rspack.config.js index 0189ba7dcca..66f80cf395e 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-rule/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-rule/rspack.config.js @@ -9,9 +9,7 @@ module.exports = { } ] }, - builtins: { - treeShaking: true - }, + optimization: { sideEffects: true }, diff --git a/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-global/rspack.config.js b/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-global/rspack.config.js index ce8bb78da91..ec04ac38f3d 100644 --- a/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-global/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-global/rspack.config.js @@ -10,11 +10,6 @@ module.exports = { output: { filename: "[name].js" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, optimization: { minimize: false, mangleExports: false, diff --git a/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-true/rspack.config.js b/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-true/rspack.config.js index 15715a13834..b266bafb2de 100644 --- a/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-true/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-true/rspack.config.js @@ -10,11 +10,6 @@ module.exports = { output: { filename: "[name].js" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, optimization: { minimize: false, mangleExports: false, diff --git a/packages/rspack-test-tools/tests/diagnosticsCases/factorize/export_star_error/rspack.config.js b/packages/rspack-test-tools/tests/diagnosticsCases/factorize/export_star_error/rspack.config.js index 9afeeb96dc6..55000d58af8 100644 --- a/packages/rspack-test-tools/tests/diagnosticsCases/factorize/export_star_error/rspack.config.js +++ b/packages/rspack-test-tools/tests/diagnosticsCases/factorize/export_star_error/rspack.config.js @@ -6,9 +6,4 @@ module.exports = { "process.env.NODE_ENV": "development" } }, - experiments: { - rspackFuture: { - newTreeshaking: false - } - } } diff --git a/packages/rspack-test-tools/tests/diagnosticsCases/factorize/export_star_error/test.filter.js b/packages/rspack-test-tools/tests/diagnosticsCases/factorize/export_star_error/test.filter.js new file mode 100644 index 00000000000..fed7caa7b92 --- /dev/null +++ b/packages/rspack-test-tools/tests/diagnosticsCases/factorize/export_star_error/test.filter.js @@ -0,0 +1 @@ +module.exports = () => false diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js index 3f62d546e1b..5eaa0ecee18 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js @@ -19,7 +19,7 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "message": " ⚠ Error: test push\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", + "message": " ⚠ Error: test push\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:464:41\\n │ at packages/rspack/dist/Compiler.js:531:65\\n", }, Object { "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js index 64eff878a9a..aeaa7ba5530 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js @@ -23,7 +23,7 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "message": " ⚠ Error: test unshift\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", + "message": " ⚠ Error: test unshift\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:464:41\\n │ at packages/rspack/dist/Compiler.js:531:65\\n", }, ], } diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js index 01291fdd17a..7c2ebd15c5d 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js @@ -19,7 +19,7 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", + "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:464:41\\n │ at packages/rspack/dist/Compiler.js:531:65\\n", }, ], } diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js index 3599acd99b1..ade5cd70265 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js @@ -19,7 +19,7 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", + "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:464:41\\n │ at packages/rspack/dist/Compiler.js:531:65\\n", }, Object { "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/rspack.config.js b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/rspack.config.js index 27be45b9eca..8608c932d81 100644 --- a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/rspack.config.js +++ b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/rspack.config.js @@ -1,8 +1,5 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { experiments: { - rspackFuture: { - newTreeshaking: true - } } }; diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/rspack.config.js b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/rspack.config.js index 9001a77b3ef..c033aa3fe3a 100644 --- a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/rspack.config.js +++ b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/rspack.config.js @@ -12,9 +12,4 @@ module.exports = { optimization: { runtimeChunk: "single" }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/module-esm-export/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/module-esm-export/rspack.config.js index 6a3e426b8e2..1389495d466 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/module-esm-export/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/module-esm-export/rspack.config.js @@ -4,9 +4,4 @@ module.exports = { optimization: { minimize: false }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/module-esm-import/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/module-esm-import/rspack.config.js index 6a3e426b8e2..1389495d466 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/module-esm-import/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/module-esm-import/rspack.config.js @@ -4,9 +4,4 @@ module.exports = { optimization: { minimize: false }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/module-esmodule-usage/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/module-esmodule-usage/rspack.config.js index f36c6b5cca4..c603ff53fa8 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/module-esmodule-usage/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/module-esmodule-usage/rspack.config.js @@ -5,9 +5,4 @@ module.exports = { minimize: false, usedExports: true }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/exports.js b/packages/rspack-test-tools/tests/statsAPICases/exports.js index 67fa66072e5..2f199c5c064 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/exports.js +++ b/packages/rspack-test-tools/tests/statsAPICases/exports.js @@ -11,11 +11,6 @@ module.exports = { usedExports: true, providedExports: true }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - } }; }, async check(stats) { diff --git a/packages/rspack-test-tools/tests/statsOutputCases/css-concat-error/rspack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/css-concat-error/rspack.config.js index 0888f842630..a77211a4b70 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/css-concat-error/rspack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/css-concat-error/rspack.config.js @@ -8,8 +8,5 @@ module.exports = { }, experiments: { css: true, - rspackFuture: { - newTreeshaking: true - } } }; diff --git a/packages/rspack-test-tools/tests/statsOutputCases/runtime-specific-exports/rspack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/runtime-specific-exports/rspack.config.js index 5d2038e880e..2fab730bd02 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/runtime-specific-exports/rspack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/runtime-specific-exports/rspack.config.js @@ -6,11 +6,6 @@ module.exports = { usedExports: true, providedExports: true, }, - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, stats: { usedExports: true, providedExports: true, diff --git a/packages/rspack-test-tools/tests/statsOutputCases/side-effects-bailouts/rspack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/side-effects-bailouts/rspack.config.js index 5d57285812a..5abacc8b356 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/side-effects-bailouts/rspack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/side-effects-bailouts/rspack.config.js @@ -4,10 +4,5 @@ module.exports = { main: "./index.js" }, mode: 'production', - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, stats: "verbose" }; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/rspack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/rspack.config.js index bdc9c8aceeb..3cffa219218 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/rspack.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/rspack.config.js @@ -1,7 +1,8 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { optimization: { - sideEffects: true + sideEffects: true, + usedExports: true, }, builtins: { define: { diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/rspack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/rspack.config.js index c7f473bbd8b..d17adc44a86 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/rspack.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/rspack.config.js @@ -1,6 +1,4 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { - builtins: { - treeShaking: true - } + }; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt index 94354c32e0f..1d288c0a89e 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt @@ -17,13 +17,13 @@ var c = "c"; __webpack_require__.d(__webpack_exports__, { x: function() { return x; } }); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/tracker.js"); +/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/tracker.js"); var x = "x"; var y = "y"; -(0, _tracker__WEBPACK_IMPORTED_MODULE_1__.track)("b.js"); +(0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("b.js"); }), "../node_modules/pmodule/c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.d(__webpack_exports__, { @@ -36,11 +36,11 @@ var z = "z"; (0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("c.js"); }), "../node_modules/pmodule/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../node_modules/pmodule/tracker.js"); +/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/tracker.js"); -(0, _tracker__WEBPACK_IMPORTED_MODULE_2__.track)("index.js"); +(0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("index.js"); /* harmony default export */ __webpack_exports__["default"] = ("def"); }), "../node_modules/pmodule/tracker.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt index f1f79cfd9bc..b74021564b6 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt @@ -5,13 +5,13 @@ __webpack_require__.d(__webpack_exports__, { x: function() { return x; } }); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/tracker.js"); +/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/tracker.js"); var x = "x"; var y = "y"; -(0, _tracker__WEBPACK_IMPORTED_MODULE_1__.track)("b.js"); +(0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("b.js"); }), "../node_modules/pmodule/c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.d(__webpack_exports__, { @@ -24,11 +24,11 @@ var z = "z"; (0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("c.js"); }), "../node_modules/pmodule/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../node_modules/pmodule/tracker.js"); +/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/tracker.js"); -(0, _tracker__WEBPACK_IMPORTED_MODULE_2__.track)("index.js"); +(0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("index.js"); /* harmony default export */ __webpack_exports__["default"] = ("def"); }), "../node_modules/pmodule/tracker.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index 0dc58da4c60..1b233ed5664 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -798,18 +798,6 @@ export type BaseUri = z.infer; // @public (undocumented) const baseUri: z.ZodString; -// @public (undocumented) -export type Builtins = z.infer; - -// @public (undocumented) -const builtins: z.ZodType; - -// @public (undocumented) -interface Builtins_2 { - // (undocumented) - treeShaking?: boolean | "module"; -} - // @public (undocumented) type CacheHookMap = Map[]>; @@ -2862,7 +2850,6 @@ const experiments: z.ZodObject<{ css: z.ZodOptional; futureDefaults: z.ZodOptional; rspackFuture: z.ZodOptional; bundlerInfo: z.ZodOptional; force: z.ZodOptional, "many">]>>; @@ -2874,13 +2861,11 @@ const experiments: z.ZodObject<{ force?: boolean | "version"[] | undefined; }>>; }, "strict", z.ZodTypeAny, { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; } | undefined; }, { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; @@ -2898,7 +2883,6 @@ const experiments: z.ZodObject<{ css?: boolean | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; @@ -2916,7 +2900,6 @@ const experiments: z.ZodObject<{ css?: boolean | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; @@ -8080,7 +8063,6 @@ declare namespace rspackExports { Profile, Bail, Performance_2 as Performance, - Builtins, rspackOptions, RspackOptions, Configuration @@ -8092,7 +8074,6 @@ export type RspackFutureOptions = z.infer; // @public (undocumented) const rspackFutureOptions: z.ZodObject<{ - newTreeshaking: z.ZodOptional; bundlerInfo: z.ZodOptional; force: z.ZodOptional, "many">]>>; @@ -8104,13 +8085,11 @@ const rspackFutureOptions: z.ZodObject<{ force?: boolean | "version"[] | undefined; }>>; }, "strict", z.ZodTypeAny, { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; } | undefined; }, { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; @@ -8788,7 +8767,6 @@ export const rspackOptions: z.ZodObject<{ css: z.ZodOptional; futureDefaults: z.ZodOptional; rspackFuture: z.ZodOptional; bundlerInfo: z.ZodOptional; force: z.ZodOptional, "many">]>>; @@ -8800,13 +8778,11 @@ export const rspackOptions: z.ZodObject<{ force?: boolean | "version"[] | undefined; }>>; }, "strict", z.ZodTypeAny, { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; } | undefined; }, { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; @@ -8824,7 +8800,6 @@ export const rspackOptions: z.ZodObject<{ css?: boolean | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; @@ -8842,7 +8817,6 @@ export const rspackOptions: z.ZodObject<{ css?: boolean | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; @@ -9419,7 +9393,6 @@ export const rspackOptions: z.ZodObject<{ resolveLoader: z.ZodOptional>; plugins: z.ZodOptional, z.ZodType, z.ZodUnion<[z.ZodLiteral, z.ZodLiteral<0>, z.ZodLiteral<"">, z.ZodNull, z.ZodUndefined]>]>, "many">>; devServer: z.ZodOptional>; - builtins: z.ZodOptional>; module: z.ZodOptional, z.ZodType]>, z.ZodUnion<[z.ZodLiteral, z.ZodLiteral<0>, z.ZodLiteral<"">, z.ZodNull, z.ZodUndefined]>]>, "many">>; rules: z.ZodOptional, z.ZodType]>, z.ZodUnion<[z.ZodLiteral, z.ZodLiteral<0>, z.ZodLiteral<"">, z.ZodNull, z.ZodUndefined]>]>, "many">>; @@ -10248,7 +10221,6 @@ export const rspackOptions: z.ZodObject<{ css?: boolean | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; @@ -10411,7 +10383,6 @@ export const rspackOptions: z.ZodObject<{ resolveLoader?: ResolveOptions | undefined; plugins?: (false | "" | 0 | RspackPluginInstance | RspackPluginFunction | null | undefined)[] | undefined; devServer?: DevServer | undefined; - builtins?: Builtins_2 | undefined; module?: { defaultRules?: (false | "" | 0 | "..." | RuleSetRule | null | undefined)[] | undefined; rules?: (false | "" | 0 | "..." | RuleSetRule | null | undefined)[] | undefined; @@ -10682,7 +10653,6 @@ export const rspackOptions: z.ZodObject<{ css?: boolean | undefined; futureDefaults?: boolean | undefined; rspackFuture?: { - newTreeshaking?: boolean | undefined; bundlerInfo?: { version?: string | undefined; force?: boolean | "version"[] | undefined; @@ -10845,7 +10815,6 @@ export const rspackOptions: z.ZodObject<{ resolveLoader?: ResolveOptions | undefined; plugins?: (false | "" | 0 | RspackPluginInstance | RspackPluginFunction | null | undefined)[] | undefined; devServer?: DevServer | undefined; - builtins?: Builtins_2 | undefined; module?: { defaultRules?: (false | "" | 0 | "..." | RuleSetRule | null | undefined)[] | undefined; rules?: (false | "" | 0 | "..." | RuleSetRule | null | undefined)[] | undefined; @@ -10967,8 +10936,6 @@ export interface RspackOptionsNormalized { // (undocumented) bail?: Bail; // (undocumented) - builtins: Builtins; - // (undocumented) cache?: CacheOptions; // (undocumented) context?: Context; diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index 406caffe34a..2d8d6fdbf96 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -33,10 +33,7 @@ import Cache = require("./lib/Cache"); import CacheFacade = require("./lib/CacheFacade"); import { Source } from "webpack-sources"; -import { - deprecated_resolveBuiltins, - JsLoaderRspackPlugin -} from "./builtin-plugin"; +import { JsLoaderRspackPlugin } from "./builtin-plugin"; import { canInherentFromParent } from "./builtin-plugin/base"; import { Chunk } from "./Chunk"; import { applyRspackOptionsDefaults } from "./config/defaults"; @@ -522,9 +519,7 @@ class Compiler { output: { ...this.options.output, ...outputOptions - }, - // TODO: check why we need to have builtins otherwise this.#instance will fail to initialize Rspack - builtins: this.options.builtins + } }; applyRspackOptionsDefaults(options); const childCompiler = new Compiler(this.context, options); @@ -735,11 +730,6 @@ class Compiler { } const options = this.options; - // TODO: remove this when drop support for builtins options - options.builtins = deprecated_resolveBuiltins( - options.builtins, - options - ) as any; const rawOptions = getRawOptions(options, this); const instanceBinding: typeof binding = require("@rspack/binding"); diff --git a/packages/rspack/src/builtin-plugin/css-extract/loader.ts b/packages/rspack/src/builtin-plugin/css-extract/loader.ts index 19788187b0d..08daf5bcd03 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/loader.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/loader.ts @@ -89,19 +89,6 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) { return; } - if ( - this._compiler && - this._compiler.options && - this._compiler.options.experiments && - this._compiler.options.experiments.rspackFuture && - this._compiler.options.experiments.rspackFuture.newTreeshaking === false - ) { - this.emitError( - new Error("Cannot use CssExtractRspackPlugin without newTreeshaking") - ); - return; - } - const options = this.getOptions(schema) as CssExtractRspackLoaderOptions; const emit = typeof options.emit !== "undefined" ? options.emit : true; const callback = this.async(); diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index 6a83ea83b03..3141716a674 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -125,9 +125,7 @@ export const getRawOptions = ( // SAFETY: applied default value in `applyRspackOptionsDefaults`. profile: options.profile!, // SAFETY: applied default value in `applyRspackOptionsDefaults`. - bail: options.bail!, - // TODO: remove this - builtins: options.builtins as any + bail: options.bail! }; }; @@ -825,12 +823,9 @@ function getRawExperiments( } function getRawRspackFutureOptions( - future: RspackFutureOptions + _future: RspackFutureOptions ): RawRspackFuture { - assert(!isNil(future.newTreeshaking)); - return { - newTreeshaking: future.newTreeshaking - }; + return {}; } function getRawNode(node: Node): RawOptions["node"] { diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 048e08049fc..7b9751dae4c 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -186,7 +186,6 @@ const applyExperimentsDefaults = ( D(experiments, "rspackFuture", {}); if (typeof experiments.rspackFuture === "object") { - D(experiments.rspackFuture, "newTreeshaking", true); D(experiments.rspackFuture, "bundlerInfo", {}); if (typeof experiments.rspackFuture.bundlerInfo === "object") { D( diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index 55fce188809..883080a35fe 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -14,7 +14,6 @@ import type { Compilation } from "../Compilation"; import type { AssetModuleFilename, Bail, - Builtins, CacheOptions, ChunkFilename, ChunkLoading, @@ -302,10 +301,7 @@ export const getNormalizedRspackOptions = ( watchOptions: cloneObject(config.watchOptions), devServer: config.devServer, profile: config.profile, - bail: config.bail, - builtins: nestedConfig(config.builtins, builtins => ({ - ...builtins - })) + bail: config.bail }; }; @@ -548,5 +544,4 @@ export interface RspackOptionsNormalized { performance?: Performance; profile?: Profile; bail?: Bail; - builtins: Builtins; } diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index ea0f348a2b2..bca2bd4b852 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -1184,7 +1184,6 @@ export type Optimization = z.infer; //#region Experiments const rspackFutureOptions = z.strictObject({ - newTreeshaking: z.boolean().optional(), bundlerInfo: z .strictObject({ version: z.string().optional(), @@ -1281,11 +1280,6 @@ const performance = z export type Performance = z.infer; //#endregion -//#region Builtins (deprecated) -const builtins = z.custom(); -export type Builtins = z.infer; -//#endregion - export const rspackOptions = z.strictObject({ name: name.optional(), dependencies: dependencies.optional(), @@ -1312,7 +1306,6 @@ export const rspackOptions = z.strictObject({ resolveLoader: resolve.optional(), plugins: plugins.optional(), devServer: devServer.optional(), - builtins: builtins.optional(), module: moduleOptions.optional(), profile: profile.optional(), bail: bail.optional(), diff --git a/packages/rspack/src/rspackOptionsApply.ts b/packages/rspack/src/rspackOptionsApply.ts index 54f94d3162d..eb958b03443 100644 --- a/packages/rspack/src/rspackOptionsApply.ts +++ b/packages/rspack/src/rspackOptionsApply.ts @@ -234,28 +234,26 @@ export class RspackOptionsApply { new MergeDuplicateChunksPlugin().apply(compiler); } - if (options.experiments.rspackFuture?.newTreeshaking) { - if (options.optimization.sideEffects) { - new SideEffectsFlagPlugin(/* options.optimization.sideEffects === true */).apply( - compiler - ); - } - if (options.optimization.providedExports) { - new FlagDependencyExportsPlugin().apply(compiler); - } - if (options.optimization.usedExports) { - new FlagDependencyUsagePlugin( - options.optimization.usedExports === "global" - ).apply(compiler); - } - if (options.optimization.concatenateModules) { - new ModuleConcatenationPlugin().apply(compiler); - } - if (options.optimization.mangleExports) { - new MangleExportsPlugin( - options.optimization.mangleExports !== "size" - ).apply(compiler); - } + if (options.optimization.sideEffects) { + new SideEffectsFlagPlugin(/* options.optimization.sideEffects === true */).apply( + compiler + ); + } + if (options.optimization.providedExports) { + new FlagDependencyExportsPlugin().apply(compiler); + } + if (options.optimization.usedExports) { + new FlagDependencyUsagePlugin( + options.optimization.usedExports === "global" + ).apply(compiler); + } + if (options.optimization.concatenateModules) { + new ModuleConcatenationPlugin().apply(compiler); + } + if (options.optimization.mangleExports) { + new MangleExportsPlugin( + options.optimization.mangleExports !== "size" + ).apply(compiler); } if (options.experiments.lazyCompilation) { diff --git a/plugin-test/css-extract/TestCache.test.js b/plugin-test/css-extract/TestCache.test.js index 5e7e748894f..7b21db162d4 100644 --- a/plugin-test/css-extract/TestCache.test.js +++ b/plugin-test/css-extract/TestCache.test.js @@ -33,9 +33,6 @@ describe("TestCache", () => { }, experiments: { css: false, - rspackFuture: { - newTreeshaking: true - } } }); @@ -80,7 +77,7 @@ describe("TestCache", () => { output: { path: outputPath }, - experiments: { css: false, rspackFuture: { newTreeshaking: true } } + experiments: { css: false } }); await new Promise((resolve, reject) => { @@ -132,7 +129,7 @@ describe("TestCache", () => { output: { path: outputPath }, - experiments: { css: false, rspackFuture: { newTreeshaking: true } } + experiments: { css: false } }); await new Promise((resolve, reject) => { @@ -178,9 +175,6 @@ describe("TestCache", () => { }, experiments: { css: false, - rspackFuture: { - newTreeshaking: true - } } }); @@ -244,7 +238,6 @@ describe("TestCache", () => { }, experiments: { css: false, - rspackFuture: { newTreeshaking: true } } }); diff --git a/plugin-test/css-extract/TestCases.test.js b/plugin-test/css-extract/TestCases.test.js index ef48e0f041f..8eb704100de 100644 --- a/plugin-test/css-extract/TestCases.test.js +++ b/plugin-test/css-extract/TestCases.test.js @@ -142,9 +142,6 @@ describe("TestCases", () => { optimization: { chunkIds: "named", ...config.optimization }, experiments: { css: false, - rspackFuture: { - newTreeshaking: true - }, ...config.experiments } }; @@ -153,9 +150,6 @@ describe("TestCases", () => { ...config, experiments: { css: false, - rspackFuture: { - newTreeshaking: true - }, ...config.experiments } }; diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-2/rspack.config.js b/plugin-test/css-extract/cases/publicpath-absolute-url-2/rspack.config.js index e846829e8dc..fbea7f0d5e8 100644 --- a/plugin-test/css-extract/cases/publicpath-absolute-url-2/rspack.config.js +++ b/plugin-test/css-extract/cases/publicpath-absolute-url-2/rspack.config.js @@ -25,8 +25,5 @@ module.exports = { ], experiments: { css: false, - rspackFuture: { - newTreeshaking: true - } } }; diff --git a/plugin-test/css-extract/emitOption.test.js b/plugin-test/css-extract/emitOption.test.js index e836dad8103..04eb6019e38 100644 --- a/plugin-test/css-extract/emitOption.test.js +++ b/plugin-test/css-extract/emitOption.test.js @@ -207,9 +207,6 @@ describe("emit option", () => { ], experiments: { css: false, - rspackFuture: { - newTreeshaking: true - } } }; @@ -314,9 +311,6 @@ describe("emit option", () => { ], experiments: { css: false, - rspackFuture: { - newTreeshaking: true - } } }; @@ -435,9 +429,6 @@ describe("emit option", () => { ], experiments: { css: false, - rspackFuture: { - newTreeshaking: true - } } }; diff --git a/plugin-test/css-extract/helpers/getCompiler.js b/plugin-test/css-extract/helpers/getCompiler.js index 6baa868a560..4467b588919 100644 --- a/plugin-test/css-extract/helpers/getCompiler.js +++ b/plugin-test/css-extract/helpers/getCompiler.js @@ -48,9 +48,6 @@ module.exports = (fixture, loaderOptions = {}, config = {}) => { ], experiments: { css: false, - rspackFuture: { - newTreeshaking: true - } }, ...cnfg }; diff --git a/plugin-test/css-extract/ignoreOrderOption.test.js b/plugin-test/css-extract/ignoreOrderOption.test.js index 19e032abc48..0ff0e294930 100644 --- a/plugin-test/css-extract/ignoreOrderOption.test.js +++ b/plugin-test/css-extract/ignoreOrderOption.test.js @@ -21,9 +21,6 @@ describe("IgnoreOrder", () => { cache: false, experiments: { css: false, - rspackFuture: { - newTreeshaking: true - } } }); compiler.run((err1, stats) => { @@ -50,9 +47,6 @@ describe("IgnoreOrder", () => { cache: false, experiments: { css: false, - rspackFuture: { - newTreeshaking: true - } } }); compiler.run((err1, stats) => { diff --git a/webpack-test/ConfigTestCases.template.js b/webpack-test/ConfigTestCases.template.js index af692884c24..093229fb0c5 100644 --- a/webpack-test/ConfigTestCases.template.js +++ b/webpack-test/ConfigTestCases.template.js @@ -107,11 +107,6 @@ const describeCases = config => { if (!options.experiments) { options.experiments = {}; } - if (!options.experiments.rspackFuture) { - options.experiments.rspackFuture = { - newTreeshaking: true - }; - } // CHANGE: use rspack internal swc minimizer // if (options.optimization.minimizer === undefined) { // options.optimization.minimizer = [ diff --git a/webpack-test/TestCases.template.js b/webpack-test/TestCases.template.js index 0833fa8f8af..6f2ef3fe170 100644 --- a/webpack-test/TestCases.template.js +++ b/webpack-test/TestCases.template.js @@ -229,10 +229,6 @@ const describeCases = config => { // backCompat: false, // CHANGE: Rspack enables `css` by default. // Turning off here to fallback to webpack's default css processing logic. - - rspackFuture: testConfig?.experiments?.rspackFuture ?? { - newTreeshaking: true - }, css: false, ...(config.module ? { outputModule: true } : {}) }, diff --git a/webpack-test/cases/cjs-tree-shaking/cjs-to-esm/test.config.js b/webpack-test/cases/cjs-tree-shaking/cjs-to-esm/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/cjs-to-esm/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/cjs-to-esm/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/esModule-getter/test.config.js b/webpack-test/cases/cjs-tree-shaking/esModule-getter/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/esModule-getter/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/esModule-getter/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/esm-to-cjs/test.config.js b/webpack-test/cases/cjs-tree-shaking/esm-to-cjs/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/esm-to-cjs/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/esm-to-cjs/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/exports/test.config.js b/webpack-test/cases/cjs-tree-shaking/exports/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/exports/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/exports/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/importing/test.config.js b/webpack-test/cases/cjs-tree-shaking/importing/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/importing/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/importing/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/mjs/test.config.js b/webpack-test/cases/cjs-tree-shaking/mjs/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/mjs/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/mjs/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/namespace/test.config.js b/webpack-test/cases/cjs-tree-shaking/namespace/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/namespace/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/namespace/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/non-root-this/test.config.js b/webpack-test/cases/cjs-tree-shaking/non-root-this/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/non-root-this/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/non-root-this/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/object-define-property-replace/test.config.js b/webpack-test/cases/cjs-tree-shaking/object-define-property-replace/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/object-define-property-replace/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/object-define-property-replace/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/objects/test.config.js b/webpack-test/cases/cjs-tree-shaking/objects/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/objects/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/objects/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/parsing/test.config.js b/webpack-test/cases/cjs-tree-shaking/parsing/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/parsing/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/parsing/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/reexports/test.config.js b/webpack-test/cases/cjs-tree-shaking/reexports/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/reexports/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/reexports/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/transpiled/test.config.js b/webpack-test/cases/cjs-tree-shaking/transpiled/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/transpiled/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/transpiled/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/cjs-tree-shaking/weird-names/test.config.js b/webpack-test/cases/cjs-tree-shaking/weird-names/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/cjs-tree-shaking/weird-names/test.config.js +++ b/webpack-test/cases/cjs-tree-shaking/weird-names/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/circular/test.config.js b/webpack-test/cases/inner-graph/circular/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/inner-graph/circular/test.config.js +++ b/webpack-test/cases/inner-graph/circular/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/circular2/test.config.js b/webpack-test/cases/inner-graph/circular2/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/inner-graph/circular2/test.config.js +++ b/webpack-test/cases/inner-graph/circular2/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/class-dynamic-props/test.config.js b/webpack-test/cases/inner-graph/class-dynamic-props/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/inner-graph/class-dynamic-props/test.config.js +++ b/webpack-test/cases/inner-graph/class-dynamic-props/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/export-default-named/test.config.js b/webpack-test/cases/inner-graph/export-default-named/test.config.js index 87792b4d410..2079d4646c9 100644 --- a/webpack-test/cases/inner-graph/export-default-named/test.config.js +++ b/webpack-test/cases/inner-graph/export-default-named/test.config.js @@ -1,10 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { experiments: { - rspackFuture: { - newTreeshaking: true, - }, }, - + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/extend-class/test.config.js b/webpack-test/cases/inner-graph/extend-class/test.config.js index 87792b4d410..035834d4e37 100644 --- a/webpack-test/cases/inner-graph/extend-class/test.config.js +++ b/webpack-test/cases/inner-graph/extend-class/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/extend-class2/test.config.js b/webpack-test/cases/inner-graph/extend-class2/test.config.js index 87792b4d410..d171107f075 100644 --- a/webpack-test/cases/inner-graph/extend-class2/test.config.js +++ b/webpack-test/cases/inner-graph/extend-class2/test.config.js @@ -1,10 +1,4 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/no-side-effects/test.config.js b/webpack-test/cases/inner-graph/no-side-effects/test.config.js index 87792b4d410..d171107f075 100644 --- a/webpack-test/cases/inner-graph/no-side-effects/test.config.js +++ b/webpack-test/cases/inner-graph/no-side-effects/test.config.js @@ -1,10 +1,4 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/pure-in-removed/test.config.js b/webpack-test/cases/inner-graph/pure-in-removed/test.config.js index 87792b4d410..d171107f075 100644 --- a/webpack-test/cases/inner-graph/pure-in-removed/test.config.js +++ b/webpack-test/cases/inner-graph/pure-in-removed/test.config.js @@ -1,10 +1,4 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/reexport-namespace-and-default/test.config.js b/webpack-test/cases/inner-graph/reexport-namespace-and-default/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/inner-graph/reexport-namespace-and-default/test.config.js +++ b/webpack-test/cases/inner-graph/reexport-namespace-and-default/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/simple/test.config.js b/webpack-test/cases/inner-graph/simple/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/inner-graph/simple/test.config.js +++ b/webpack-test/cases/inner-graph/simple/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/static-of-class/test.config.js b/webpack-test/cases/inner-graph/static-of-class/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/inner-graph/static-of-class/test.config.js +++ b/webpack-test/cases/inner-graph/static-of-class/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/switch/test.config.js b/webpack-test/cases/inner-graph/switch/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/inner-graph/switch/test.config.js +++ b/webpack-test/cases/inner-graph/switch/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/inner-graph/try-globals/test.config.js b/webpack-test/cases/inner-graph/try-globals/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/inner-graph/try-globals/test.config.js +++ b/webpack-test/cases/inner-graph/try-globals/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/concat-star-import/test.config.js b/webpack-test/cases/optimize/concat-star-import/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/concat-star-import/test.config.js +++ b/webpack-test/cases/optimize/concat-star-import/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/many-exports-100/test.config.js b/webpack-test/cases/optimize/many-exports-100/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/many-exports-100/test.config.js +++ b/webpack-test/cases/optimize/many-exports-100/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/many-exports-120/test.config.js b/webpack-test/cases/optimize/many-exports-120/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/many-exports-120/test.config.js +++ b/webpack-test/cases/optimize/many-exports-120/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/many-exports-40/test.config.js b/webpack-test/cases/optimize/many-exports-40/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/many-exports-40/test.config.js +++ b/webpack-test/cases/optimize/many-exports-40/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/side-effects-all-chain-unused/test.config.js b/webpack-test/cases/optimize/side-effects-all-chain-unused/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/side-effects-all-chain-unused/test.config.js +++ b/webpack-test/cases/optimize/side-effects-all-chain-unused/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/side-effects-all-used/test.config.js b/webpack-test/cases/optimize/side-effects-all-used/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/side-effects-all-used/test.config.js +++ b/webpack-test/cases/optimize/side-effects-all-used/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/side-effects-immediate-unused/test.config.js b/webpack-test/cases/optimize/side-effects-immediate-unused/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/side-effects-immediate-unused/test.config.js +++ b/webpack-test/cases/optimize/side-effects-immediate-unused/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/side-effects-root-unused/test.config.js b/webpack-test/cases/optimize/side-effects-root-unused/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/side-effects-root-unused/test.config.js +++ b/webpack-test/cases/optimize/side-effects-root-unused/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/side-effects-scope-hoisting/test.config.js b/webpack-test/cases/optimize/side-effects-scope-hoisting/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/side-effects-scope-hoisting/test.config.js +++ b/webpack-test/cases/optimize/side-effects-scope-hoisting/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/side-effects-simple-unused/test.config.js b/webpack-test/cases/optimize/side-effects-simple-unused/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/side-effects-simple-unused/test.config.js +++ b/webpack-test/cases/optimize/side-effects-simple-unused/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/side-effects-transitive-unused/test.config.js b/webpack-test/cases/optimize/side-effects-transitive-unused/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/side-effects-transitive-unused/test.config.js +++ b/webpack-test/cases/optimize/side-effects-transitive-unused/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/tree-shaking-commonjs/test.config.js b/webpack-test/cases/optimize/tree-shaking-commonjs/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/tree-shaking-commonjs/test.config.js +++ b/webpack-test/cases/optimize/tree-shaking-commonjs/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/tree-shaking-star/test.config.js b/webpack-test/cases/optimize/tree-shaking-star/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/tree-shaking-star/test.config.js +++ b/webpack-test/cases/optimize/tree-shaking-star/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/optimize/tree-shaking-star2/test.config.js b/webpack-test/cases/optimize/tree-shaking-star2/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/optimize/tree-shaking-star2/test.config.js +++ b/webpack-test/cases/optimize/tree-shaking-star2/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/parsing/issue-7519/test.config.js b/webpack-test/cases/parsing/issue-7519/test.config.js index 71579e0938c..15c075be6b6 100644 --- a/webpack-test/cases/parsing/issue-7519/test.config.js +++ b/webpack-test/cases/parsing/issue-7519/test.config.js @@ -1,11 +1,6 @@ const rspack = require("@rspack/core"); /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, builtins: { treeShaking: false }, diff --git a/webpack-test/cases/scope-hoisting/async-keyword-5615/test.config.js b/webpack-test/cases/scope-hoisting/async-keyword-5615/test.config.js index 9366752fff7..bacea526938 100644 --- a/webpack-test/cases/scope-hoisting/async-keyword-5615/test.config.js +++ b/webpack-test/cases/scope-hoisting/async-keyword-5615/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/chained-reexport/test.config.js b/webpack-test/cases/scope-hoisting/chained-reexport/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/chained-reexport/test.config.js +++ b/webpack-test/cases/scope-hoisting/chained-reexport/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/circular-external/test.config.js b/webpack-test/cases/scope-hoisting/circular-external/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/circular-external/test.config.js +++ b/webpack-test/cases/scope-hoisting/circular-external/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/circular-namespace-object/test.config.js b/webpack-test/cases/scope-hoisting/circular-namespace-object/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/circular-namespace-object/test.config.js +++ b/webpack-test/cases/scope-hoisting/circular-namespace-object/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/delete-issue-10831/test.config.js b/webpack-test/cases/scope-hoisting/delete-issue-10831/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/delete-issue-10831/test.config.js +++ b/webpack-test/cases/scope-hoisting/delete-issue-10831/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/esModule/test.config.js b/webpack-test/cases/scope-hoisting/esModule/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/esModule/test.config.js +++ b/webpack-test/cases/scope-hoisting/esModule/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/export-namespace/test.config.js b/webpack-test/cases/scope-hoisting/export-namespace/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/export-namespace/test.config.js +++ b/webpack-test/cases/scope-hoisting/export-namespace/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/external-root/test.config.js b/webpack-test/cases/scope-hoisting/external-root/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/external-root/test.config.js +++ b/webpack-test/cases/scope-hoisting/external-root/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/import-order-11617/test.config.js b/webpack-test/cases/scope-hoisting/import-order-11617/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/import-order-11617/test.config.js +++ b/webpack-test/cases/scope-hoisting/import-order-11617/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/import-order/test.config.js b/webpack-test/cases/scope-hoisting/import-order/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/import-order/test.config.js +++ b/webpack-test/cases/scope-hoisting/import-order/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/indirect-reexport/test.config.js b/webpack-test/cases/scope-hoisting/indirect-reexport/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/indirect-reexport/test.config.js +++ b/webpack-test/cases/scope-hoisting/indirect-reexport/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/inside-class/test.config.js b/webpack-test/cases/scope-hoisting/inside-class/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/inside-class/test.config.js +++ b/webpack-test/cases/scope-hoisting/inside-class/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/intra-references/test.config.js b/webpack-test/cases/scope-hoisting/intra-references/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/intra-references/test.config.js +++ b/webpack-test/cases/scope-hoisting/intra-references/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-10308/test.config.js b/webpack-test/cases/scope-hoisting/issue-10308/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-10308/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-10308/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-10409/test.config.js b/webpack-test/cases/scope-hoisting/issue-10409/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-10409/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-10409/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-11840/test.config.js b/webpack-test/cases/scope-hoisting/issue-11840/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-11840/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-11840/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-11897/test.config.js b/webpack-test/cases/scope-hoisting/issue-11897/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-11897/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-11897/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-5020-minimal/test.config.js b/webpack-test/cases/scope-hoisting/issue-5020-minimal/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-5020-minimal/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-5020-minimal/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-5020/test.config.js b/webpack-test/cases/scope-hoisting/issue-5020/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-5020/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-5020/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-5096/test.config.js b/webpack-test/cases/scope-hoisting/issue-5096/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-5096/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-5096/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-5314/test.config.js b/webpack-test/cases/scope-hoisting/issue-5314/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-5314/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-5314/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-5443/test.config.js b/webpack-test/cases/scope-hoisting/issue-5443/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-5443/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-5443/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-5481/test.config.js b/webpack-test/cases/scope-hoisting/issue-5481/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-5481/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-5481/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-6407/test.config.js b/webpack-test/cases/scope-hoisting/issue-6407/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-6407/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-6407/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/issue-7930/test.config.js b/webpack-test/cases/scope-hoisting/issue-7930/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/issue-7930/test.config.js +++ b/webpack-test/cases/scope-hoisting/issue-7930/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/json-reexport-6700/test.config.js b/webpack-test/cases/scope-hoisting/json-reexport-6700/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/json-reexport-6700/test.config.js +++ b/webpack-test/cases/scope-hoisting/json-reexport-6700/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/name-conflicts/test.config.js b/webpack-test/cases/scope-hoisting/name-conflicts/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/name-conflicts/test.config.js +++ b/webpack-test/cases/scope-hoisting/name-conflicts/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/order-without-side-effects/test.config.js b/webpack-test/cases/scope-hoisting/order-without-side-effects/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/order-without-side-effects/test.config.js +++ b/webpack-test/cases/scope-hoisting/order-without-side-effects/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/orphan/test.config.js b/webpack-test/cases/scope-hoisting/orphan/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/orphan/test.config.js +++ b/webpack-test/cases/scope-hoisting/orphan/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/reexport-cjs/test.config.js b/webpack-test/cases/scope-hoisting/reexport-cjs/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/reexport-cjs/test.config.js +++ b/webpack-test/cases/scope-hoisting/reexport-cjs/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/reexport-exposed-cjs/test.config.js b/webpack-test/cases/scope-hoisting/reexport-exposed-cjs/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/reexport-exposed-cjs/test.config.js +++ b/webpack-test/cases/scope-hoisting/reexport-exposed-cjs/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/reexport-exposed-default-cjs/test.config.js b/webpack-test/cases/scope-hoisting/reexport-exposed-default-cjs/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/reexport-exposed-default-cjs/test.config.js +++ b/webpack-test/cases/scope-hoisting/reexport-exposed-default-cjs/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/reexport-exposed-harmony/test.config.js b/webpack-test/cases/scope-hoisting/reexport-exposed-harmony/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/reexport-exposed-harmony/test.config.js +++ b/webpack-test/cases/scope-hoisting/reexport-exposed-harmony/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/reexport-star-exposed-cjs/test.config.js b/webpack-test/cases/scope-hoisting/reexport-star-exposed-cjs/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/reexport-star-exposed-cjs/test.config.js +++ b/webpack-test/cases/scope-hoisting/reexport-star-exposed-cjs/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/reexport-star-external-cjs/test.config.js b/webpack-test/cases/scope-hoisting/reexport-star-external-cjs/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/reexport-star-external-cjs/test.config.js +++ b/webpack-test/cases/scope-hoisting/reexport-star-external-cjs/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/renaming-4967/test.config.js b/webpack-test/cases/scope-hoisting/renaming-4967/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/renaming-4967/test.config.js +++ b/webpack-test/cases/scope-hoisting/renaming-4967/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/renaming-shorthand-5027/test.config.js b/webpack-test/cases/scope-hoisting/renaming-shorthand-5027/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/renaming-shorthand-5027/test.config.js +++ b/webpack-test/cases/scope-hoisting/renaming-shorthand-5027/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/require-root-5604/test.config.js b/webpack-test/cases/scope-hoisting/require-root-5604/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/require-root-5604/test.config.js +++ b/webpack-test/cases/scope-hoisting/require-root-5604/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/side-effects-11662/test.config.js b/webpack-test/cases/scope-hoisting/side-effects-11662/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/side-effects-11662/test.config.js +++ b/webpack-test/cases/scope-hoisting/side-effects-11662/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/side-effects-11990-star/test.config.js b/webpack-test/cases/scope-hoisting/side-effects-11990-star/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/side-effects-11990-star/test.config.js +++ b/webpack-test/cases/scope-hoisting/side-effects-11990-star/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/side-effects-11990/test.config.js b/webpack-test/cases/scope-hoisting/side-effects-11990/test.config.js index 7b0d3da0136..539bc6b9361 100644 --- a/webpack-test/cases/scope-hoisting/side-effects-11990/test.config.js +++ b/webpack-test/cases/scope-hoisting/side-effects-11990/test.config.js @@ -1,10 +1,5 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/side-effects-9159/test.config.js b/webpack-test/cases/scope-hoisting/side-effects-9159/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/side-effects-9159/test.config.js +++ b/webpack-test/cases/scope-hoisting/side-effects-9159/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/simple/test.config.js b/webpack-test/cases/scope-hoisting/simple/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/simple/test.config.js +++ b/webpack-test/cases/scope-hoisting/simple/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/scope-hoisting/this-in-import/test.config.js b/webpack-test/cases/scope-hoisting/this-in-import/test.config.js index 7b0d3da0136..656d97578a5 100644 --- a/webpack-test/cases/scope-hoisting/this-in-import/test.config.js +++ b/webpack-test/cases/scope-hoisting/this-in-import/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, + optimization: { concatenateModules: true, }, diff --git a/webpack-test/cases/side-effects/dynamic-reexports/test.config.js b/webpack-test/cases/side-effects/dynamic-reexports/test.config.js index 9495bd4e339..1e98ef84280 100644 --- a/webpack-test/cases/side-effects/dynamic-reexports/test.config.js +++ b/webpack-test/cases/side-effects/dynamic-reexports/test.config.js @@ -1,11 +1,7 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + optimization: { sideEffects: true, }, diff --git a/webpack-test/cases/side-effects/empty-modules/test.config.js b/webpack-test/cases/side-effects/empty-modules/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/side-effects/empty-modules/test.config.js +++ b/webpack-test/cases/side-effects/empty-modules/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/side-effects/issue-11673/test.config.js b/webpack-test/cases/side-effects/issue-11673/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/side-effects/issue-11673/test.config.js +++ b/webpack-test/cases/side-effects/issue-11673/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/side-effects/issue-12071/test.config.js b/webpack-test/cases/side-effects/issue-12071/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/side-effects/issue-12071/test.config.js +++ b/webpack-test/cases/side-effects/issue-12071/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/side-effects/issue-12114/test.config.js b/webpack-test/cases/side-effects/issue-12114/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/side-effects/issue-12114/test.config.js +++ b/webpack-test/cases/side-effects/issue-12114/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/side-effects/issue-12570-second-try/test.config.js b/webpack-test/cases/side-effects/issue-12570-second-try/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/side-effects/issue-12570-second-try/test.config.js +++ b/webpack-test/cases/side-effects/issue-12570-second-try/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/side-effects/issue-12570/test.config.js b/webpack-test/cases/side-effects/issue-12570/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/side-effects/issue-12570/test.config.js +++ b/webpack-test/cases/side-effects/issue-12570/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/side-effects/missing-module-7499/test.config.js b/webpack-test/cases/side-effects/missing-module-7499/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/side-effects/missing-module-7499/test.config.js +++ b/webpack-test/cases/side-effects/missing-module-7499/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/side-effects/order-issue-7665/test.config.js b/webpack-test/cases/side-effects/order-issue-7665/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/side-effects/order-issue-7665/test.config.js +++ b/webpack-test/cases/side-effects/order-issue-7665/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/cases/side-effects/wrong-module-10146/test.config.js b/webpack-test/cases/side-effects/wrong-module-10146/test.config.js index 87792b4d410..1411bc8299a 100644 --- a/webpack-test/cases/side-effects/wrong-module-10146/test.config.js +++ b/webpack-test/cases/side-effects/wrong-module-10146/test.config.js @@ -1,10 +1,6 @@ /**@type {import("@rspack/cli").Configuration} */ const config = { - experiments: { - rspackFuture: { - newTreeshaking: true, - }, - }, - + + }; module.exports = config; diff --git a/webpack-test/configCases/optimization/runtime-specific-used-exports2/webpack.config.js b/webpack-test/configCases/optimization/runtime-specific-used-exports2/webpack.config.js index d7ff8eeb2f5..794c3350d02 100644 --- a/webpack-test/configCases/optimization/runtime-specific-used-exports2/webpack.config.js +++ b/webpack-test/configCases/optimization/runtime-specific-used-exports2/webpack.config.js @@ -4,11 +4,6 @@ module.exports = { filename: "[name].js" }, target: "node", - experiments: { - rspackFuture: { - newTreeshaking: true - } - }, optimization: { chunkIds: "named", usedExports: true, diff --git a/webpack-test/configCases/scope-hoisting/class-naming/rspack.config.js b/webpack-test/configCases/scope-hoisting/class-naming/rspack.config.js index c39a6475740..7d4cc233bfe 100644 --- a/webpack-test/configCases/scope-hoisting/class-naming/rspack.config.js +++ b/webpack-test/configCases/scope-hoisting/class-naming/rspack.config.js @@ -1,10 +1,5 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { - experiments: { - rspackFuture: { - newTreeshaking: true, - } - }, optimization: { concatenateModules: true } diff --git a/website/docs/en/config/experiments.mdx b/website/docs/en/config/experiments.mdx index 638dddcac95..715244f813b 100644 --- a/website/docs/en/config/experiments.mdx +++ b/website/docs/en/config/experiments.mdx @@ -319,11 +319,16 @@ module.exports = { ### experiments.rspackFuture.newTreeshaking - + - **Type:** `boolean` - **Introduced in Version:** v0.4.2 - **Enabled by Default in Version:** v0.6.0 +- **Removed in Version:** v0.7.0 + +:::warning +newTreeshaking has been enabled and cannot go back to the deprecated tree shaking algorithm since version 0.7.0. +::: This feature enables the new treeshaking implementation the same as webpack, which would generate more efficient and smaller code diff --git a/website/docs/zh/config/experiments.mdx b/website/docs/zh/config/experiments.mdx index 18fbebdceab..be23327f13e 100644 --- a/website/docs/zh/config/experiments.mdx +++ b/website/docs/zh/config/experiments.mdx @@ -328,11 +328,16 @@ module.exports = { ### experiments.rspackFuture.newTreeshaking - + - **类型:** `boolean` - **引入版本:** v0.4.2 - **默认开启版本:** v0.6.0 +- **移除版本:** v0.7.0 + +:::warning +从 0.7.0 版本开始,newTreeshaking 默认开启并且不能切换回已废弃的老 tree shaking 算法。 +::: 该功能启用了与 webpack 相同的新摇树优化实现,可以生成更高效和更小的代码。