Skip to content

Commit

Permalink
fix(postcss-convert-values): keep % unit in @Property (#1531)
Browse files Browse the repository at this point in the history
Co-authored-by: Ludovico Fischer <43557+ludofischer@users.noreply.github.com>
  • Loading branch information
xiaojundebug and ludofischer committed Nov 21, 2023
1 parent e2669ce commit c9d221e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Expand Up @@ -69,3 +69,4 @@ Thanks goes to these wonderful people:
- Jakka Prihatna
- James George
- Jordy D'Hoker
- Xiaojun Zhou
21 changes: 16 additions & 5 deletions packages/postcss-convert-values/src/index.js
Expand Up @@ -118,13 +118,24 @@ function shouldKeepZeroUnit(decl, browsers) {
(decl.value.includes('%') &&
keepZeroPercent.has(lowerCasedProp) &&
browsers.includes('ie 11')) ||
(parent &&
(lowerCasedProp === 'stroke-dasharray' &&
parent &&
parent.parent &&
parent.parent.type === 'atrule' &&
/** @type {import('postcss').AtRule} */ (
parent.parent
).name.toLowerCase() === 'keyframes' &&
lowerCasedProp === 'stroke-dasharray') ||
/** @type {import('postcss').AtRule} */
(parent.parent).name.toLowerCase() === 'keyframes') ||
(lowerCasedProp === 'initial-value' &&
parent &&
parent.type === 'atrule' &&
/** @type {import('postcss').AtRule} */
(parent).name === 'property' &&
/** @type {import('postcss').AtRule} */
(parent).nodes.some(
(node) =>
node.type === 'decl' &&
node.prop.toLowerCase() === 'syntax' &&
node.value === "'<percentage>'"
)) ||
keepWhenZero.has(lowerCasedProp)
);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/postcss-convert-values/test/index.js
Expand Up @@ -430,5 +430,13 @@ test(
)
);

test(
`should not strip the percentage from 0 in @property, for initial-value`,
processCSS(
`@property --percent{syntax:'<percentage>';inherits:false;initial-value:0%;}`,
`@property --percent{syntax:'<percentage>';inherits:false;initial-value:0%;}`,
)
);

test('should use the postcss plugin api', usePostCSSPlugin(plugin()));
test.run();

0 comments on commit c9d221e

Please sign in to comment.