@@ -4,7 +4,7 @@ static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
44
55use lightningcss:: bundler:: { BundleErrorKind , Bundler , FileProvider , SourceProvider } ;
66use lightningcss:: css_modules:: { CssModuleExports , CssModuleReferences , PatternParseError } ;
7- use lightningcss:: dependencies:: Dependency ;
7+ use lightningcss:: dependencies:: { Dependency , DependencyOptions } ;
88use lightningcss:: error:: { Error , ErrorLocation , MinifyErrorKind , ParserError , PrinterErrorKind } ;
99use lightningcss:: stylesheet:: {
1010 MinifyOptions , ParserOptions , PrinterOptions , PseudoClasses , StyleAttribute , StyleSheet ,
@@ -466,12 +466,25 @@ struct Config {
466466 pub input_source_map : Option < String > ,
467467 pub drafts : Option < Drafts > ,
468468 pub css_modules : Option < CssModulesOption > ,
469- pub analyze_dependencies : Option < bool > ,
469+ pub analyze_dependencies : Option < AnalyzeDependenciesOption > ,
470470 pub pseudo_classes : Option < OwnedPseudoClasses > ,
471471 pub unused_symbols : Option < HashSet < String > > ,
472472 pub error_recovery : Option < bool > ,
473473}
474474
475+ #[ derive( Debug , Deserialize ) ]
476+ #[ serde( untagged) ]
477+ enum AnalyzeDependenciesOption {
478+ Bool ( bool ) ,
479+ Config ( AnalyzeDependenciesConfig ) ,
480+ }
481+
482+ #[ derive( Debug , Deserialize ) ]
483+ #[ serde( rename_all = "camelCase" ) ]
484+ struct AnalyzeDependenciesConfig {
485+ preserve_imports : bool ,
486+ }
487+
475488#[ derive( Debug , Deserialize ) ]
476489#[ serde( untagged) ]
477490enum CssModulesOption {
@@ -495,7 +508,7 @@ struct BundleConfig {
495508 pub source_map : Option < bool > ,
496509 pub drafts : Option < Drafts > ,
497510 pub css_modules : Option < CssModulesOption > ,
498- pub analyze_dependencies : Option < bool > ,
511+ pub analyze_dependencies : Option < AnalyzeDependenciesOption > ,
499512 pub pseudo_classes : Option < OwnedPseudoClasses > ,
500513 pub unused_symbols : Option < HashSet < String > > ,
501514 pub error_recovery : Option < bool > ,
@@ -586,7 +599,17 @@ fn compile<'i>(code: &'i str, config: &Config) -> Result<TransformResult<'i>, Co
586599 minify : config. minify . unwrap_or_default ( ) ,
587600 source_map : source_map. as_mut ( ) ,
588601 targets : config. targets ,
589- analyze_dependencies : config. analyze_dependencies . unwrap_or_default ( ) ,
602+ analyze_dependencies : if let Some ( d) = & config. analyze_dependencies {
603+ match d {
604+ AnalyzeDependenciesOption :: Bool ( b) if * b => Some ( DependencyOptions { remove_imports : true } ) ,
605+ AnalyzeDependenciesOption :: Config ( c) => Some ( DependencyOptions {
606+ remove_imports : !c. preserve_imports ,
607+ } ) ,
608+ _ => None ,
609+ }
610+ } else {
611+ None
612+ } ,
590613 pseudo_classes : config. pseudo_classes . as_ref ( ) . map ( |p| p. into ( ) ) ,
591614 } ) ?
592615 } ;
@@ -672,7 +695,17 @@ fn compile_bundle<'i, P: SourceProvider>(
672695 minify : config. minify . unwrap_or_default ( ) ,
673696 source_map : source_map. as_mut ( ) ,
674697 targets : config. targets ,
675- analyze_dependencies : config. analyze_dependencies . unwrap_or_default ( ) ,
698+ analyze_dependencies : if let Some ( d) = & config. analyze_dependencies {
699+ match d {
700+ AnalyzeDependenciesOption :: Bool ( b) if * b => Some ( DependencyOptions { remove_imports : true } ) ,
701+ AnalyzeDependenciesOption :: Config ( c) => Some ( DependencyOptions {
702+ remove_imports : !c. preserve_imports ,
703+ } ) ,
704+ _ => None ,
705+ }
706+ } else {
707+ None
708+ } ,
676709 pseudo_classes : config. pseudo_classes . as_ref ( ) . map ( |p| p. into ( ) ) ,
677710 } ) ?
678711 } ;
@@ -701,16 +734,15 @@ fn compile_bundle<'i, P: SourceProvider>(
701734 } )
702735}
703736
704- #[ derive( Serialize , Debug , Deserialize ) ]
737+ #[ derive( Debug , Deserialize ) ]
705738#[ serde( rename_all = "camelCase" ) ]
706739struct AttrConfig {
707740 #[ serde( with = "serde_bytes" ) ]
708741 pub code : Vec < u8 > ,
709742 pub targets : Option < Browsers > ,
710743 #[ serde( default ) ]
711744 pub minify : bool ,
712- #[ serde( default ) ]
713- pub analyze_dependencies : bool ,
745+ pub analyze_dependencies : Option < AnalyzeDependenciesOption > ,
714746 #[ serde( default ) ]
715747 pub error_recovery : bool ,
716748}
@@ -764,7 +796,17 @@ fn compile_attr<'i>(
764796 minify : config. minify ,
765797 source_map : None ,
766798 targets : config. targets ,
767- analyze_dependencies : config. analyze_dependencies ,
799+ analyze_dependencies : if let Some ( d) = & config. analyze_dependencies {
800+ match d {
801+ AnalyzeDependenciesOption :: Bool ( b) if * b => Some ( DependencyOptions { remove_imports : true } ) ,
802+ AnalyzeDependenciesOption :: Config ( c) => Some ( DependencyOptions {
803+ remove_imports : !c. preserve_imports ,
804+ } ) ,
805+ _ => None ,
806+ }
807+ } else {
808+ None
809+ } ,
768810 pseudo_classes : None ,
769811 } ) ?
770812 } ;
0 commit comments