Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit c6afbc9

Browse files
committed
fix(index): prevent adding scope to percentages with decimals
1 parent e114e7d commit c6afbc9

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

develop/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const fixture = 'develop';
99
const fixturePath = path.join(process.cwd(), 'tests', 'fixtures');
1010
const input = fs.readFileSync(path.join(fixturePath, `${fixture}.css`), 'utf-8');
1111

12-
const write = (result) => fs.writeFileSync(path.join(fixturePath, `${fixture}-processed.css`), result.css, 'utf-8');
12+
const write = (result) => {
13+
console.log(`\n⚡️ ${fixture}-processed.css updated\n`);
14+
15+
fs.writeFileSync(path.join(fixturePath, `${fixture}-processed.css`), result.css);
16+
};
1317

1418
postcss()
1519
.use(plugin)

lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ module.exports = postcss.plugin('postcss-selector-scope', (options = {}) => {
2020
* :root
2121
* from, to and percentages used in keyframes
2222
*/
23-
const defaultExclusions = [/^:root/, /^from/, /^to/, /^\d+%/];
23+
const defaultExclusions = [/^:root/, /^from/, /^to/, /^(\d{1,3}(?:\.\d*)?)%$/];
2424
const allExclusions = settings.exclude.concat(defaultExclusions);
2525
const excludedSelectors = allExclusions.map((value) => {
2626
if (typeof value === 'string') {
27-
return new RegExp(`${value}`, 'i');
27+
return new RegExp(value, 'i');
2828
}
2929

3030
if (value instanceof RegExp) {

tests/fixtures/develop.css

+13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ a:hover,
6262
to {}
6363
}
6464

65+
@keyframes any {
66+
0%,
67+
66.64%,
68+
100% {
69+
color: red;
70+
}
71+
8.33%,
72+
41.65%,
73+
58.31% {
74+
color: red;
75+
}
76+
}
77+
6578
/* media queries */
6679
@media (min-width: 1024px) {
6780
.class {

tests/lib/index.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ describe('postcss-selector-scope', () => {
3232
@keyframes any {
3333
from {}
3434
50% {}
35+
66.34%,
36+
75.123%,
37+
67.2% {}
3538
to {}
3639
}
3740
`;

0 commit comments

Comments
 (0)