postcss-minify-params 4.0.0-rc.2 → 4.0.0

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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/dist/index.js +34 -25
  3. package/package.json +8 -7
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,43 +54,41 @@ function removeNode(node) {
54
54
  node.type = 'word';
55
55
  }
56
56
 
57
- function transform(rule) {
57
+ function transform(legacy, rule) {
58
58
  // We should not re-arrange parameters for css-modules' @value
59
59
  // at-rule. For example:
60
60
  //
61
61
  // @value vertical, center from "./foo.css";
62
- if (!rule.params || rule.name === 'value') {
62
+ if (!rule.params || rule.name.toLowerCase() === 'value') {
63
63
  return;
64
64
  }
65
65
 
66
- var params = (0, _postcssValueParser2.default)(rule.params);
66
+ const params = (0, _postcssValueParser2.default)(rule.params);
67
67
 
68
- params.walk(function (node, index) {
68
+ params.walk((node, index) => {
69
69
  if (node.type === 'div' || node.type === 'function') {
70
70
  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];
76
-
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);
77
73
  node.nodes[2].value = a;
78
74
  node.nodes[4].value = b;
79
75
  }
80
76
  } else if (node.type === 'space') {
81
77
  node.value = ' ';
82
78
  } 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') {
79
+ const prevWord = params.nodes[index - 2];
80
+ if (node.value.toLowerCase() === 'all' && rule.name.toLowerCase() === 'media' && !prevWord) {
81
+ const nextWord = params.nodes[index + 2];
82
+ if (!legacy || nextWord) {
83
+ removeNode(node);
84
+ }
85
+ if (nextWord && nextWord.value.toLowerCase() === 'and') {
86
+ const nextSpace = params.nodes[index + 1];
87
+ const secondSpace = params.nodes[index + 3];
89
88
  removeNode(nextWord);
90
89
  removeNode(nextSpace);
91
90
  removeNode(secondSpace);
92
91
  }
93
- removeNode(node);
94
92
  }
95
93
  }
96
94
  }, true);
@@ -104,9 +102,20 @@ function transform(rule) {
104
102
  }
105
103
  }
106
104
 
107
- exports.default = _postcss2.default.plugin('postcss-minify-params', function () {
108
- return function (css) {
109
- return css.walkAtRules(transform);
105
+ function hasAllBug(browser) {
106
+ return ~['ie 10', 'ie 11'].indexOf(browser);
107
+ }
108
+
109
+ exports.default = _postcss2.default.plugin('postcss-minify-params', () => {
110
+ return (css, result) => {
111
+ const resultOpts = result.opts || {};
112
+ const browsers = (0, _browserslist2.default)(null, {
113
+ stats: resultOpts.stats,
114
+ path: __dirname,
115
+ env: resultOpts.env
116
+ });
117
+
118
+ return css.walkAtRules(transform.bind(null, browsers.some(hasAllBug)));
110
119
  };
111
120
  });
112
121
  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.2",
3
+ "version": "4.0.0",
4
4
  "description": "Minify at-rule params with PostCSS",
5
5
  "keywords": [
6
6
  "postcss",
@@ -16,14 +16,14 @@
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.2",
26
+ "cssnano-util-get-arguments": "^4.0.0",
27
27
  "postcss": "^6.0.0",
28
28
  "postcss-value-parser": "^3.0.0",
29
29
  "uniqs": "^2.0.0"
@@ -33,9 +33,10 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "babel-cli": "^6.0.0",
36
- "cross-env": "^3.0.0"
36
+ "browserslist": "^4.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
  }