@@ -280,8 +280,9 @@ impl<'i> DeclarationBlock<'i> {
280280 /// the shorthand will be split apart into its component longhand properties, minus the property
281281 /// to remove. When removing a shorthand, all included longhand properties are also removed.
282282 pub fn remove ( & mut self , property_id : & PropertyId ) {
283- fn remove < ' i , ' a > ( declarations : & mut Vec < Property < ' i > > , property_id : & PropertyId < ' a > ) {
283+ fn remove < ' i , ' a > ( declarations : & mut Vec < Property < ' i > > , property_id : & PropertyId < ' a > ) -> bool {
284284 let longhands = property_id. longhands ( ) . unwrap_or ( vec ! [ ] ) ;
285+ let mut needs_minify = false ;
285286 let mut i = 0 ;
286287 while i < declarations. len ( ) {
287288 let replacement = {
@@ -291,15 +292,21 @@ impl<'i> DeclarationBlock<'i> {
291292 // If the property matches the requested property id, or is a longhand
292293 // property that is included in the requested shorthand, remove it.
293294 None
294- } else if longhands. is_empty ( ) && id. longhands ( ) . unwrap_or ( vec ! [ ] ) . contains ( & property_id) {
295+ } else if id
296+ . longhands ( )
297+ . unwrap_or ( vec ! [ ] )
298+ . iter ( )
299+ . any ( |longhand| * longhand == * property_id || longhands. contains ( longhand) )
300+ {
295301 // If this is a shorthand property that includes the requested longhand,
296302 // split it apart into its component longhands, excluding the requested one.
303+ needs_minify = !longhands. is_empty ( ) ;
297304 Some (
298305 id. longhands ( )
299306 . unwrap ( )
300307 . iter ( )
301308 . filter_map ( |longhand| {
302- if * longhand == * property_id {
309+ if * longhand == * property_id || longhands . contains ( longhand ) {
303310 None
304311 } else {
305312 property. longhand ( longhand)
@@ -324,10 +331,23 @@ impl<'i> DeclarationBlock<'i> {
324331 }
325332 }
326333 }
334+
335+ needs_minify
327336 }
328337
329- remove ( & mut self . declarations , property_id) ;
330- remove ( & mut self . important_declarations , property_id) ;
338+ let needs_minify = remove ( & mut self . declarations , property_id) ;
339+ let needs_minify2 = remove ( & mut self . important_declarations , property_id) ;
340+
341+ // If we split apart a shorthand property into longhands for another shorthand
342+ // (e.g. removing border-top from border), then re-minify to combine the remaining
343+ // properties into shorthands where possible.
344+ if needs_minify || needs_minify2 {
345+ self . minify (
346+ & mut DeclarationHandler :: new ( None ) ,
347+ & mut DeclarationHandler :: new ( None ) ,
348+ & mut PropertyHandlerContext :: new ( None ) ,
349+ )
350+ }
331351 }
332352}
333353
0 commit comments