postcss-minify-params 4.0.0-rc.1 → 4.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/README.md CHANGED
@@ -28,12 +28,12 @@ See [PostCSS] docs for examples for your environment.
28
28
 
29
29
  ## Contributors
30
30
 
31
- See [CONTRIBUTORS.md](https://github.com/ben-eb/cssnano/blob/master/CONTRIBUTORS.md).
31
+ See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
32
32
 
33
33
  ## License
34
34
 
35
35
  MIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)
36
36
 
37
37
  [PostCSS]: https://github.com/postcss/postcss
38
- [ci-img]: https://travis-ci.org/ben-eb/postcss-minify-params.svg
39
- [ci]: https://travis-ci.org/ben-eb/postcss-minify-params
38
+ [ci-img]: https://travis-ci.org/cssnano/postcss-minify-params.svg
39
+ [ci]: https://travis-ci.org/cssnano/postcss-minify-params
package/dist/index.js CHANGED
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
7
+ var _browserslist = require('browserslist');
8
+
9
+ var _browserslist2 = _interopRequireDefault(_browserslist);
8
10
 
9
11
  var _postcss = require('postcss');
10
12
 
@@ -38,15 +40,13 @@ function gcd(a, b) {
38
40
  }
39
41
 
40
42
  function aspectRatio(a, b) {
41
- var divisor = gcd(a, b);
43
+ const divisor = gcd(a, b);
42
44
 
43
45
  return [a / divisor, b / divisor];
44
46
  }
45
47
 
46
48
  function split(args) {
47
- return args.map(function (arg) {
48
- return (0, _postcssValueParser.stringify)(arg);
49
- }).join('');
49
+ return args.map(arg => (0, _postcssValueParser.stringify)(arg)).join('');
50
50
  }
51
51
 
52
52
  function removeNode(node) {
@@ -54,25 +54,22 @@ function removeNode(node) {
54
54
  node.type = 'word';
55
55
  }
56
56
 
57
- function transform(rule) {
58
- // We should not re-arrange parameters for css-modules' @value
59
- // at-rule. For example:
60
- //
61
- // @value vertical, center from "./foo.css";
62
- if (!rule.params || rule.name === 'value') {
57
+ function transform(legacy, rule) {
58
+ const ruleName = rule.name.toLowerCase();
59
+
60
+ // We should re-arrange parameters only for `@media` and `@supports` at-rules
61
+ if (!rule.params || !["media", "supports"].includes(ruleName)) {
63
62
  return;
64
63
  }
65
64
 
66
- var params = (0, _postcssValueParser2.default)(rule.params);
65
+ const params = (0, _postcssValueParser2.default)(rule.params);
67
66
 
68
- params.walk(function (node, index) {
67
+ params.walk((node, index) => {
69
68
  if (node.type === 'div' || node.type === 'function') {
70
69
  node.before = node.after = '';
71
- if (node.type === 'function' && node.nodes[4] && node.nodes[0].value.indexOf('-aspect-ratio') === 3) {
72
- var _aspectRatio = aspectRatio(node.nodes[2].value, node.nodes[4].value),
73
- _aspectRatio2 = _slicedToArray(_aspectRatio, 2),
74
- a = _aspectRatio2[0],
75
- b = _aspectRatio2[1];
70
+
71
+ if (node.type === 'function' && node.nodes[4] && node.nodes[0].value.toLowerCase().indexOf('-aspect-ratio') === 3) {
72
+ const [a, b] = aspectRatio(node.nodes[2].value, node.nodes[4].value);
76
73
 
77
74
  node.nodes[2].value = a;
78
75
  node.nodes[4].value = b;
@@ -80,17 +77,23 @@ function transform(rule) {
80
77
  } else if (node.type === 'space') {
81
78
  node.value = ' ';
82
79
  } else {
83
- var prevWord = params.nodes[index - 2];
84
- if (node.value === 'all' && rule.name === 'media' && !prevWord) {
85
- var nextSpace = params.nodes[index + 1];
86
- var nextWord = params.nodes[index + 2];
87
- var secondSpace = params.nodes[index + 3];
88
- if (nextWord && nextWord.value === 'and') {
80
+ const prevWord = params.nodes[index - 2];
81
+
82
+ if (node.value.toLowerCase() === 'all' && rule.name.toLowerCase() === 'media' && !prevWord) {
83
+ const nextWord = params.nodes[index + 2];
84
+
85
+ if (!legacy || nextWord) {
86
+ removeNode(node);
87
+ }
88
+
89
+ if (nextWord && nextWord.value.toLowerCase() === 'and') {
90
+ const nextSpace = params.nodes[index + 1];
91
+ const secondSpace = params.nodes[index + 3];
92
+
89
93
  removeNode(nextWord);
90
94
  removeNode(nextSpace);
91
95
  removeNode(secondSpace);
92
96
  }
93
- removeNode(node);
94
97
  }
95
98
  }
96
99
  }, true);
@@ -104,9 +107,20 @@ function transform(rule) {
104
107
  }
105
108
  }
106
109
 
107
- exports.default = _postcss2.default.plugin('postcss-minify-params', function () {
108
- return function (css) {
109
- return css.walkAtRules(transform);
110
+ function hasAllBug(browser) {
111
+ return ~['ie 10', 'ie 11'].indexOf(browser);
112
+ }
113
+
114
+ exports.default = _postcss2.default.plugin('postcss-minify-params', () => {
115
+ return (css, result) => {
116
+ const resultOpts = result.opts || {};
117
+ const browsers = (0, _browserslist2.default)(null, {
118
+ stats: resultOpts.stats,
119
+ path: __dirname,
120
+ env: resultOpts.env
121
+ });
122
+
123
+ return css.walkAtRules(transform.bind(null, browsers.some(hasAllBug)));
110
124
  };
111
125
  });
112
126
  module.exports = exports['default'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-minify-params",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.2",
4
4
  "description": "Minify at-rule params with PostCSS",
5
5
  "keywords": [
6
6
  "postcss",
@@ -16,15 +16,16 @@
16
16
  ],
17
17
  "author": "Bogdan Chadkin <trysound@yandex.ru>",
18
18
  "license": "MIT",
19
- "repository": "ben-eb/cssnano",
19
+ "repository": "cssnano/cssnano",
20
20
  "bugs": {
21
- "url": "https://github.com/ben-eb/cssnano/issues"
21
+ "url": "https://github.com/cssnano/cssnano/issues"
22
22
  },
23
- "homepage": "https://github.com/ben-eb/cssnano",
23
+ "homepage": "https://github.com/cssnano/cssnano",
24
24
  "dependencies": {
25
25
  "alphanum-sort": "^1.0.0",
26
- "cssnano-util-get-arguments": "^4.0.0-rc.0",
27
- "postcss": "^6.0.0",
26
+ "browserslist": "^4.0.0",
27
+ "cssnano-util-get-arguments": "^4.0.0",
28
+ "postcss": "^7.0.0",
28
29
  "postcss-value-parser": "^3.0.0",
29
30
  "uniqs": "^2.0.0"
30
31
  },
@@ -33,9 +34,9 @@
33
34
  },
34
35
  "devDependencies": {
35
36
  "babel-cli": "^6.0.0",
36
- "cross-env": "^3.0.0"
37
+ "cross-env": "^5.0.0"
37
38
  },
38
39
  "engines": {
39
- "node": ">=4"
40
+ "node": ">=6.9.0"
40
41
  }
41
42
  }
package/CHANGELOG.md DELETED
@@ -1,36 +0,0 @@
1
- # Head
2
-
3
- * Resolves an issue with mangling css-modules' `@value` at-rule.
4
-
5
- # 4.0.0-rc.0
6
-
7
- * Breaking: Drops support for Node 0.12, we now require at least Node 4.
8
- * Breaking: Update PostCSS to 6.0.0.
9
-
10
- # 1.2.2
11
-
12
- * Resolves an issue where `all and` would be removed from
13
- `@media not all and (conditions) {}`, causing an invalid media query to
14
- be output.
15
-
16
- # 1.2.1
17
-
18
- * Resolves an issue where `1.2.0` would throw on empty function parentheses.
19
-
20
- # 1.2.0
21
-
22
- * Adds support for simplifying `min-aspect-ratio` and `max-aspect-ratio`. For
23
- example, `@media (min-aspect-ratio: 1280/720) {}` can be minified to
24
- `@media (min-aspect-ratio:16/9){}`.
25
-
26
- # 1.1.0
27
-
28
- * Adds support for removing the unnecessary `all and` from media queries.
29
-
30
- # 1.0.1
31
-
32
- * Refactor to ES6.
33
-
34
- # 1.0.0
35
-
36
- * Initial release.