Socket
Socket
Sign inDemoInstall

postcss-discard-comments

Package Overview
Dependencies
Maintainers
8
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-discard-comments - npm Package Compare versions

Comparing version 7.0.0 to 7.0.1

5

package.json
{
"name": "postcss-discard-comments",
"version": "7.0.0",
"version": "7.0.1",
"description": "Discard comments in your CSS files with PostCSS.",

@@ -26,2 +26,5 @@ "main": "src/index.js",

"repository": "cssnano/cssnano",
"dependencies": {
"postcss-selector-parser": "^6.1.0"
},
"bugs": {

@@ -28,0 +31,0 @@ "url": "https://github.com/cssnano/cssnano/issues"

64

src/index.js
'use strict';
const CommentRemover = require('./lib/commentRemover');
const commentParser = require('./lib/commentParser');
const selectorParser = require('postcss-selector-parser');

@@ -68,2 +69,41 @@ /** @typedef {object} Options

/**
* @param {string} source
* @param {(s: string) => string[]} space
* @return {string}
*/
function replaceCommentsInSelector(source, space) {
const key = source + '@|@';
if (replacerCache.has(key)) {
return replacerCache.get(key);
}
const processed = selectorParser((ast) => {
ast.walk((node) => {
if (node.type === 'comment') {
const contents = node.value.slice(2, -2);
if (remover.canRemove(contents)) {
node.remove();
}
}
const rawSpaceAfter = replaceComments(node.rawSpaceAfter, space, '');
const rawSpaceBefore = replaceComments(node.rawSpaceBefore, space, '');
// If comments are not removed, the result of trim will be returned,
// so if we compare and there are no changes, skip it.
if (rawSpaceAfter !== node.rawSpaceAfter.trim()) {
node.rawSpaceAfter = rawSpaceAfter;
}
if (rawSpaceBefore !== node.rawSpaceBefore.trim()) {
node.rawSpaceBefore = rawSpaceBefore;
}
});
}).processSync(source);
const result = space(processed).join(' ');
replacerCache.set(key, result);
return result;
}
return {

@@ -113,12 +153,14 @@ postcssPlugin: 'postcss-discard-comments',

if (
node.type === 'rule' &&
node.raws.selector &&
node.raws.selector.raw
) {
node.raws.selector.raw = replaceComments(
node.raws.selector.raw,
list.space,
''
);
if (node.type === 'rule') {
if (node.raws.selector && node.raws.selector.raw) {
node.raws.selector.raw = replaceCommentsInSelector(
node.raws.selector.raw,
list.space
);
} else if (node.selector && node.selector.includes('/*')) {
node.selector = replaceCommentsInSelector(
node.selector,
list.space
);
}

@@ -147,2 +189,4 @@ return;

);
} else if (node.params && node.params.includes('/*')) {
node.params = replaceComments(node.params, list.space);
}

@@ -149,0 +193,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc