Repository navigation
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.
Fixes #740.
:root { --v: 1px 2px }kept its internal whitespace: theCustomPropertyGrammarbranch trimmed only the ends of the value and wrote the rest verbatim.This collapses runs of two or more whitespace characters to a single space, which is the transform you sketched in #305 ("replace multiple whitespace by a single space, but not when between quotes") and confirmed on #740.
It does not go as far as the issue's expected output. #740 asks for
--v:a,b,cand this gives--v:a, b, c. Collapsing a run keeps the token stream identical, just shorter; dropping the whitespace next to a comma removes a token, which is only safe if you know the grammar, and a custom property's grammar is unknown by construction (the suite has--foo: if(x > 5) this.width = 10). Happy to add the comma case if you want it, but it seemed like the wrong side of that line to cross uninvited.The "not when between quotes" part is why it does not reuse
parse.ReplaceMultipleWhitespace: that one is a raw byte scan and would rewrite--v: "a b". Instead the value is re-lexed and only whitespace tokens are collapsed, so strings, comments andurl()keep their whitespace. Two cases fall out of the tokenizer, both tested:\followed by a newline is not a valid escape, so the backslash is a delim token. Collapsing the newline after it would produce\, a valid escaped space, and change the token stream. Guarded.\41 bbecomes\41 b.A lone whitespace character is left as it is. There is a prescan for two adjacent whitespace bytes so that values with nothing to collapse never reach the lexer; without it a stylesheet of 8000 design tokens was ~44% slower, with it the difference is in the noise.
One behaviour change worth naming:
getComputedStyle().getPropertyValue('--v')returns the specified text, so JS comparing against'1px 2px'would now see'1px 2px'. That is the same class of change as the trimming this branch already does.Checked against master over 300k randomised custom property values: the output differs only by collapsed whitespace runs, the non-whitespace bytes are identical in every case, and all seven files in
tests/css/corpusminify byte-identically.