@@ -7,7 +7,7 @@ use crate::printer::Printer;
77use crate :: properties:: PropertyId ;
88use crate :: rules:: supports:: SupportsCondition ;
99use crate :: stylesheet:: ParserOptions ;
10- use crate :: targets:: { should_compile, Targets } ;
10+ use crate :: targets:: { should_compile, Features , Targets } ;
1111use crate :: traits:: { Parse , ParseWithOptions , ToCss } ;
1212use crate :: values:: angle:: Angle ;
1313use crate :: values:: color:: {
@@ -1176,6 +1176,44 @@ impl<'i> TokenList<'i> {
11761176 res
11771177 }
11781178
1179+ pub ( crate ) fn get_features ( & self ) -> Features {
1180+ let mut features = Features :: empty ( ) ;
1181+ for token in & self . 0 {
1182+ match token {
1183+ TokenOrValue :: Color ( color) => {
1184+ features |= color. get_features ( ) ;
1185+ }
1186+ TokenOrValue :: UnresolvedColor ( unresolved_color) => {
1187+ features |= Features :: SpaceSeparatedColorNotation ;
1188+ match unresolved_color {
1189+ UnresolvedColor :: LightDark { light, dark } => {
1190+ features |= Features :: LightDark ;
1191+ features |= light. get_features ( ) ;
1192+ features |= dark. get_features ( ) ;
1193+ }
1194+ _ => { }
1195+ }
1196+ }
1197+ TokenOrValue :: Function ( f) => {
1198+ features |= f. arguments . get_features ( ) ;
1199+ }
1200+ TokenOrValue :: Var ( v) => {
1201+ if let Some ( fallback) = & v. fallback {
1202+ features |= fallback. get_features ( ) ;
1203+ }
1204+ }
1205+ TokenOrValue :: Env ( v) => {
1206+ if let Some ( fallback) = & v. fallback {
1207+ features |= fallback. get_features ( ) ;
1208+ }
1209+ }
1210+ _ => { }
1211+ }
1212+ }
1213+
1214+ features
1215+ }
1216+
11791217 /// Substitutes variables with the provided values.
11801218 #[ cfg( feature = "substitute_variables" ) ]
11811219 #[ cfg_attr( docsrs, doc( cfg( feature = "substitute_variables" ) ) ) ]
@@ -1605,7 +1643,7 @@ impl<'i> UnresolvedColor<'i> {
16051643
16061644 match self {
16071645 UnresolvedColor :: RGB { r, g, b, alpha } => {
1608- if should_compile ! ( dest. targets, SpaceSeparatedColorNotation ) {
1646+ if should_compile ! ( dest. targets. current , SpaceSeparatedColorNotation ) {
16091647 dest. write_str ( "rgba(" ) ?;
16101648 c ( r) . to_css ( dest) ?;
16111649 dest. delim ( ',' , false ) ?;
@@ -1629,7 +1667,7 @@ impl<'i> UnresolvedColor<'i> {
16291667 dest. write_char ( ')' )
16301668 }
16311669 UnresolvedColor :: HSL { h, s, l, alpha } => {
1632- if should_compile ! ( dest. targets, SpaceSeparatedColorNotation ) {
1670+ if should_compile ! ( dest. targets. current , SpaceSeparatedColorNotation ) {
16331671 dest. write_str ( "hsla(" ) ?;
16341672 h. to_css ( dest) ?;
16351673 dest. delim ( ',' , false ) ?;
@@ -1653,7 +1691,7 @@ impl<'i> UnresolvedColor<'i> {
16531691 dest. write_char ( ')' )
16541692 }
16551693 UnresolvedColor :: LightDark { light, dark } => {
1656- if should_compile ! ( dest. targets, LightDark ) {
1694+ if should_compile ! ( dest. targets. current , LightDark ) {
16571695 dest. write_str ( "var(--lightningcss-light" ) ?;
16581696 dest. delim ( ',' , false ) ?;
16591697 light. to_css ( dest, is_custom_property) ?;
0 commit comments