postcss-minify-params 4.0.0-rc.0 → 4.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
@@ -1,3 +1,7 @@
1
+ # Head
2
+
3
+ * Resolves an issue with mangling css-modules' `@value` at-rule.
4
+
1
5
  # 4.0.0-rc.0
2
6
 
3
7
  * Breaking: Drops support for Node 0.12, we now require at least Node 4.
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,39 +54,41 @@ function removeNode(node) {
54
54
  node.type = 'word';
55
55
  }
56
56
 
57
- function transform(rule) {
58
- if (!rule.params) {
57
+ function transform(legacy, 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.toLowerCase() === 'value') {
59
63
  return;
60
64
  }
61
65
 
62
- var params = (0, _postcssValueParser2.default)(rule.params);
66
+ const params = (0, _postcssValueParser2.default)(rule.params);
63
67
 
64
- params.walk(function (node, index) {
68
+ params.walk((node, index) => {
65
69
  if (node.type === 'div' || node.type === 'function') {
66
70
  node.before = node.after = '';
67
- if (node.type === 'function' && node.nodes[4] && node.nodes[0].value.indexOf('-aspect-ratio') === 3) {
68
- var _aspectRatio = aspectRatio(node.nodes[2].value, node.nodes[4].value),
69
- _aspectRatio2 = _slicedToArray(_aspectRatio, 2),
70
- a = _aspectRatio2[0],
71
- b = _aspectRatio2[1];
72
-
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);
73
73
  node.nodes[2].value = a;
74
74
  node.nodes[4].value = b;
75
75
  }
76
76
  } else if (node.type === 'space') {
77
77
  node.value = ' ';
78
78
  } else {
79
- var prevWord = params.nodes[index - 2];
80
- if (node.value === 'all' && rule.name === 'media' && !prevWord) {
81
- var nextSpace = params.nodes[index + 1];
82
- var nextWord = params.nodes[index + 2];
83
- var secondSpace = params.nodes[index + 3];
84
- 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];
85
88
  removeNode(nextWord);
86
89
  removeNode(nextSpace);
87
90
  removeNode(secondSpace);
88
91
  }
89
- removeNode(node);
90
92
  }
91
93
  }
92
94
  }, true);
@@ -100,9 +102,20 @@ function transform(rule) {
100
102
  }
101
103
  }
102
104
 
103
- exports.default = _postcss2.default.plugin('postcss-minify-params', function () {
104
- return function (css) {
105
- 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)));
106
119
  };
107
120
  });
108
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.0",
3
+ "version": "4.0.1",
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
  }