postcss-merge-rules 5.0.0-rc.1 → 5.0.2

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 CHANGED
@@ -7,23 +7,17 @@ exports.default = void 0;
7
7
 
8
8
  var _browserslist = _interopRequireDefault(require("browserslist"));
9
9
 
10
- var _vendors = _interopRequireDefault(require("vendors"));
11
-
12
10
  var _cssnanoUtils = require("cssnano-utils");
13
11
 
14
- var _ensureCompatibility = _interopRequireDefault(require("./lib/ensureCompatibility"));
12
+ var _ensureCompatibility = require("./lib/ensureCompatibility");
15
13
 
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
 
18
- /** @type {string[]} */
19
- const prefixes = _vendors.default.map(v => `-${v}-`);
20
16
  /**
21
17
  * @param {postcss.Declaration} a
22
18
  * @param {postcss.Declaration} b
23
19
  * @return {boolean}
24
20
  */
25
-
26
-
27
21
  function declarationIsEqual(a, b) {
28
22
  return a.important === b.important && a.prop === b.prop && a.value === b.value;
29
23
  }
@@ -65,36 +59,6 @@ function sameDeclarationsAndOrder(a, b) {
65
59
  }
66
60
 
67
61
  return a.every((d, index) => declarationIsEqual(d, b[index]));
68
- } // Internet Explorer use :-ms-input-placeholder.
69
- // Microsoft Edge use ::-ms-input-placeholder.
70
-
71
-
72
- const findMsInputPlaceholder = selector => ~selector.search(/-ms-input-placeholder/i);
73
- /**
74
- * @param {string} selector
75
- * @return {string[]}
76
- */
77
-
78
-
79
- function filterPrefixes(selector) {
80
- return prefixes.filter(prefix => selector.indexOf(prefix) !== -1);
81
- }
82
-
83
- function sameVendor(selectorsA, selectorsB) {
84
- let same = selectors => selectors.map(filterPrefixes).join();
85
-
86
- let findMsVendor = selectors => selectors.find(findMsInputPlaceholder);
87
-
88
- return same(selectorsA) === same(selectorsB) && !(findMsVendor(selectorsA) && findMsVendor(selectorsB));
89
- }
90
- /**
91
- * @param {string} selector
92
- * @return {boolean}
93
- */
94
-
95
-
96
- function noVendor(selector) {
97
- return !filterPrefixes(selector).length;
98
62
  }
