postcss-discard-duplicates
Advanced tools
Comparing version 2.1.0 to 4.0.0-nightly.2020.7.24
@@ -1,6 +0,9 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _postcss = require('postcss'); | ||
var _postcss = require("postcss"); | ||
@@ -10,130 +13,137 @@ function noop() {} | ||
function trimValue(value) { | ||
return value ? value.trim() : value; | ||
return value ? value.trim() : value; | ||
} | ||
function empty(node) { | ||
return !node.nodes.filter(function (child) { | ||
return child.type !== 'comment'; | ||
}).length; | ||
return !node.nodes.filter(child => child.type !== 'comment').length; | ||
} | ||
function equals(a, b) { | ||
if (a.type !== b.type) { | ||
if (a.type !== b.type) { | ||
return false; | ||
} | ||
if (a.important !== b.important) { | ||
return false; | ||
} | ||
if (a.raws && !b.raws || !a.raws && b.raws) { | ||
return false; | ||
} | ||
switch (a.type) { | ||
case 'rule': | ||
if (a.selector !== b.selector) { | ||
return false; | ||
} | ||
} | ||
if (a.important !== b.important) { | ||
break; | ||
case 'atrule': | ||
if (a.name !== b.name || a.params !== b.params) { | ||
return false; | ||
} | ||
} | ||
if (a.raws && !b.raws || !a.raws && b.raws) { | ||
if (a.raws && trimValue(a.raws.before) !== trimValue(b.raws.before)) { | ||
return false; | ||
} | ||
} | ||
switch (a.type) { | ||
case 'rule': | ||
if (a.selector !== b.selector) { | ||
return false; | ||
} | ||
break; | ||
case 'atrule': | ||
if (a.name !== b.name || a.params !== b.params) { | ||
return false; | ||
} | ||
if (a.raws && trimValue(a.raws.afterName) !== trimValue(b.raws.afterName)) { | ||
return false; | ||
} | ||
if (a.raws && trimValue(a.raws.before) !== trimValue(b.raws.before)) { | ||
return false; | ||
} | ||
break; | ||
if (a.raws && trimValue(a.raws.afterName) !== trimValue(b.raws.afterName)) { | ||
return false; | ||
} | ||
break; | ||
case 'decl': | ||
if (a.prop !== b.prop || a.value !== b.value) { | ||
return false; | ||
} | ||
case 'decl': | ||
if (a.prop !== b.prop || a.value !== b.value) { | ||
return false; | ||
} | ||
if (a.raws && trimValue(a.raws.before) !== trimValue(b.raws.before)) { | ||
return false; | ||
} | ||
break; | ||
if (a.raws && trimValue(a.raws.before) !== trimValue(b.raws.before)) { | ||
return false; | ||
} | ||
break; | ||
} | ||
if (a.nodes) { | ||
if (a.nodes.length !== b.nodes.length) { | ||
return false; | ||
} | ||
if (a.nodes) { | ||
if (a.nodes.length !== b.nodes.length) { | ||
return false; | ||
} | ||
for (let i = 0; i < a.nodes.length; i++) { | ||
if (!equals(a.nodes[i], b.nodes[i])) { | ||
return false; | ||
} | ||
} | ||
} | ||
for (var i = 0; i < a.nodes.length; i++) { | ||
if (!equals(a.nodes[i], b.nodes[i])) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
return true; | ||
} | ||
function dedupeRule(last, nodes) { | ||
var index = nodes.indexOf(last) - 1; | ||
let index = nodes.indexOf(last) - 1; | ||
var _loop = function _loop() { | ||
var node = nodes[index--]; | ||
if (node && node.type === 'rule' && node.selector === last.selector) { | ||
last.each(function (child) { | ||
if (child.type === 'decl') { | ||
dedupeNode(child, node.nodes); | ||
} | ||
}); | ||
while (index >= 0) { | ||
const node = nodes[index--]; | ||
if (empty(node)) { | ||
node.remove(); | ||
} | ||
if (node && node.type === 'rule' && node.selector === last.selector) { | ||
last.each(child => { | ||
if (child.type === 'decl') { | ||
dedupeNode(child, node.nodes); | ||
} | ||
}; | ||
}); | ||
while (index >= 0) { | ||
_loop(); | ||
if (empty(node)) { | ||
node.remove(); | ||
} | ||
} | ||
} | ||
} | ||
function dedupeNode(last, nodes) { | ||
var index = !!~nodes.indexOf(last) ? nodes.indexOf(last) - 1 : nodes.length - 1; | ||
let index = ~nodes.indexOf(last) ? nodes.indexOf(last) - 1 : nodes.length - 1; | ||
while (index >= 0) { | ||
var _node = nodes[index--]; | ||
if (_node && equals(_node, last)) { | ||
_node.remove(); | ||
} | ||
while (index >= 0) { | ||
const node = nodes[index--]; | ||
if (node && equals(node, last)) { | ||
node.remove(); | ||
} | ||
} | ||
} | ||
var handlers = { | ||
rule: dedupeRule, | ||
atrule: dedupeNode, | ||
decl: dedupeNode, | ||
comment: noop | ||
const handlers = { | ||
rule: dedupeRule, | ||
atrule: dedupeNode, | ||
decl: dedupeNode, | ||
comment: noop | ||
}; | ||
function dedupe(root) { | ||
var nodes = root.nodes; | ||
const { | ||
nodes | ||
} = root; | ||
if (!nodes) { | ||
return; | ||
if (!nodes) { | ||
return; | ||
} | ||
let index = nodes.length - 1; | ||
while (index >= 0) { | ||
let last = nodes[index--]; | ||
if (!last || !last.parent) { | ||
continue; | ||
} | ||
var index = nodes.length - 1; | ||
while (index >= 0) { | ||
var last = nodes[index--]; | ||
if (!last || !last.parent) { | ||
continue; | ||
} | ||
dedupe(last); | ||
handlers[last.type](last, nodes); | ||
} | ||
dedupe(last); | ||
handlers[last.type](last, nodes); | ||
} | ||
} | ||
exports.default = (0, _postcss.plugin)('postcss-discard-duplicates', function () { | ||
return dedupe; | ||
}); | ||
module.exports = exports['default']; | ||
var _default = (0, _postcss.plugin)('postcss-discard-duplicates', () => dedupe); | ||
exports.default = _default; | ||
module.exports = exports.default; |
{ | ||
"name": "postcss-discard-duplicates", | ||
"version": "2.1.0", | ||
"version": "4.0.0-nightly.2020.7.24", | ||
"description": "Discard duplicate rules in your CSS files with PostCSS.", | ||
@@ -11,8 +11,5 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"contributorAdd": "all-contributors add", | ||
"contributorGenerate": "all-contributors generate", | ||
"pretest": "eslint src", | ||
"prepublish": "del-cli dist && babel src --out-dir dist --ignore /__tests__/", | ||
"test": "ava src/__tests__", | ||
"test-012": "ava src/__tests__" | ||
"prebuild": "", | ||
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"", | ||
"prepublish": "" | ||
}, | ||
@@ -28,21 +25,5 @@ "keywords": [ | ||
"dependencies": { | ||
"postcss": "^5.0.4" | ||
"postcss": "^7.0.16" | ||
}, | ||
"devDependencies": { | ||
"all-contributors-cli": "^3.0.5", | ||
"ava": "^0.17.0", | ||
"babel-cli": "^6.3.17", | ||
"babel-core": "^6.3.26", | ||
"babel-plugin-add-module-exports": "^0.2.0", | ||
"babel-preset-es2015": "^6.5.0", | ||
"babel-preset-es2015-loose": "^7.0.0", | ||
"babel-preset-stage-0": "^6.3.13", | ||
"babel-register": "^6.9.0", | ||
"del-cli": "^0.2.0", | ||
"eslint": "^3.0.0", | ||
"eslint-config-cssnano": "^3.0.0", | ||
"eslint-plugin-babel": "^3.3.0", | ||
"eslint-plugin-import": "^2.0.1" | ||
}, | ||
"homepage": "https://github.com/ben-eb/postcss-discard-duplicates", | ||
"homepage": "https://github.com/cssnano/cssnano", | ||
"author": { | ||
@@ -53,9 +34,9 @@ "name": "Ben Briggs", | ||
}, | ||
"repository": "ben-eb/postcss-discard-duplicates", | ||
"eslintConfig": { | ||
"extends": "cssnano" | ||
"repository": "cssnano/cssnano", | ||
"bugs": { | ||
"url": "https://github.com/cssnano/cssnano/issues" | ||
}, | ||
"ava": { | ||
"require": "babel-register" | ||
"engines": { | ||
"node": ">=6.9.0" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# [postcss][postcss]-discard-duplicates [![Build Status](https://travis-ci.org/ben-eb/postcss-discard-duplicates.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-discard-duplicates.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-discard-duplicates.svg)][deps] | ||
# [postcss][postcss]-discard-duplicates | ||
@@ -59,14 +59,8 @@ > Discard duplicate rules in your CSS files with PostCSS. | ||
## Contributors | ||
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): | ||
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md). | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
| [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/ben-eb/postcss-discard-duplicates/commits?author=ben-eb) [📖](https://github.com/ben-eb/postcss-discard-duplicates/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/postcss-discard-duplicates/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[💻](https://github.com/ben-eb/postcss-discard-duplicates/commits?author=TrySound) 👀 [⚠️](https://github.com/ben-eb/postcss-discard-duplicates/commits?author=TrySound) | [<img src="https://avatars.githubusercontent.com/u/68302?v=3" width="100px;"/><br /><sub>Lee Houghton</sub>](https://github.com/asztal)<br />[💻](https://github.com/ben-eb/postcss-discard-duplicates/commits?author=asztal) | [<img src="https://avatars.githubusercontent.com/u/1737375?v=3" width="100px;"/><br /><sub>Andy Jansson</sub>](https://github.com/andyjansson)<br />[💻](https://github.com/ben-eb/postcss-discard-duplicates/commits?author=andyjansson) [⚠️](https://github.com/ben-eb/postcss-discard-duplicates/commits?author=andyjansson) | | ||
| :---: | :---: | :---: | :---: | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
This project follows the [all-contributors] specification. Contributions of | ||
any kind welcome! | ||
## License | ||
@@ -77,6 +71,2 @@ | ||
[all-contributors]: https://github.com/kentcdodds/all-contributors | ||
[ci]: https://travis-ci.org/ben-eb/postcss-discard-duplicates | ||
[deps]: https://gemnasium.com/ben-eb/postcss-discard-duplicates | ||
[npm]: http://badge.fury.io/js/postcss-discard-duplicates | ||
[postcss]: https://github.com/postcss/postcss |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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 v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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 website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
0
5871
4
111
71
1
+ Addedpicocolors@0.2.1(transitive)
+ Addedpostcss@7.0.39(transitive)
+ Addedsource-map@0.6.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-flag@1.0.0(transitive)
- Removedjs-base64@2.6.4(transitive)
- Removedpostcss@5.2.18(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.03.2.3(transitive)
Updatedpostcss@^7.0.16