postcss-merge-rules 5.0.1 → 5.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +12 -12
- package/dist/lib/ensureCompatibility.js +15 -21
- package/package.json +12 -13
- package/CHANGELOG.md +0 -87
package/dist/index.js
CHANGED
|
@@ -64,7 +64,7 @@ function sameDeclarationsAndOrder(a, b) {
|
|
|
64
64
|
* @param {postcss.Rule} ruleA
|
|
65
65
|
* @param {postcss.Rule} ruleB
|
|
66
66
|
* @param {string[]=} browsers
|
|
67
|
-
* @param {
|
|
67
|
+
* @param {Map<string, boolean>=} compatibilityCache
|
|
68
68
|
* @return {boolean}
|
|
69
69
|
*/
|
|
70
70
|
|
|
@@ -83,7 +83,7 @@ function canMerge(ruleA, ruleB, browsers, compatibilityCache) {
|
|
|
83
83
|
name
|
|
84
84
|
} = ruleA.parent;
|
|
85
85
|
|
|
86
|
-
if (parent && name &&
|
|
86
|
+
if (parent && name && name.includes('keyframes')) {
|
|
87
87
|
return false;
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -232,24 +232,24 @@ function partialMerge(first, second) {
|
|
|
232
232
|
const firstDecls = getDecls(first); // Filter out intersections with later conflicts in First
|
|
233
233
|
|
|
234
234
|
intersection = intersection.filter((decl, intersectIndex) => {
|
|
235
|
-
const
|
|
236
|
-
const nextConflictInFirst = firstDecls.slice(
|
|
235
|
+
const indexOfDecl = indexOfDeclaration(firstDecls, decl);
|
|
236
|
+
const nextConflictInFirst = firstDecls.slice(indexOfDecl + 1).filter(d => isConflictingProp(d.prop, decl.prop));
|
|
237
237
|
|
|
238
|
-
if (!nextConflictInFirst) {
|
|
238
|
+
if (!nextConflictInFirst.length) {
|
|
239
239
|
return true;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
const nextConflictInIntersection = intersection.slice(intersectIndex + 1).
|
|
242
|
+
const nextConflictInIntersection = intersection.slice(intersectIndex + 1).filter(d => isConflictingProp(d.prop, decl.prop));
|
|
243
243
|
|
|
244
|
-
if (!nextConflictInIntersection) {
|
|
244
|
+
if (!nextConflictInIntersection.length) {
|
|
245
245
|
return false;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
if (
|
|
249
|
-
return
|
|
248
|
+
if (nextConflictInFirst.length !== nextConflictInIntersection.length) {
|
|
249
|
+
return false;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
return
|
|
252
|
+
return nextConflictInFirst.every((d, index) => declarationIsEqual(d, nextConflictInIntersection[index]));
|
|
253
253
|
}); // Filter out intersections with previous conflicts in Second
|
|
254
254
|
|
|
255
255
|
const secondDecls = getDecls(second);
|
|
@@ -325,7 +325,7 @@ function partialMerge(first, second) {
|
|
|
325
325
|
}
|
|
326
326
|
/**
|
|
327
327
|
* @param {string[]} browsers
|
|
328
|
-
* @param {
|
|
328
|
+
* @param {Map<string, boolean>} compatibilityCache
|
|
329
329
|
* @return {function(postcss.Rule)}
|
|
330
330
|
*/
|
|
331
331
|
|
|
@@ -391,7 +391,7 @@ function pluginCreator() {
|
|
|
391
391
|
path: __dirname,
|
|
392
392
|
env: resultOpts.env
|
|
393
393
|
});
|
|
394
|
-
const compatibilityCache =
|
|
394
|
+
const compatibilityCache = new Map();
|
|
395
395
|
return {
|
|
396
396
|
OnceExit(css) {
|
|
397
397
|
css.walkRules(selectorMerger(browsers, compatibilityCache));
|
|
@@ -3,18 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.filterPrefixes = filterPrefixes;
|
|
7
|
-
exports.sameVendor = sameVendor;
|
|
8
|
-
exports.noVendor = noVendor;
|
|
9
6
|
exports.ensureCompatibility = ensureCompatibility;
|
|
7
|
+
exports.noVendor = noVendor;
|
|
10
8
|
exports.pseudoElements = void 0;
|
|
9
|
+
exports.sameVendor = sameVendor;
|
|
11
10
|
|
|
12
11
|
var _caniuseApi = require("caniuse-api");
|
|
13
12
|
|
|
14
13
|
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
15
14
|
|
|
16
|
-
var _vendors = _interopRequireDefault(require("vendors"));
|
|
17
|
-
|
|
18
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
16
|
|
|
20
17
|
const simpleSelectorRe = /^#?[-._a-z0-9 ]+$/i;
|
|
@@ -25,17 +22,14 @@ const cssFirstLetter = 'css-first-letter';
|
|
|
25
22
|
const cssFirstLine = 'css-first-line';
|
|
26
23
|
const cssInOutOfRange = 'css-in-out-of-range';
|
|
27
24
|
const formValidation = 'form-validation';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const prefixes = _vendors.default.map(v => `-${v}-`);
|
|
25
|
+
const vendorPrefix = /-(ah|apple|atsc|epub|hp|khtml|moz|ms|o|rim|ro|tc|wap|webkit|xv)-/;
|
|
31
26
|
/**
|
|
32
27
|
* @param {string} selector
|
|
33
28
|
* @return {string[]}
|
|
34
29
|
*/
|
|
35
30
|
|
|
36
|
-
|
|
37
31
|
function filterPrefixes(selector) {
|
|
38
|
-
return
|
|
32
|
+
return selector.match(vendorPrefix);
|
|
39
33
|
} // Internet Explorer use :-ms-input-placeholder.
|
|
40
34
|
// Microsoft Edge use ::-ms-input-placeholder.
|
|
41
35
|
|
|
@@ -56,7 +50,7 @@ function sameVendor(selectorsA, selectorsB) {
|
|
|
56
50
|
|
|
57
51
|
|
|
58
52
|
function noVendor(selector) {
|
|
59
|
-
return !
|
|
53
|
+
return !vendorPrefix.test(selector);
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
const pseudoElements = {
|
|
@@ -122,18 +116,18 @@ function isHostPseudoClass(selector) {
|
|
|
122
116
|
return selector.includes(':host');
|
|
123
117
|
}
|
|
124
118
|
|
|
125
|
-
const isSupportedCache =
|
|
119
|
+
const isSupportedCache = new Map(); // Move to util in future
|
|
126
120
|
|
|
127
121
|
function isSupportedCached(feature, browsers) {
|
|
128
122
|
const key = JSON.stringify({
|
|
129
123
|
feature,
|
|
130
124
|
browsers
|
|
131
125
|
});
|
|
132
|
-
let result = isSupportedCache
|
|
126
|
+
let result = isSupportedCache.get(key);
|
|
133
127
|
|
|
134
128
|
if (!result) {
|
|
135
129
|
result = (0, _caniuseApi.isSupported)(feature, browsers);
|
|
136
|
-
isSupportedCache
|
|
130
|
+
isSupportedCache.set(key, result);
|
|
137
131
|
}
|
|
138
132
|
|
|
139
133
|
return result;
|
|
@@ -155,8 +149,8 @@ function ensureCompatibility(selectors, browsers, compatibilityCache) {
|
|
|
155
149
|
return true;
|
|
156
150
|
}
|
|
157
151
|
|
|
158
|
-
if (compatibilityCache && selector
|
|
159
|
-
return compatibilityCache
|
|
152
|
+
if (compatibilityCache && compatibilityCache.has(selector)) {
|
|
153
|
+
return compatibilityCache.get(selector);
|
|
160
154
|
}
|
|
161
155
|
|
|
162
156
|
let compatible = true;
|
|
@@ -180,11 +174,11 @@ function ensureCompatibility(selectors, browsers, compatibilityCache) {
|
|
|
180
174
|
}
|
|
181
175
|
|
|
182
176
|
if (type === 'combinator') {
|
|
183
|
-
if (
|
|
177
|
+
if (value.includes('~')) {
|
|
184
178
|
compatible = isSupportedCached(cssSel3, browsers);
|
|
185
179
|
}
|
|
186
180
|
|
|
187
|
-
if (
|
|
181
|
+
if (value.includes('>') || value.includes('+')) {
|
|
188
182
|
compatible = isSupportedCached(cssSel2, browsers);
|
|
189
183
|
}
|
|
190
184
|
}
|
|
@@ -197,12 +191,12 @@ function ensureCompatibility(selectors, browsers, compatibilityCache) {
|
|
|
197
191
|
|
|
198
192
|
if (value) {
|
|
199
193
|
// [foo="bar"], [foo~="bar"], [foo|="bar"]
|
|
200
|
-
if (
|
|
194
|
+
if (['=', '~=', '|='].includes(node.operator)) {
|
|
201
195
|
compatible = isSupportedCached(cssSel2, browsers);
|
|
202
196
|
} // [foo^="bar"], [foo$="bar"], [foo*="bar"]
|
|
203
197
|
|
|
204
198
|
|
|
205
|
-
if (
|
|
199
|
+
if (['^=', '$=', '*='].includes(node.operator)) {
|
|
206
200
|
compatible = isSupportedCached(cssSel3, browsers);
|
|
207
201
|
}
|
|
208
202
|
} // [foo="bar" i]
|
|
@@ -222,7 +216,7 @@ function ensureCompatibility(selectors, browsers, compatibilityCache) {
|
|
|
222
216
|
}).processSync(selector);
|
|
223
217
|
|
|
224
218
|
if (compatibilityCache) {
|
|
225
|
-
compatibilityCache
|
|
219
|
+
compatibilityCache.set(selector, compatible);
|
|
226
220
|
}
|
|
227
221
|
|
|
228
222
|
return compatible;
|
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-merge-rules",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.5",
|
|
4
4
|
"description": "Merge CSS rules with PostCSS.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"LICENSE-MIT",
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prebuild": "del-cli dist",
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
-
"prepublish": "yarn build"
|
|
14
|
-
},
|
|
15
10
|
"keywords": [
|
|
16
11
|
"css",
|
|
17
12
|
"optimise",
|
|
@@ -27,11 +22,10 @@
|
|
|
27
22
|
},
|
|
28
23
|
"repository": "cssnano/cssnano",
|
|
29
24
|
"dependencies": {
|
|
30
|
-
"browserslist": "^4.16.
|
|
25
|
+
"browserslist": "^4.16.6",
|
|
31
26
|
"caniuse-api": "^3.0.0",
|
|
32
|
-
"cssnano-utils": "^
|
|
33
|
-
"postcss-selector-parser": "^6.0.5"
|
|
34
|
-
"vendors": "^1.0.3"
|
|
27
|
+
"cssnano-utils": "^3.0.1",
|
|
28
|
+
"postcss-selector-parser": "^6.0.5"
|
|
35
29
|
},
|
|
36
30
|
"bugs": {
|
|
37
31
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
@@ -40,10 +34,15 @@
|
|
|
40
34
|
"node": "^10 || ^12 || >=14.0"
|
|
41
35
|
},
|
|
42
36
|
"devDependencies": {
|
|
43
|
-
"postcss": "^8.2.15"
|
|
37
|
+
"postcss": "^8.2.15",
|
|
38
|
+
"postcss-discard-comments": "^5.0.2"
|
|
44
39
|
},
|
|
45
40
|
"peerDependencies": {
|
|
46
41
|
"postcss": "^8.2.15"
|
|
47
42
|
},
|
|
48
|
-
"
|
|
49
|
-
|
|
43
|
+
"scripts": {
|
|
44
|
+
"prebuild": "rimraf dist",
|
|
45
|
+
"build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
|
|
46
|
+
},
|
|
47
|
+
"readme": "# [postcss][postcss]-merge-rules\n\n> Merge CSS rules with PostCSS.\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-merge-rules) do:\n\n```\nnpm install postcss-merge-rules --save\n```\n\n## Examples\n\nThis module will attempt to merge *adjacent* CSS rules:\n\n### By declarations\n\n#### Input\n\n```css\na {\n color: blue;\n font-weight: bold\n}\n\np {\n color: blue;\n font-weight: bold\n}\n```\n\n#### Output\n\n```css\na,p {\n color: blue;\n font-weight: bold\n}\n```\n\n### By selectors\n\n#### Input\n\n```css\na {\n color: blue\n}\n\na {\n font-weight: bold\n}\n```\n\n#### Output\n\n```css\na {\n color: blue;\n font-weight: bold\n}\n```\n\n### By partial declarations\n\n#### Input\n\n```css\na {\n font-weight: bold\n}\n\np {\n color: blue;\n font-weight: bold\n}\n```\n\n#### Output\n\n```css\na,p {\n font-weight: bold\n}\n\np {\n color: blue\n}\n```\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[postcss]: https://github.com/postcss/postcss\n"
|
|
48
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [5.0.1](https://github.com/cssnano/cssnano/compare/postcss-merge-rules@5.0.0...postcss-merge-rules@5.0.1) (2021-05-19)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Bug Fixes
|
|
10
|
-
|
|
11
|
-
* **postcss-merge-rules:** add some missing known pseudo classes. ([#1099](https://github.com/cssnano/cssnano/issues/1099)) ([4d7fe36](https://github.com/cssnano/cssnano/commit/4d7fe367bebab86c7b5664ed4621ee7586ca7d86))
|
|
12
|
-
* **postcss-merge-rules:** prevent breaking rule merges ([#1072](https://github.com/cssnano/cssnano/issues/1072)) ([c5e0a5e](https://github.com/cssnano/cssnano/commit/c5e0a5eac171089ae994fcba21d9c565fb462577)), closes [#999](https://github.com/cssnano/cssnano/issues/999)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-merge-rules@5.0.0-rc.2...postcss-merge-rules@5.0.0) (2021-04-06)
|
|
19
|
-
|
|
20
|
-
**Note:** Version bump only for package postcss-merge-rules
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
# [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-merge-rules@5.0.0-rc.1...postcss-merge-rules@5.0.0-rc.2) (2021-03-15)
|
|
27
|
-
|
|
28
|
-
**Note:** Version bump only for package postcss-merge-rules
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-merge-rules@5.0.0-rc.0...postcss-merge-rules@5.0.0-rc.1) (2021-03-04)
|
|
35
|
-
|
|
36
|
-
**Note:** Version bump only for package postcss-merge-rules
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# 5.0.0-rc.0 (2021-02-19)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
### Bug Fixes
|
|
46
|
-
|
|
47
|
-
* don't unsafe merge 'all' declaration ([#872](https://github.com/cssnano/cssnano/issues/872)) ([6ea9e5d](https://github.com/cssnano/cssnano/commit/6ea9e5dcad2d8ea22be7209332ee29d352c807de))
|
|
48
|
-
* focus-visible issue ([#882](https://github.com/cssnano/cssnano/issues/882)) ([4cfcaaf](https://github.com/cssnano/cssnano/commit/4cfcaaf25b162ec2b0308907a408d7dba6a354c3))
|
|
49
|
-
* **merge-rules, merge-idents:** add support for nested at-rules ([#719](https://github.com/cssnano/cssnano/issues/719)) ([cdedda7](https://github.com/cssnano/cssnano/commit/cdedda7f9d67873d872add044ad34c91616579f3))
|
|
50
|
-
* **postcss-merge-rules:** don't change specificity of prefixed properties ([#723](https://github.com/cssnano/cssnano/issues/723)) ([863cf2b](https://github.com/cssnano/cssnano/commit/863cf2b3470d3172523a3165dc368abcfa18809c))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
### chore
|
|
54
|
-
|
|
55
|
-
* minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### Features
|
|
59
|
-
|
|
60
|
-
* migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
|
|
61
|
-
* **postcss-merge-rules:** merge at-rules ([#722](https://github.com/cssnano/cssnano/issues/722)) ([8d4610a](https://github.com/cssnano/cssnano/commit/8d4610a6391ddab29bcb08ef0522d0b7ce2d6582))
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
### BREAKING CHANGES
|
|
65
|
-
|
|
66
|
-
* minimum supported `postcss` version is `8.2.1`
|
|
67
|
-
* minimum require version of node is 10.13
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
## 4.1.9 (2019-02-12)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
### Performance Improvements
|
|
75
|
-
|
|
76
|
-
* **postcss-merge-rules:** increase perf ([#681](https://github.com/cssnano/cssnano/issues/681)) ([35bad2b](https://github.com/cssnano/cssnano/commit/35bad2b70fca5390c88eaabc24c25bb8d28b2f95))
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
## 4.1.1 (2018-09-24)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
### Bug Fixes
|
|
84
|
-
|
|
85
|
-
* handle uppercase `all` property in merge rules ([#611](https://github.com/cssnano/cssnano/issues/611)) ([0dfe335](https://github.com/cssnano/cssnano/commit/0dfe3355951fa4a080a04dca34c6d99420def7ac))
|
|
86
|
-
* merge same atrules with difference case ([#605](https://github.com/cssnano/cssnano/issues/605)) ([ca350fd](https://github.com/cssnano/cssnano/commit/ca350fda779bab5ca2eadf70299d92f8e495a273))
|
|
87
|
-
* **postcss-merge-longhand:** not mangle border output ([#555](https://github.com/cssnano/cssnano/issues/555)) ([9a70605](https://github.com/cssnano/cssnano/commit/9a706050b621e7795a9bf74eb7110b5c81804ffe)), closes [#553](https://github.com/cssnano/cssnano/issues/553) [#554](https://github.com/cssnano/cssnano/issues/554)
|