Preserve ordering of font-* properties that follow a font shorthand#1209
Preserve ordering of font-* properties that follow a font shorthand#1209samizdatco wants to merge 5 commits intoparcel-bundler:masterfrom
font-* properties that follow a font shorthand#1209Conversation
the downside is that this assumes that the shorthand will be parsed successfully by all browsers. |
Good point. So in that case, maybe the better solution is the one in the previous commit where the appearance of a longhand property triggers any pending shorthand to be flushed first (i.e., it prevents reordering but doesn't discard potentially-reset longhands)? |
…ent shorthand" This reverts commit 91fe728.
This PR prevents non-shorthand
font-*properties being reordered to precede a shorthandfontrule.Existing behavior
As described in #1207, the
FontHandlercurrently watches for all the properties that could be combined into a shorthand (e.g.,font-family,font-weight,font-style, etc.), but will immediately emit any unrecognized font properties such asfont-variantorfont-kerningwhile deferring thefontshorthand.For example (playground):
will be minified to:
This is a problem because placing the
fontshorthand at the end has the side-effect of resetting all priorfont-*properties to their defaults, which is clearly not the intent of the original css.Changes
I added a new
matchbranch toFontHandler’shandle_propertymethod to catch anyProperty::Customthat begins with"font-"(but has not already been caught as a property that could be merged into the shorthand) and trigger a flush of the pending shorthand before emitting the newly encountered longhand.Initially I applied this to just the
font-variant-*properties (cd12e58), but I believe this behavior is actually desirable for all non-shorthand font properties so I extended it to the wholefont-*prefix.Fixes #1207
Questions
I'm not quite clear on the distinction between
Property::CustomandProperty::Unparsed; maybe this needs to checkUnparsedproperties to see if they match thefont-*prefix as well?I added an optimization that discards the cached longhand properties when a shorthand[reverted: see discussion below]fontdeclaration is encountered (since they'll all be reset to their defaults anyway). Are there any negative consequences to doing this?