Unverified Commit e71934a1 authored by Sam Poder's avatar Sam Poder Committed by GitHub

[turbopack] Drop unused exports from a CJS module (#95716)

This PR introduces two new things: a pass of the analyzer that
recognises exports from CJS modules (in the form of `exports.foo`, see
`analyze_cjs_exports`) and then a CodeGen that reads `export_usage_info`
to remove CJS exports that are not used.

This PR does not add anything additionally to `export_usage_info`, so
this means that we only trim from modules that are imported with `import
{ foo } from "bar"`. The CodeGen depends on the output of
`analyze_cjs_exports` for the locations of exports, whether it is safe
to drop exports (its pretty conservative), and also whether `__esModule`
is present.
parent 5fe8c690
...@@ -374,6 +374,7 @@ pub async fn get_client_module_options_context( ...@@ -374,6 +374,7 @@ pub async fn get_client_module_options_context(
enable_import_as_bytes: *next_config.turbopack_import_type_bytes().await?, enable_import_as_bytes: *next_config.turbopack_import_type_bytes().await?,
source_maps, source_maps,
infer_module_side_effects: *next_config.turbopack_infer_module_side_effects().await?, infer_module_side_effects: *next_config.turbopack_infer_module_side_effects().await?,
cjs_tree_shaking: *next_config.turbopack_cjs_tree_shaking().await?,
preset_env_config, preset_env_config,
..Default::default() ..Default::default()
}, },
......
...@@ -1409,6 +1409,8 @@ pub struct ExperimentalConfig { ...@@ -1409,6 +1409,8 @@ pub struct ExperimentalConfig {
turbopack_remove_unused_exports: Option<bool>, turbopack_remove_unused_exports: Option<bool>,
/// Enable local analysis to infer side effect free modules. Defaults to true. /// Enable local analysis to infer side effect free modules. Defaults to true.
turbopack_infer_module_side_effects: Option<bool>, turbopack_infer_module_side_effects: Option<bool>,
/// Enable tree shaking of unused exports from static CommonJS modules. Defaults to false.
turbopack_cjs_tree_shaking: Option<bool>,
/// Devtool option for the segment explorer. /// Devtool option for the segment explorer.
devtool_segment_explorer: Option<bool>, devtool_segment_explorer: Option<bool>,
/// Whether to report inlined system environment variables as warnings or errors. /// Whether to report inlined system environment variables as warnings or errors.
...@@ -2468,6 +2470,15 @@ impl NextConfig { ...@@ -2468,6 +2470,15 @@ impl NextConfig {
) )
} }
#[turbo_tasks::function]
pub fn turbopack_cjs_tree_shaking(&self) -> Vc<bool> {
Vc::cell(
self.experimental
.turbopack_cjs_tree_shaking
.unwrap_or(false),
)
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn turbopack_plugin_runtime_strategy(&self) -> Vc<TurbopackPluginRuntimeStrategy> { pub fn turbopack_plugin_runtime_strategy(&self) -> Vc<TurbopackPluginRuntimeStrategy> {
#[cfg(feature = "process_pool")] #[cfg(feature = "process_pool")]
......
...@@ -578,6 +578,7 @@ pub async fn get_server_module_options_context( ...@@ -578,6 +578,7 @@ pub async fn get_server_module_options_context(
ignore_dynamic_requests: true, ignore_dynamic_requests: true,
source_maps, source_maps,
infer_module_side_effects: *next_config.turbopack_infer_module_side_effects().await?, infer_module_side_effects: *next_config.turbopack_infer_module_side_effects().await?,
cjs_tree_shaking: *next_config.turbopack_cjs_tree_shaking().await?,
..Default::default() ..Default::default()
}, },
execution_context: Some(execution_context), execution_context: Some(execution_context),
......
...@@ -404,6 +404,7 @@ export const experimentalSchema = { ...@@ -404,6 +404,7 @@ export const experimentalSchema = {
turbopackLocalPostcssConfig: z.boolean().optional(), turbopackLocalPostcssConfig: z.boolean().optional(),
turbopackModuleIds: z.enum(['named', 'deterministic']).optional(), turbopackModuleIds: z.enum(['named', 'deterministic']).optional(),
turbopackInferModuleSideEffects: z.boolean().optional(), turbopackInferModuleSideEffects: z.boolean().optional(),
turbopackCjsTreeShaking: z.boolean().optional(),
turbopackServerFastRefresh: z.boolean().optional(), turbopackServerFastRefresh: z.boolean().optional(),
optimizePackageImports: z.array(z.string()).optional(), optimizePackageImports: z.array(z.string()).optional(),
optimizeServerReact: z.boolean().optional(), optimizeServerReact: z.boolean().optional(),
......
...@@ -900,6 +900,13 @@ export interface ExperimentalConfig { ...@@ -900,6 +900,13 @@ export interface ExperimentalConfig {
*/ */
turbopackInferModuleSideEffects?: boolean turbopackInferModuleSideEffects?: boolean
/**
* Enable tree shaking of unused exports from analyzable CommonJS modules in Turbopack.
*
* Defaults to `false`
*/
turbopackCjsTreeShaking?: boolean
/** /**
* Set this to `false` to disable the automatic configuration of the babel loader when a Babel * Set this to `false` to disable the automatic configuration of the babel loader when a Babel
* configuration file is present. This option is enabled by default. * configuration file is present. This option is enabled by default.
......
...@@ -25,7 +25,7 @@ use turbopack_core::{ ...@@ -25,7 +25,7 @@ use turbopack_core::{
target::CompileTarget, target::CompileTarget,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
AnalyzeMode, AnalyzeMode, SpecifiedModuleType,
analyzer::{ analyzer::{
Bump, ThreadLocal, Bump, ThreadLocal,
graph::{EvalContext, VarGraph, create_graph}, graph::{EvalContext, VarGraph, create_graph},
...@@ -84,6 +84,8 @@ pub fn benchmark(c: &mut Criterion) { ...@@ -84,6 +84,8 @@ pub fn benchmark(c: &mut Criterion) {
&eval_context, &eval_context,
AnalyzeMode::CodeGenerationAndTracing, AnalyzeMode::CodeGenerationAndTracing,
true, true,
SpecifiedModuleType::Automatic,
true,
)); ));
let input = BenchInput { let input = BenchInput {
...@@ -120,6 +122,8 @@ fn bench_create_graph(b: &mut Bencher, input: &BenchInput) { ...@@ -120,6 +122,8 @@ fn bench_create_graph(b: &mut Bencher, input: &BenchInput) {
&input.eval_context, &input.eval_context,
AnalyzeMode::CodeGenerationAndTracing, AnalyzeMode::CodeGenerationAndTracing,
true, true,
SpecifiedModuleType::Automatic,
true,
)); ));
}); });
} }
......
use swc_core::{
common::Mark,
ecma::ast::{Expr, Ident, MemberExpr, MemberProp},
};
use crate::utils::unparen;
/// True if `prop` is the non-computed member property `.<name>`.
fn prop_is(prop: &MemberProp, name: &str) -> bool {
matches!(prop, MemberProp::Ident(i) if i.sym.as_ref() == name)
}
/// True if `identifier` is the named, unshadowed module-scope (unresolved)
/// binding — e.g. the real CommonJS `module`/`exports`/`require`, not a local
/// shadow. Prevents `let exports = {}; exports.foo = 'a'` from being treated as
/// a write to the global `exports`.
pub(crate) fn is_global(identifier: &Ident, name: &str, unresolved_mark: Mark) -> bool {
identifier.ctxt.outer() == unresolved_mark && identifier.sym.as_ref() == name
}
/// `module.exports` (the real, unshadowed `module` binding).
pub(crate) fn is_module_dot_exports(member: &MemberExpr, unresolved_mark: Mark) -> bool {
matches!(unparen(&member.obj), Expr::Ident(o) if is_global(o, "module", unresolved_mark))
&& prop_is(&member.prop, "exports")
}
/// Whether `expr` is the real (unshadowed) `exports` or `module.exports`.
pub(crate) fn is_exports_object(expr: &Expr, unresolved_mark: Mark) -> bool {
match unparen(expr) {
Expr::Ident(o) => is_global(o, "exports", unresolved_mark),
Expr::Member(inner) => is_module_dot_exports(inner, unresolved_mark),
_ => false,
}
}
/// `module.exports` or a property chain rooted at it (`module.exports.a.b`).
pub(crate) fn is_module_exports_chain(expr: &Expr, unresolved_mark: Mark) -> bool {
match unparen(expr) {
Expr::Member(m) => {
is_module_dot_exports(m, unresolved_mark)
|| is_module_exports_chain(&m.obj, unresolved_mark)
}
_ => false,
}
}
/// Whether `member` writes the module's own CommonJS exports: `exports.<x>`,
/// `module.exports`, or `module.exports.<x>`.
pub(crate) fn is_cjs_export_member(member: &MemberExpr, unresolved_mark: Mark) -> bool {
match unparen(&member.obj) {
// `exports.<anything>`, or `module.exports`
Expr::Ident(obj) => {
is_global(obj, "exports", unresolved_mark)
|| is_module_dot_exports(member, unresolved_mark)
}
// `module.exports.<anything>`
Expr::Member(inner) => is_cjs_export_member(inner, unresolved_mark),
_ => false,
}
}
...@@ -59,6 +59,10 @@ impl EvalContext { ...@@ -59,6 +59,10 @@ impl EvalContext {
self.imports.is_esm(specified_type) self.imports.is_esm(specified_type)
} }
pub fn is_cjs(&self, specified_type: SpecifiedModuleType) -> bool {
self.imports.is_cjs(specified_type)
}
pub(super) fn eval_prop_name<'a>(&self, arena: &'a Bump, prop: &PropName) -> JsValue<'a> { pub(super) fn eval_prop_name<'a>(&self, arena: &'a Bump, prop: &PropName) -> JsValue<'a> {
match prop { match prop {
PropName::Ident(ident) => ident.sym.clone().into(), PropName::Ident(ident) => ident.sym.clone().into(),
......
...@@ -11,7 +11,7 @@ pub use crate::analyzer::graph::{ ...@@ -11,7 +11,7 @@ pub use crate::analyzer::graph::{
eval_context::EvalContext, eval_context::EvalContext,
}; };
use crate::{ use crate::{
AnalyzeMode, AnalyzeMode, SpecifiedModuleType,
analyzer::{Bump, JsValue, graph::visitor::Analyzer}, analyzer::{Bump, JsValue, graph::visitor::Analyzer},
code_gen::CodeGen, code_gen::CodeGen,
}; };
...@@ -52,6 +52,8 @@ pub fn create_graph<'a>( ...@@ -52,6 +52,8 @@ pub fn create_graph<'a>(
eval_context: &EvalContext, eval_context: &EvalContext,
analyze_mode: AnalyzeMode, analyze_mode: AnalyzeMode,
supports_block_scoping: bool, supports_block_scoping: bool,
specified_module_type: SpecifiedModuleType,
cjs_tree_shaking: bool,
) -> VarGraph<'a> { ) -> VarGraph<'a> {
let mut analyzer = Analyzer { let mut analyzer = Analyzer {
arena, arena,
...@@ -70,6 +72,13 @@ pub fn create_graph<'a>( ...@@ -70,6 +72,13 @@ pub fn create_graph<'a>(
supports_block_scoping, supports_block_scoping,
}; };
// CommonJS export recognition runs only for a CommonJS module that emits code, and only
// when the `turbopackCjsTreeShaking` experimental flag is enabled.
if cjs_tree_shaking && analyze_mode.is_code_gen() && eval_context.is_cjs(specified_module_type)
{
analyzer.enable_cjs_exports();
}
m.visit_with_ast_path(&mut analyzer, &mut Default::default()); m.visit_with_ast_path(&mut analyzer, &mut Default::default());
let mut graph = analyzer.data; let mut graph = analyzer.data;
......
...@@ -524,6 +524,10 @@ impl ImportMap { ...@@ -524,6 +524,10 @@ impl ImportMap {
} }
} }
pub fn is_cjs(&self, specified_type: SpecifiedModuleType) -> bool {
!self.is_esm(specified_type)
}
pub fn get_import<'a>(&self, arena: &'a Bump, id: &Id) -> Option<JsValue<'a>> { pub fn get_import<'a>(&self, arena: &'a Bump, id: &Id) -> Option<JsValue<'a>> {
if let Some((i, i_sym)) = self.imports.get(id) { if let Some((i, i_sym)) = self.imports.get(id) {
let r = &self.references[*i]; let r = &self.references[*i];
......
...@@ -7,6 +7,7 @@ pub(crate) use self::imports::ImportMap; ...@@ -7,6 +7,7 @@ pub(crate) use self::imports::ImportMap;
pub mod builtin; pub mod builtin;
pub mod bump_vec; pub mod bump_vec;
pub(crate) mod cjs_ast;
pub mod graph; pub mod graph;
pub mod imports; pub mod imports;
pub mod linker; pub mod linker;
...@@ -290,7 +291,7 @@ mod tests { ...@@ -290,7 +291,7 @@ mod tests {
linker::link, linker::link,
}; };
use crate::{ use crate::{
AnalyzeMode, AnalyzeMode, SpecifiedModuleType,
analyzer::{Bump, ThreadLocal, graph::AssignmentScopes, imports::ImportAttributes}, analyzer::{Bump, ThreadLocal, graph::AssignmentScopes, imports::ImportAttributes},
}; };
...@@ -363,6 +364,8 @@ mod tests { ...@@ -363,6 +364,8 @@ mod tests {
&eval_context, &eval_context,
AnalyzeMode::CodeGenerationAndTracing, AnalyzeMode::CodeGenerationAndTracing,
true, true,
SpecifiedModuleType::EcmaScript,
true,
); );
anyhow::Ok((eval_context, var_graph)) anyhow::Ok((eval_context, var_graph))
})?; })?;
......
...@@ -48,7 +48,12 @@ use swc_core::{ ...@@ -48,7 +48,12 @@ use swc_core::{
}; };
use turbopack_core::module::ModuleSideEffects; use turbopack_core::module::ModuleSideEffects;
use crate::utils::unparen; use crate::{
analyzer::cjs_ast::{
is_cjs_export_member, is_global, is_module_dot_exports, is_module_exports_chain,
},
utils::unparen,
};
/// Macro to check if side effects have been detected and return early if so. /// Macro to check if side effects have been detected and return early if so.
/// This makes the early-return pattern more explicit and reduces boilerplate. /// This makes the early-return pattern more explicit and reduces boilerplate.
...@@ -268,19 +273,6 @@ static KNOWN_PURE_REGEXP_PROTOTYPE_METHODS: phf::Set<&'static str> = phf_set! { ...@@ -268,19 +273,6 @@ static KNOWN_PURE_REGEXP_PROTOTYPE_METHODS: phf::Set<&'static str> = phf_set! {
"test", "exec", "test", "exec",
}; };
/// True if `prop` is the non-computed member property `.<name>`.
fn prop_is(prop: &MemberProp, name: &str) -> bool {
matches!(prop, MemberProp::Ident(i) if i.sym.as_ref() == name)
}
/// True if `identifier` is the named, unshadowed module-scope (unresolved)
/// binding — e.g. the real CommonJS `module`/`exports`/`require`, not a local
/// shadow. Prevents `let exports = {}; exports.foo = 'a'` from being treated as
/// a write to the global `exports`.
fn is_global(identifier: &Ident, name: &str, unresolved_mark: Mark) -> bool {
identifier.ctxt.outer() == unresolved_mark && identifier.sym.as_ref() == name
}
/// A freshly-allocated object/array literal (evaluates to a brand-new value). /// A freshly-allocated object/array literal (evaluates to a brand-new value).
fn is_object_or_array_literal(expr: &Expr) -> bool { fn is_object_or_array_literal(expr: &Expr) -> bool {
matches!(unparen(expr), Expr::Object(_) | Expr::Array(_)) matches!(unparen(expr), Expr::Object(_) | Expr::Array(_))
...@@ -379,38 +371,6 @@ fn contains_getters_or_setters(expr: &Expr) -> bool { ...@@ -379,38 +371,6 @@ fn contains_getters_or_setters(expr: &Expr) -> bool {
} }
} }
/// `module.exports` (the real, unshadowed `module` binding).
fn is_module_dot_exports(member: &MemberExpr, unresolved_mark: Mark) -> bool {
matches!(unparen(&member.obj), Expr::Ident(o) if is_global(o, "module", unresolved_mark))
&& prop_is(&member.prop, "exports")
}
/// `module.exports` or a property chain rooted at it (`module.exports.a.b`).
fn is_module_exports_chain(expr: &Expr, unresolved_mark: Mark) -> bool {
match unparen(expr) {
Expr::Member(m) => {
is_module_dot_exports(m, unresolved_mark)
|| is_module_exports_chain(&m.obj, unresolved_mark)
}
_ => false,
}
}
/// Whether `member` writes the module's own CommonJS exports: `exports.<x>`,
/// `module.exports`, or `module.exports.<x>`.
fn is_cjs_export_member(member: &MemberExpr, unresolved_mark: Mark) -> bool {
match unparen(&member.obj) {
// `exports.<anything>`, or `module.exports`
Expr::Ident(obj) => {
is_global(obj, "exports", unresolved_mark)
|| is_module_dot_exports(member, unresolved_mark)
}
// `module.exports.<anything>`
Expr::Member(inner) => is_cjs_export_member(inner, unresolved_mark),
_ => false,
}
}
/// Calls `f` for every assignment that executes during module evaluation. /// Calls `f` for every assignment that executes during module evaluation.
/// ///
/// This descends through all expressions — conditionals, logical/binary /// This descends through all expressions — conditionals, logical/binary
......
...@@ -21,7 +21,7 @@ use crate::{ ...@@ -21,7 +21,7 @@ use crate::{
AstPath, AstPath,
amd::AmdDefineWithDependenciesCodeGen, amd::AmdDefineWithDependenciesCodeGen,
cjs::{ cjs::{
CjsRequireAssetReferenceCodeGen, CjsRequireCacheAccess, CjsExportsDropCodeGen, CjsRequireAssetReferenceCodeGen, CjsRequireCacheAccess,
CjsRequireResolveAssetReferenceCodeGen, CjsRequireResolveAssetReferenceCodeGen,
}, },
constant_condition::ConstantConditionCodeGen, constant_condition::ConstantConditionCodeGen,
...@@ -190,6 +190,7 @@ pub enum CodeGen { ...@@ -190,6 +190,7 @@ pub enum CodeGen {
EsmModuleItem(EsmModuleItem), EsmModuleItem(EsmModuleItem),
ExportsInfoBinding(ExportsInfoBinding), ExportsInfoBinding(ExportsInfoBinding),
ExportsInfoRef(ExportsInfoRef), ExportsInfoRef(ExportsInfoRef),
CjsExportsDropCodeGen(CjsExportsDropCodeGen),
IdentReplacement(IdentReplacement), IdentReplacement(IdentReplacement),
ImportMetaBinding(ImportMetaBinding), ImportMetaBinding(ImportMetaBinding),
ImportMetaRef(ImportMetaRef), ImportMetaRef(ImportMetaRef),
...@@ -226,6 +227,7 @@ impl CodeGen { ...@@ -226,6 +227,7 @@ impl CodeGen {
Self::EsmModuleItem(v) => v.code_generation(ctx).await, Self::EsmModuleItem(v) => v.code_generation(ctx).await,
Self::ExportsInfoBinding(v) => v.code_generation(ctx, module, exports).await, Self::ExportsInfoBinding(v) => v.code_generation(ctx, module, exports).await,
Self::ExportsInfoRef(v) => v.code_generation(ctx).await, Self::ExportsInfoRef(v) => v.code_generation(ctx).await,
Self::CjsExportsDropCodeGen(v) => v.code_generation(ctx, module, exports).await,
Self::IdentReplacement(v) => v.code_generation(ctx).await, Self::IdentReplacement(v) => v.code_generation(ctx).await,
Self::ImportMetaBinding(v) => v.code_generation(ctx).await, Self::ImportMetaBinding(v) => v.code_generation(ctx).await,
Self::ImportMetaRef(v) => v.code_generation(ctx).await, Self::ImportMetaRef(v) => v.code_generation(ctx).await,
......
...@@ -259,6 +259,8 @@ pub struct EcmascriptOptions { ...@@ -259,6 +259,8 @@ pub struct EcmascriptOptions {
pub inline_helpers: bool, pub inline_helpers: bool,
/// Whether to infer side effect free modules via local analysis. Defaults to true. /// Whether to infer side effect free modules via local analysis. Defaults to true.
pub infer_module_side_effects: bool, pub infer_module_side_effects: bool,
/// Whether to tree shake unused exports from static CommonJS modules. Defaults to false.
pub cjs_tree_shaking: bool,
} }
#[turbo_tasks::value(task_input)] #[turbo_tasks::value(task_input)]
......
...@@ -5,6 +5,7 @@ use swc_core::{ ...@@ -5,6 +5,7 @@ use swc_core::{
ecma::ast::{CallExpr, Expr, ExprOrSpread, Lit}, ecma::ast::{CallExpr, Expr, ExprOrSpread, Lit},
quote, quote,
}; };
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
NonLocalValue, ResolvedVc, ValueToString, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, ResolvedVc, ValueToString, Vc, debug::ValueDebugFormat, trace::TraceRawVcs,
}; };
...@@ -19,6 +20,7 @@ use turbopack_core::{ ...@@ -19,6 +20,7 @@ use turbopack_core::{
use turbopack_resolve::ecmascript::cjs_resolve; use turbopack_resolve::ecmascript::cjs_resolve;
use crate::{ use crate::{
chunk::{EcmascriptChunkPlaceable, EcmascriptExports},
code_gen::{CodeGen, CodeGeneration, IntoCodeGenReference}, code_gen::{CodeGen, CodeGeneration, IntoCodeGenReference},
create_visitor, create_visitor,
references::{ references::{
...@@ -405,3 +407,82 @@ impl From<CjsRequireCacheAccess> for CodeGen { ...@@ -405,3 +407,82 @@ impl From<CjsRequireCacheAccess> for CodeGen {
CodeGen::CjsRequireCacheAccess(val) CodeGen::CjsRequireCacheAccess(val)
} }
} }
/// Removes each named `exports.NAME = …` write the module graph proved unused.
/// Built by the analyzer for statically-analyzable CommonJS modules; recognition
/// happens inline during the walk (see `analyzer::graph::visitor`).
#[derive(
PartialEq, Eq, TraceRawVcs, ValueDebugFormat, NonLocalValue, Hash, Debug, Encode, Decode,
)]
pub struct CjsExportsDropCodeGen {
drops: Vec<DroppableCjsExportAssignment>,
/// Whether the module sets `__esModule`. Without it, a default import binds
/// the whole `module.exports`, so nothing may be dropped.
has_es_module: bool,
}
/// A single named `exports.NAME = …` write.
#[derive(
PartialEq, Eq, TraceRawVcs, ValueDebugFormat, NonLocalValue, Hash, Debug, Encode, Decode,
)]
pub struct DroppableCjsExportAssignment {
pub name: RcStr,
/// Path to the `exports.NAME = …` assignment expression.
pub path: AstPath,
}
impl CjsExportsDropCodeGen {
pub fn new(drops: Vec<DroppableCjsExportAssignment>, has_es_module: bool) -> Self {
CjsExportsDropCodeGen {
drops,
has_es_module,
}
}
pub async fn code_generation(
&self,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
_exports: ResolvedVc<EcmascriptExports>,
) -> Result<CodeGeneration> {
let export_usage_info = chunking_context
.module_export_usage(*ResolvedVc::upcast(module))
.await?;
let export_usage_info = export_usage_info.export_usage.await?;
// Without `__esModule`, a default import binds the whole `module.exports`,
// so a used `default` makes every named export reachable — drop nothing.
if !self.has_es_module && export_usage_info.is_export_used(&rcstr!("default")) {
return Ok(CodeGeneration::empty());
}
// Replace each unused `exports.NAME = <value>` with `<value>`, preserving
// side effects (the minifier drops a pure value). Rewriting the assignment
// rather than its statement keeps chained writes like
// `exports.a = exports.b = 1` sound.
let mut visitors = Vec::new();
for drop in &self.drops {
if export_usage_info.is_export_used(&drop.name) {
continue;
}
visitors.push(create_visitor!(
drop.path,
visit_mut_expr,
|expr: &mut Expr| {
if let Expr::Assign(assign) = expr {
let value = assign.right.take();
*expr = *value;
}
}
));
}
Ok(CodeGeneration::visitors(visitors))
}
}
impl From<CjsExportsDropCodeGen> for CodeGen {
fn from(val: CjsExportsDropCodeGen) -> Self {
CodeGen::CjsExportsDropCodeGen(val)
}
}
...@@ -700,6 +700,7 @@ async fn analyze_ecmascript_module_internal( ...@@ -700,6 +700,7 @@ async fn analyze_ecmascript_module_internal(
}); });
let is_esm = eval_context.is_esm(specified_type); let is_esm = eval_context.is_esm(specified_type);
let compile_time_info = compile_time_info_for_module_options( let compile_time_info = compile_time_info_for_module_options(
*raw_module.compile_time_info, *raw_module.compile_time_info,
is_esm, is_esm,
...@@ -822,6 +823,8 @@ async fn analyze_ecmascript_module_internal( ...@@ -822,6 +823,8 @@ async fn analyze_ecmascript_module_internal(
eval_context, eval_context,
analyze_mode, analyze_mode,
supports_block_scoping, supports_block_scoping,
specified_type,
options.cjs_tree_shaking,
)); ));
}); });
graph.unwrap() graph.unwrap()
......
import { used } from './lib.js'
it('keeps a used named CommonJS export', () => {
expect(used).toBe('used-value')
})
it('preserves the side effects of an unused-but-impure export write', () => {
// `exports.impure` is never imported, but its RHS has a side effect, so the
// write must not be dropped.
expect(globalThis.__cjs_impure_ran).toBe(true)
})
globalThis.__cjs_impure_ran = false
exports.used = 'used-value'
// Unused + pure: expected to be dropped from the output entirely.
exports.unused = 'unused-value'
// Unused but impure: the assignment is removable, yet its side-effecting RHS must
// still run, so this statement is kept.
exports.impure = globalThis.__cjs_impure_ran = true
...@@ -93,6 +93,8 @@ struct SnapshotOptions { ...@@ -93,6 +93,8 @@ struct SnapshotOptions {
#[serde(default)] #[serde(default)]
remove_unused_exports: bool, remove_unused_exports: bool,
#[serde(default)] #[serde(default)]
cjs_tree_shaking: bool,
#[serde(default)]
scope_hoisting: bool, scope_hoisting: bool,
#[serde(default)] #[serde(default)]
shared_runtime: bool, shared_runtime: bool,
...@@ -136,6 +138,7 @@ impl Default for SnapshotOptions { ...@@ -136,6 +138,7 @@ impl Default for SnapshotOptions {
tree_shaking_mode: None, tree_shaking_mode: None,
remove_unused_imports: false, remove_unused_imports: false,
remove_unused_exports: false, remove_unused_exports: false,
cjs_tree_shaking: false,
scope_hoisting: false, scope_hoisting: false,
shared_runtime: false, shared_runtime: false,
production_chunking: false, production_chunking: false,
...@@ -410,6 +413,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -410,6 +413,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
})), })),
ignore_dynamic_requests: true, ignore_dynamic_requests: true,
infer_module_side_effects: true, infer_module_side_effects: true,
cjs_tree_shaking: options.cjs_tree_shaking,
enable_exports_info_inlining: true, enable_exports_info_inlining: true,
enable_rust_react_compiler: options enable_rust_react_compiler: options
.enable_rust_react_compiler .enable_rust_react_compiler
......
exports.used = 'first'
exports.used = 'second'
exports.unused = 'x'
exports.unused = 'y'
{
"removeUnusedImports": false,
"removeUnusedExports": true,
"cjsTreeShaking": true,
"treeShakingMode": "reexports-only"
}
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1ece_tests_snapshot_cjs-remove-unused-exports_duplicate-export_input_index_0xvj6cu.js",
{"otherChunks":["output/1jsg_tests_snapshot_cjs-remove-unused-exports_duplicate-export_input_1js1n6_._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/duplicate-export/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/1jsg_tests_snapshot_cjs-remove-unused-exports_duplicate-export_input_1js1n6_._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/duplicate-export/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$duplicate$2d$export$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/duplicate-export/input/lib.js [test] (ecmascript)");
;
console.log(__TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$duplicate$2d$export$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__["used"]);
__turbopack_context__.s([]);
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/duplicate-export/input/lib.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
exports.used = 'first';
exports.used = 'second';
'x';
'y';
}),
]);
//# sourceMappingURL=1jsg_tests_snapshot_cjs-remove-unused-exports_duplicate-export_input_1js1n6_._.js.map
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/duplicate-export/input/index.js"],"sourcesContent":["import { used } from './lib.js'\n\nconsole.log(used)\n"],"names":["console","log"],"mappings":"AAAA;;AAEAA,QAAQC,GAAG,CAAC,6OAAI"}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/duplicate-export/input/lib.js"],"sourcesContent":["exports.used = 'first'\nexports.used = 'second'\nexports.unused = 'x'\nexports.unused = 'y'\n"],"names":["exports","used"],"mappings":"AAAAA,QAAQC,IAAI,GAAG;AACfD,QAAQC,IAAI,GAAG;AACE;AACA"}}]
}
\ No newline at end of file
{
"removeUnusedImports": false,
"removeUnusedExports": true,
"cjsTreeShaking": true,
"treeShakingMode": "reexports-only"
}
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1ece_tests_snapshot_cjs-remove-unused-exports_named-import_input_index_0y_8z-5.js",
{"otherChunks":["output/1jsg_tests_snapshot_cjs-remove-unused-exports_named-import_input_0sdv_zx._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/named-import/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/1jsg_tests_snapshot_cjs-remove-unused-exports_named-import_input_0sdv_zx._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/named-import/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$named$2d$import$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/named-import/input/lib.js [test] (ecmascript)");
;
console.log(__TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$named$2d$import$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__["used"]);
__turbopack_context__.s([]);
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/named-import/input/lib.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
exports.used = 'used-value';
'unused-value';
}),
]);
//# sourceMappingURL=1jsg_tests_snapshot_cjs-remove-unused-exports_named-import_input_0sdv_zx._.js.map
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/named-import/input/index.js"],"sourcesContent":["import { used } from './lib.js'\n\nconsole.log(used)\n"],"names":["console","log"],"mappings":"AAAA;;AAEAA,QAAQC,GAAG,CAAC,yOAAI"}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/named-import/input/lib.js"],"sourcesContent":["exports.used = 'used-value'\nexports.unused = 'unused-value'\n"],"names":["exports","used"],"mappings":"AAAAA,QAAQC,IAAI,GAAG;AACE"}}]
}
\ No newline at end of file
import { used } from './lib.js'
// A wholesale `require()` consumer reports `ExportUsage::All`, so the graph must
// mark every export used and nothing may be dropped.
const lib = require('./lib.js')
console.log(used, lib.unused)
{
"removeUnusedImports": false,
"removeUnusedExports": true,
"cjsTreeShaking": true,
"treeShakingMode": "reexports-only"
}
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1ece_tests_snapshot_cjs-remove-unused-exports_require-consumer_input_index_1spu1dq.js",
{"otherChunks":["output/1jsg_tests_snapshot_cjs-remove-unused-exports_require-consumer_input_0n4wt13._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/require-consumer/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/1jsg_tests_snapshot_cjs-remove-unused-exports_require-consumer_input_0n4wt13._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/require-consumer/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$require$2d$consumer$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/require-consumer/input/lib.js [test] (ecmascript)");
;
// A wholesale `require()` consumer reports `ExportUsage::All`, so the graph must
// mark every export used and nothing may be dropped.
const lib = __turbopack_context__.r("[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/require-consumer/input/lib.js [test] (ecmascript)");
console.log(__TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$require$2d$consumer$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__["used"], lib.unused);
__turbopack_context__.s([]);
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/require-consumer/input/lib.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
exports.used = 'used-value';
exports.unused = 'unused-value';
}),
]);
//# sourceMappingURL=1jsg_tests_snapshot_cjs-remove-unused-exports_require-consumer_input_0n4wt13._.js.map
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/require-consumer/input/index.js"],"sourcesContent":["import { used } from './lib.js'\n\n// A wholesale `require()` consumer reports `ExportUsage::All`, so the graph must\n// mark every export used and nothing may be dropped.\nconst lib = require('./lib.js')\n\nconsole.log(used, lib.unused)\n"],"names":["lib","console","log","unused"],"mappings":"AAAA;;AAEA,iFAAiF;AACjF,qDAAqD;AACrD,MAAMA;AAENC,QAAQC,GAAG,CAAC,6OAAI,EAAEF,IAAIG,MAAM"}},
{"offset": {"line": 14, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/require-consumer/input/lib.js"],"sourcesContent":["exports.used = 'used-value'\nexports.unused = 'unused-value'\n"],"names":["exports","used","unused"],"mappings":"AAAAA,QAAQC,IAAI,GAAG;AACfD,QAAQE,MAAM,GAAG"}}]
}
\ No newline at end of file
error - [bindings] /turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-export/input/index.js:1:0 Export used doesn't exist in target module
+ v-----------------------------v
1 + import { used } from './lib.js'
+ ^-----------------------------^
2 |
3 | console.log(used)
4 |
The export used was not found in module [project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-export/input/lib.js [test] (ecmascript).
The module has no exports at all.
All exports of the module are statically known (It doesn't have dynamic exports). So it's known statically that the requested export doesn't exist.
| These are the exports of the module:
|
|
\ No newline at end of file
{
"removeUnusedImports": false,
"removeUnusedExports": true,
"cjsTreeShaking": true,
"treeShakingMode": "reexports-only"
}
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1ece_tests_snapshot_cjs-remove-unused-exports_this-export_input_index_0k-9-zc.js",
{"otherChunks":["output/1jsg_tests_snapshot_cjs-remove-unused-exports_this-export_input_1n3fiwl._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-export/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/1jsg_tests_snapshot_cjs-remove-unused-exports_this-export_input_1n3fiwl._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-export/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$this$2d$export$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-export/input/lib.js [test] (ecmascript)");
;
console.log(__TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$this$2d$export$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__["used"]);
__turbopack_context__.s([]);
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-export/input/lib.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
/*TURBOPACK member replacement*/ __turbopack_context__.e.used = 'used-value';
'unused-value';
}),
]);
//# sourceMappingURL=1jsg_tests_snapshot_cjs-remove-unused-exports_this-export_input_1n3fiwl._.js.map
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-export/input/index.js"],"sourcesContent":["import { used } from './lib.js'\n\nconsole.log(used)\n"],"names":["console","log"],"mappings":"AAAA;;AAEAA,QAAQC,GAAG,CAAC,wOAAI"}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-export/input/lib.js"],"sourcesContent":["this.used = 'used-value'\nthis.unused = 'unused-value'\n"],"names":["used"],"mappings":"AAAA,yDAAKA,IAAI,GAAG;AACE"}}]
}
\ No newline at end of file
// `viaThis` is pure and never imported by name, so it looks droppable. But it is
// read through `this` in a top-level arrow — where `this` aliases `exports` — so
// the module must be treated as opaque CommonJS and nothing may be dropped.
exports.viaThis = 'V'
exports.leak = () => this.viaThis
{
"removeUnusedImports": false,
"removeUnusedExports": true,
"cjsTreeShaking": true,
"treeShakingMode": "reexports-only"
}
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1ece_tests_snapshot_cjs-remove-unused-exports_this-in-arrow_input_index_1a7v9ht.js",
{"otherChunks":["output/1jsg_tests_snapshot_cjs-remove-unused-exports_this-in-arrow_input_0tvvz6j._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-in-arrow/input/index.js [test] (ecmascript)"]}
]);
// Dummy runtime
\ No newline at end of file
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push(["output/1jsg_tests_snapshot_cjs-remove-unused-exports_this-in-arrow_input_0tvvz6j._.js",
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-in-arrow/input/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";
var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$this$2d$in$2d$arrow$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-in-arrow/input/lib.js [test] (ecmascript)");
;
console.log((0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$cjs$2d$remove$2d$unused$2d$exports$2f$this$2d$in$2d$arrow$2f$input$2f$lib$2e$js__$5b$test$5d$__$28$ecmascript$29$__["leak"])());
__turbopack_context__.s([]);
}),
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-in-arrow/input/lib.js [test] (ecmascript)", ((__turbopack_context__, module, exports) => {
// `viaThis` is pure and never imported by name, so it looks droppable. But it is
// read through `this` in a top-level arrow — where `this` aliases `exports` — so
// the module must be treated as opaque CommonJS and nothing may be dropped.
exports.viaThis = 'V';
exports.leak = ()=>/*TURBOPACK member replacement*/ __turbopack_context__.e.viaThis;
}),
]);
//# sourceMappingURL=1jsg_tests_snapshot_cjs-remove-unused-exports_this-in-arrow_input_0tvvz6j._.js.map
\ No newline at end of file
{
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 4, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-in-arrow/input/index.js"],"sourcesContent":["import { leak } from './lib.js'\n\nconsole.log(leak())\n"],"names":["console","log"],"mappings":"AAAA;;AAEAA,QAAQC,GAAG,CAAC,IAAA,6OAAI"}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/cjs-remove-unused-exports/this-in-arrow/input/lib.js"],"sourcesContent":["// `viaThis` is pure and never imported by name, so it looks droppable. But it is\n// read through `this` in a top-level arrow — where `this` aliases `exports` — so\n// the module must be treated as opaque CommonJS and nothing may be dropped.\nexports.viaThis = 'V'\nexports.leak = () => this.viaThis\n"],"names":["exports","viaThis","leak"],"mappings":"AAAA,iFAAiF;AACjF,iFAAiF;AACjF,4EAA4E;AAC5EA,QAAQC,OAAO,GAAG;AAClBD,QAAQE,IAAI,GAAG,IAAM,yDAAKD,OAAO"}}]
}
\ No newline at end of file
...@@ -246,6 +246,7 @@ impl ModuleOptions { ...@@ -246,6 +246,7 @@ impl ModuleOptions {
source_maps: ecmascript_source_maps, source_maps: ecmascript_source_maps,
inline_helpers, inline_helpers,
infer_module_side_effects, infer_module_side_effects,
cjs_tree_shaking,
ref preset_env_config, ref preset_env_config,
.. ..
}, },
...@@ -336,6 +337,7 @@ impl ModuleOptions { ...@@ -336,6 +337,7 @@ impl ModuleOptions {
enable_exports_info_inlining, enable_exports_info_inlining,
inline_helpers, inline_helpers,
infer_module_side_effects, infer_module_side_effects,
cjs_tree_shaking,
..Default::default() ..Default::default()
}; };
let ecmascript_options_vc = ecmascript_options.resolved_cell(); let ecmascript_options_vc = ecmascript_options.resolved_cell();
......
...@@ -281,6 +281,9 @@ pub struct EcmascriptOptionsContext { ...@@ -281,6 +281,9 @@ pub struct EcmascriptOptionsContext {
/// Whether to infer side effect free modules via local analysis. Defaults to true. /// Whether to infer side effect free modules via local analysis. Defaults to true.
pub infer_module_side_effects: bool, pub infer_module_side_effects: bool,
/// Whether to tree shake unused exports from static CommonJS modules. Defaults to false.
pub cjs_tree_shaking: bool,
/// Additional SWC preset-env options (mode, coreJs, include, exclude, etc.). /// Additional SWC preset-env options (mode, coreJs, include, exclude, etc.).
pub preset_env_config: Option<ResolvedVc<PresetEnvConfig>>, pub preset_env_config: Option<ResolvedVc<PresetEnvConfig>>,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment