postcss-discard-comments
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -0,1 +1,5 @@ | ||
# 2.0.1 | ||
* Replaces a dependency on node-balanced with internal comments parser. | ||
# 2.0.0 | ||
@@ -2,0 +6,0 @@ |
49
index.js
'use strict'; | ||
var balanced = require('node-balanced'); | ||
var CommentRemover = require('./lib/commentRemover'); | ||
var commentParser = require('./lib/commentParser'); | ||
var postcss = require('postcss'); | ||
@@ -9,23 +9,28 @@ var space = postcss.list.space; | ||
module.exports = postcss.plugin('postcss-discard-comments', function (options) { | ||
return function (css) { | ||
var remover = new CommentRemover(options || {}); | ||
var remover = new CommentRemover(options || {}); | ||
function replaceComments (source) { | ||
if (!source) { | ||
return; | ||
function matchesComments (source) { | ||
return commentParser(source).filter(function (node) { | ||
return node.type === 'comment'; | ||
}); | ||
} | ||
function replaceComments (source) { | ||
if (!source) { | ||
return; | ||
} | ||
var parsed = commentParser(source).reduce(function (value, node) { | ||
if (node.type !== 'comment') { | ||
return value + node.value; | ||
} | ||
var b = balanced.replacements({ | ||
source: source, | ||
open: '/*', | ||
close: '*/', | ||
replace: function (comment, head, tail) { | ||
if (remover.canRemove(comment)) { | ||
return ' '; | ||
} | ||
return head + comment + tail; | ||
} | ||
}); | ||
return space(b).join(' '); | ||
} | ||
if (remover.canRemove(node.value)) { | ||
return value + ' '; | ||
} | ||
return value + '/*' + node.value + '*/'; | ||
}, ''); | ||
return space(parsed).join(' '); | ||
} | ||
return function (css) { | ||
css.walk(function (node) { | ||
@@ -47,7 +52,3 @@ if (node.type === 'comment' && remover.canRemove(node.text)) { | ||
node.raws.important = replaceComments(node.raws.important); | ||
var b = balanced.matches({ | ||
source: node.raws.important, | ||
open: '/*', | ||
close: '*/' | ||
}); | ||
var b = matchesComments(node.raws.important); | ||
node.raws.important = b.length ? node.raws.important : '!important'; | ||
@@ -54,0 +55,0 @@ } |
'use strict'; | ||
function CommentRemover (options) { | ||
if (!(this instanceof CommentRemover)) { | ||
return new CommentRemover(options); | ||
} | ||
this.options = options; | ||
@@ -8,0 +5,0 @@ } |
{ | ||
"name": "postcss-discard-comments", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Discard comments in your CSS files with PostCSS.", | ||
"main": "index.js", | ||
"files": [ | ||
"lib", | ||
"index.js", | ||
"LICENSE-MIT" | ||
], | ||
"scripts": { | ||
@@ -17,4 +22,5 @@ "test": "tape test.js | tap-spec" | ||
"devDependencies": { | ||
"postcss-scss": "^0.1.2", | ||
"tap-spec": "^4.1.0", | ||
"tape": "^4.2.0" | ||
"tape": "^4.2.1" | ||
}, | ||
@@ -27,10 +33,6 @@ "homepage": "https://github.com/ben-eb/postcss-discard-comments", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/ben-eb/postcss-discard-comments.git" | ||
}, | ||
"repository": "ben-eb/postcss-discard-comments", | ||
"dependencies": { | ||
"node-balanced": "0.0.14", | ||
"postcss": "^5.0.4" | ||
"postcss": "^5.0.8" | ||
} | ||
} |
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 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
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
10115
1
123
3
1
- Removednode-balanced@0.0.14
- Removednode-balanced@0.0.14(transitive)
Updatedpostcss@^5.0.8