New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(postcss-convert-values): preserve percentage-only properties #1212
Conversation
@@ -18,6 +18,23 @@ const LENGTH_UNITS = [ | |||
'pc', | |||
'px', | |||
]; | |||
|
|||
// These properties only accept percentages, so no point in trying to transform | |||
const notANumber = new Set([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there more of these? Could not find a list of CSS properties grouped by accepted values
@@ -71,7 +88,7 @@ function clampOpacity(node) { | |||
} | |||
} | |||
|
|||
function shouldKeepUnit(decl) { | |||
function shouldKeepZeroUnit(decl) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed this function name because it is only used in the parseWord()
function when num === 0
.
if ( | ||
~lowerCasedProp.indexOf('flex') || | ||
lowerCasedProp.indexOf('--') === 0 || | ||
notANumber.has(lowerCasedProp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip processing completely here, since there is not meaningful possible conversion.
Don't process properties that look like numbers, but only take percentage values according to the spec. Fix #1203
524c382
to
26f5029
Compare
Codecov Report
@@ Coverage Diff @@
## master #1212 +/- ##
=======================================
Coverage 96.53% 96.54%
=======================================
Files 116 116
Lines 3611 3614 +3
Branches 1063 1064 +1
=======================================
+ Hits 3486 3489 +3
Misses 117 117
Partials 8 8
Continue to review full report at Codecov.
|
Don't process properties that look like numbers, but only take percentage values
according to the spec.
Fix #1203
I've found that the original code seems to repeat similar checks in in different places, so I've found the logic a bit confusing, but I have avoided changing too much.