postcss-minify-params
Advanced tools
Comparing version
@@ -7,4 +7,6 @@ 'use strict'; | ||
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"); } }; }(); | ||
var _browserslist = require('browserslist'); | ||
var _browserslist2 = _interopRequireDefault(_browserslist); | ||
var _postcss = require('postcss'); | ||
@@ -42,3 +44,3 @@ | ||
function aspectRatio(a, b) { | ||
var divisor = gcd(a, b); | ||
const divisor = gcd(a, b); | ||
@@ -49,5 +51,3 @@ return [a / divisor, b / divisor]; | ||
function split(args) { | ||
return args.map(function (arg) { | ||
return (0, _postcssValueParser.stringify)(arg); | ||
}).join(''); | ||
return args.map(arg => (0, _postcssValueParser.stringify)(arg)).join(''); | ||
} | ||
@@ -60,3 +60,3 @@ | ||
function transform(rule) { | ||
function transform(legacy, rule) { | ||
// We should not re-arrange parameters for css-modules' @value | ||
@@ -66,17 +66,13 @@ // at-rule. For example: | ||
// @value vertical, center from "./foo.css"; | ||
if (!rule.params || rule.name === 'value') { | ||
if (!rule.params || rule.name.toLowerCase() === 'value') { | ||
return; | ||
} | ||
var params = (0, _postcssValueParser2.default)(rule.params); | ||
const params = (0, _postcssValueParser2.default)(rule.params); | ||
params.walk(function (node, index) { | ||
params.walk((node, index) => { | ||
if (node.type === 'div' || node.type === 'function') { | ||
node.before = node.after = ''; | ||
if (node.type === 'function' && node.nodes[4] && node.nodes[0].value.indexOf('-aspect-ratio') === 3) { | ||
var _aspectRatio = aspectRatio(node.nodes[2].value, node.nodes[4].value), | ||
_aspectRatio2 = _slicedToArray(_aspectRatio, 2), | ||
a = _aspectRatio2[0], | ||
b = _aspectRatio2[1]; | ||
if (node.type === 'function' && node.nodes[4] && node.nodes[0].value.toLowerCase().indexOf('-aspect-ratio') === 3) { | ||
const [a, b] = aspectRatio(node.nodes[2].value, node.nodes[4].value); | ||
node.nodes[2].value = a; | ||
@@ -88,8 +84,11 @@ node.nodes[4].value = b; | ||
} else { | ||
var prevWord = params.nodes[index - 2]; | ||
if (node.value === 'all' && rule.name === 'media' && !prevWord) { | ||
var nextSpace = params.nodes[index + 1]; | ||
var nextWord = params.nodes[index + 2]; | ||
var secondSpace = params.nodes[index + 3]; | ||
if (nextWord && nextWord.value === 'and') { | ||
const prevWord = params.nodes[index - 2]; | ||
if (node.value.toLowerCase() === 'all' && rule.name.toLowerCase() === 'media' && !prevWord) { | ||
const nextWord = params.nodes[index + 2]; | ||
if (!legacy || nextWord) { | ||
removeNode(node); | ||
} | ||
if (nextWord && nextWord.value.toLowerCase() === 'and') { | ||
const nextSpace = params.nodes[index + 1]; | ||
const secondSpace = params.nodes[index + 3]; | ||
removeNode(nextWord); | ||
@@ -99,3 +98,2 @@ removeNode(nextSpace); | ||
} | ||
removeNode(node); | ||
} | ||
@@ -114,7 +112,18 @@ } | ||
exports.default = _postcss2.default.plugin('postcss-minify-params', function () { | ||
return function (css) { | ||
return css.walkAtRules(transform); | ||
function hasAllBug(browser) { | ||
return ~['ie 10', 'ie 11'].indexOf(browser); | ||
} | ||
exports.default = _postcss2.default.plugin('postcss-minify-params', () => { | ||
return (css, result) => { | ||
const resultOpts = result.opts || {}; | ||
const browsers = (0, _browserslist2.default)(null, { | ||
stats: resultOpts.stats, | ||
path: __dirname, | ||
env: resultOpts.env | ||
}); | ||
return css.walkAtRules(transform.bind(null, browsers.some(hasAllBug))); | ||
}; | ||
}); | ||
module.exports = exports['default']; |
{ | ||
"name": "postcss-minify-params", | ||
"version": "4.0.0-rc.2", | ||
"version": "4.0.0", | ||
"description": "Minify at-rule params with PostCSS", | ||
@@ -19,10 +19,10 @@ "keywords": [ | ||
"license": "MIT", | ||
"repository": "ben-eb/cssnano", | ||
"repository": "cssnano/cssnano", | ||
"bugs": { | ||
"url": "https://github.com/ben-eb/cssnano/issues" | ||
"url": "https://github.com/cssnano/cssnano/issues" | ||
}, | ||
"homepage": "https://github.com/ben-eb/cssnano", | ||
"homepage": "https://github.com/cssnano/cssnano", | ||
"dependencies": { | ||
"alphanum-sort": "^1.0.0", | ||
"cssnano-util-get-arguments": "^4.0.0-rc.2", | ||
"cssnano-util-get-arguments": "^4.0.0", | ||
"postcss": "^6.0.0", | ||
@@ -37,7 +37,8 @@ "postcss-value-parser": "^3.0.0", | ||
"babel-cli": "^6.0.0", | ||
"cross-env": "^3.0.0" | ||
"browserslist": "^4.0.0", | ||
"cross-env": "^5.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=6.9.0" | ||
} | ||
} |
@@ -31,3 +31,3 @@ # postcss-minify-params [![Build Status][ci-img]][ci] | ||
See [CONTRIBUTORS.md](https://github.com/ben-eb/cssnano/blob/master/CONTRIBUTORS.md). | ||
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md). | ||
@@ -39,3 +39,3 @@ ## License | ||
[PostCSS]: https://github.com/postcss/postcss | ||
[ci-img]: https://travis-ci.org/ben-eb/postcss-minify-params.svg | ||
[ci]: https://travis-ci.org/ben-eb/postcss-minify-params | ||
[ci-img]: https://travis-ci.org/cssnano/postcss-minify-params.svg | ||
[ci]: https://travis-ci.org/cssnano/postcss-minify-params |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
92
5.75%0
-100%7247
-3.06%3
50%1
Infinity%