Preserve ordering of font-* properties that follow a font shorthand#1209
Open
samizdatco wants to merge 3 commits intoparcel-bundler:masterfrom
Open
Preserve ordering of font-* properties that follow a font shorthand#1209samizdatco wants to merge 3 commits intoparcel-bundler:masterfrom
font-* properties that follow a font shorthand#1209samizdatco wants to merge 3 commits intoparcel-bundler:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 cache it in alonghand_propertiesvector. The cached properties can then be flushed after the shorthand.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
fontdeclaration is encountered (since they'll all be reset to their defaults anyway). Are there any negative consequences to doing this?