99
63
  /**
100
64
  * @param {postcss.Rule} ruleA
@@ -110,7 +74,7 @@ function canMerge(ruleA, ruleB, browsers, compatibilityCache) {
110
74
  const b = ruleB.selectors;
111
75
  const selectors = a.concat(b);
112
76
 
113
- if (!(0, _ensureCompatibility.default)(selectors, browsers, compatibilityCache)) {
77
+ if (!(0, _ensureCompatibility.ensureCompatibility)(selectors, browsers, compatibilityCache)) {
114
78
  return false;
115
79
  }
116
80
 
@@ -123,7 +87,7 @@ function canMerge(ruleA, ruleB, browsers, compatibilityCache) {
123
87
  return false;
124
88
  }
125
89
 
126
- return parent && (selectors.every(noVendor) || sameVendor(a, b));
90
+ return parent && (selectors.every(_ensureCompatibility.noVendor) || (0, _ensureCompatibility.sameVendor)(a, b));
127
91
  }
128
92
  /**
129
93
  * @param {postcss.Rule} rule
@@ -268,24 +232,24 @@ function partialMerge(first, second) {
268
232
  const firstDecls = getDecls(first); // Filter out intersections with later conflicts in First
269
233
 
270
234
  intersection = intersection.filter((decl, intersectIndex) => {
271
- const index = indexOfDeclaration(firstDecls, decl);
272
- const nextConflictInFirst = firstDecls.slice(index + 1).find(d => isConflictingProp(d.prop, decl.prop));
235
+ const indexOfDecl = indexOfDeclaration(firstDecls, decl);
236
+ const nextConflictInFirst = firstDecls.slice(indexOfDecl + 1).filter(d => isConflictingProp(d.prop, decl.prop));
273
237
 
274
- if (!nextConflictInFirst) {
238
+ if (!nextConflictInFirst.length) {
275
239
  return true;
276
240
  }
277
241
 
278
- const nextConflictInIntersection = intersection.slice(intersectIndex + 1).find(d => isConflictingProp(d.prop, decl.prop));
242
+ const nextConflictInIntersection = intersection.slice(intersectIndex + 1).filter(d => isConflictingProp(d.prop, decl.prop));
279
243
 
280
- if (!nextConflictInIntersection) {
244
+ if (!nextConflictInIntersection.length) {
281
245
  return false;
282
246
  }
283
247
 
284
- if (declarationIsEqual(nextConflictInFirst, nextConflictInIntersection)) {
285
- return true;
248
+ if (nextConflictInFirst.length !== nextConflictInIntersection.length) {
249
+ return false;
286
250
  }
287
251
 
288
- return false;
252
+ return nextConflictInFirst.every((d, index) => declarationIsEqual(d, nextConflictInIntersection[index]));
289
253
  }); // Filter out intersections with previous conflicts in Second
290
254
 
291
255
  const secondDecls = getDecls(second);
@@ -3,13 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = ensureCompatibility;
6
+ exports.filterPrefixes = filterPrefixes;
7
+ exports.sameVendor = sameVendor;
8
+ exports.noVendor = noVendor;
9
+ exports.ensureCompatibility = ensureCompatibility;
7
10
  exports.pseudoElements = void 0;
8
11
 
9
12
  var _caniuseApi = require("caniuse-api");
10
13
 
11
14
  var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
12
15
 
16
+ var _vendors = _interopRequireDefault(require("vendors"));
17
+
13
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
19
 
15
20
  const simpleSelectorRe = /^#?[-._a-z0-9 ]+$/i;
@@ -19,9 +24,45 @@ const cssGencontent = 'css-gencontent';
19
24
  const cssFirstLetter = 'css-first-letter';
20
25
  const cssFirstLine = 'css-first-line';
21
26
  const cssInOutOfRange = 'css-in-out-of-range';
27
+ const formValidation = 'form-validation';
28
+ /** @type {string[]} */
29
+
30
+ const prefixes = _vendors.default.map(v => `-${v}-`);
31
+ /**
32
+ * @param {string} selector
33
+ * @return {string[]}
34
+ */
35
+
36
+
37
+ function filterPrefixes(selector) {
38
+ return prefixes.filter(prefix => selector.indexOf(prefix) !== -1);
39
+ } // Internet Explorer use :-ms-input-placeholder.
40
+ // Microsoft Edge use ::-ms-input-placeholder.
41
+
42
+
43
+ const findMsInputPlaceholder = selector => ~selector.search(/-ms-input-placeholder/i);
44
+
45
+ function sameVendor(selectorsA, selectorsB) {
46
+ let same = selectors => selectors.map(filterPrefixes).join();
47
+
48
+ let findMsVendor = selectors => selectors.find(findMsInputPlaceholder);
49
+
50
+ return same(selectorsA) === same(selectorsB) && !(findMsVendor(selectorsA) && findMsVendor(selectorsB));
51
+ }
52
+ /**
53
+ * @param {string} selector
54
+ * @return {boolean}
55
+ */
56
+
57
+
58
+ function noVendor(selector) {
59
+ return !filterPrefixes(selector).length;
60
+ }
61
+
22
62
  const pseudoElements = {
23
63
  ':active': cssSel2,
24
64
  ':after': cssGencontent,
65
+ ':any-link': 'css-any-link',
25
66
  ':before': cssGencontent,
26
67
  ':checked': cssSel3,
27
68
  ':default': 'css-default-pseudo',
@@ -40,9 +81,12 @@ const pseudoElements = {
40
81
  ':hover': cssSel2,
41
82
  ':in-range': cssInOutOfRange,
42
83
  ':indeterminate': 'css-indeterminate-pseudo',
84
+ ':invalid': formValidation,
85
+ ':is': 'css-matches-pseudo',
43
86
  ':lang': cssSel2,
44
87
  ':last-child': cssSel3,
45
88
  ':last-of-type': cssSel3,
89
+ ':link': cssSel2,
46
90
  ':matches': 'css-matches-pseudo',
47
91
  ':not': cssSel3,
48
92
  ':nth-child': cssSel3,
@@ -54,6 +98,7 @@ const pseudoElements = {
54
98
  ':optional': 'css-optional-pseudo',
55
99
  ':out-of-range': cssInOutOfRange,
56
100
  ':placeholder-shown': 'css-placeholder-shown',
101
+ ':required': formValidation,
57
102
  ':root': cssSel3,
58
103
  ':target': cssSel3,
59
104
  '::after': cssGencontent,
@@ -63,7 +108,9 @@ const pseudoElements = {
63
108
  '::first-line': cssFirstLine,
64
109
  '::marker': 'css-marker-pseudo',
65
110
  '::placeholder': 'css-placeholder',
66
- '::selection': 'css-selection'
111
+ '::selection': 'css-selection',
112
+ ':valid': formValidation,
113
+ ':visited': cssSel2
67
114
  };
68
115
  exports.pseudoElements = pseudoElements;
69
116
 
@@ -71,6 +118,10 @@ function isCssMixin(selector) {
71
118
  return selector[selector.length - 1] === ':';
72
119
  }
73
120
 
121
+ function isHostPseudoClass(selector) {
122
+ return selector.includes(':host');
123
+ }
124
+
74
125
  const isSupportedCache = {}; // Move to util in future
75
126
 
76
127
  function isSupportedCached(feature, browsers) {
@@ -92,6 +143,11 @@ function ensureCompatibility(selectors, browsers, compatibilityCache) {
92
143
  // Should not merge mixins
93
144
  if (selectors.some(isCssMixin)) {
94
145
  return false;
146
+ } // Should not merge :host selector https://github.com/angular/angular-cli/issues/18672
147
+
148
+
149
+ if (selectors.some(isHostPseudoClass)) {
150
+ return false;
95
151
  }
96
152
 
97
153
  return selectors.every(selector => {
@@ -114,6 +170,10 @@ function ensureCompatibility(selectors, browsers, compatibilityCache) {
114
170
  if (type === 'pseudo') {
115
171
  const entry = pseudoElements[value];
116
172
 
173
+ if (!entry && noVendor(value)) {
174
+ compatible = false;
175
+ }
176
+
117
177
  if (entry && compatible) {
118
178
  compatible = isSupportedCached(entry, browsers);
119
179
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-merge-rules",
3
- "version": "5.0.0-rc.1",
3
+ "version": "5.0.2",
4
4
  "description": "Merge CSS rules with PostCSS.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "prebuild": "del-cli dist",
12
- "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
12
+ "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\"",
13
13
  "prepublish": "yarn build"
14
14
  },
15
15
  "keywords": [
@@ -27,10 +27,10 @@
27
27
  },
28
28
  "repository": "cssnano/cssnano",
29
29
  "dependencies": {
30
- "browserslist": "^4.16.0",
30
+ "browserslist": "^4.16.6",
31
31
  "caniuse-api": "^3.0.0",
32
- "cssnano-utils": "^2.0.0-rc.1",
33
- "postcss-selector-parser": "^6.0.4",
32
+ "cssnano-utils": "^2.0.1",
33
+ "postcss-selector-parser": "^6.0.5",
34
34
  "vendors": "^1.0.3"
35
35
  },
36
36
  "bugs": {
@@ -40,10 +40,10 @@
40
40
  "node": "^10 || ^12 || >=14.0"
41
41
  },
42
42
  "devDependencies": {
43
- "postcss": "^8.2.1"
43
+ "postcss": "^8.2.15"
44
44
  },
45
45
  "peerDependencies": {
46
- "postcss": "^8.2.1"
46
+ "postcss": "^8.2.15"
47
47
  },
48
- "gitHead": "114efb0092fff944dd4c8a28d184add24d8fde3e"
48
+ "gitHead": "9b3c54fd94f3e2bdb503d1e21f171d7fe02f33ca"
49
49
  }
package/CHANGELOG.md DELETED
@@ -1,59 +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.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)
7
-
8
- **Note:** Version bump only for package postcss-merge-rules
9
-
10
-
11
-
12
-
13
-
14
- # 5.0.0-rc.0 (2021-02-19)
15
-
16
-
17
- ### Bug Fixes
18
-
19
- * don't unsafe merge 'all' declaration ([#872](https://github.com/cssnano/cssnano/issues/872)) ([6ea9e5d](https://github.com/cssnano/cssnano/commit/6ea9e5dcad2d8ea22be7209332ee29d352c807de))
20
- * focus-visible issue ([#882](https://github.com/cssnano/cssnano/issues/882)) ([4cfcaaf](https://github.com/cssnano/cssnano/commit/4cfcaaf25b162ec2b0308907a408d7dba6a354c3))
21
- * **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))
22
- * **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))
23
-
24
-
25
- ### chore
26
-
27
- * minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
28
-
29
-
30
- ### Features
31
-
32
- * migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
33
- * **postcss-merge-rules:** merge at-rules ([#722](https://github.com/cssnano/cssnano/issues/722)) ([8d4610a](https://github.com/cssnano/cssnano/commit/8d4610a6391ddab29bcb08ef0522d0b7ce2d6582))
34
-
35
-
36
- ### BREAKING CHANGES
37
-
38
- * minimum supported `postcss` version is `8.2.1`
39
- * minimum require version of node is 10.13
40
-
41
-
42
-
43
- ## 4.1.9 (2019-02-12)
44
-
45
-
46
- ### Performance Improvements
47
-
48
- * **postcss-merge-rules:** increase perf ([#681](https://github.com/cssnano/cssnano/issues/681)) ([35bad2b](https://github.com/cssnano/cssnano/commit/35bad2b70fca5390c88eaabc24c25bb8d28b2f95))
49
-
50
-
51
-
52
- ## 4.1.1 (2018-09-24)
53
-
54
-
55
- ### Bug Fixes
56
-
57
- * handle uppercase `all` property in merge rules ([#611](https://github.com/cssnano/cssnano/issues/611)) ([0dfe335](https://github.com/cssnano/cssnano/commit/0dfe3355951fa4a080a04dca34c6d99420def7ac))
58
- * merge same atrules with difference case ([#605](https://github.com/cssnano/cssnano/issues/605)) ([ca350fd](https://github.com/cssnano/cssnano/commit/ca350fda779bab5ca2eadf70299d92f8e495a273))
59
- * **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)