postcss-merge-rules 5.0.0 → 5.0.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
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
+
6
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)
7
19
 
8
20
  **Note:** Version bump only for package postcss-merge-rules
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
@@ -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",
3
+ "version": "5.0.1",
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": [
@@ -29,8 +29,8 @@
29
29
  "dependencies": {
30
30
  "browserslist": "^4.16.0",
31
31
  "caniuse-api": "^3.0.0",
32
- "cssnano-utils": "^2.0.0",
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": "0e2c3bf5835bafcdc8783bef66f730a24194c8f3"
48
+ "gitHead": "28c247175032fa03f04911cde56ad82d74d211cc"
49
49
  }