postcss-discard-comments 8.0.0 → 8.0.2
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/LICENSE-MIT +1 -1
- package/README.md +1 -1
- package/package.json +21 -8
- package/src/index.js +9 -5
- package/src/lib/commentRemover.js +25 -23
- package/types/index.d.ts +3 -17
- package/types/index.d.ts.map +1 -1
- package/types/lib/commentParser.d.ts +9 -2
- package/types/lib/commentParser.d.ts.map +1 -1
- package/types/lib/commentRemover.d.ts +3 -5
- package/types/lib/commentRemover.d.ts.map +1 -1
package/LICENSE-MIT
CHANGED
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-discard-comments",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "Discard comments in your CSS files with PostCSS.",
|
|
5
|
-
"
|
|
6
|
-
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./types/index.d.ts",
|
|
8
|
+
"default": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./src": "./src/index.js",
|
|
11
|
+
"./src/index": "./src/index.js",
|
|
12
|
+
"./src/index.js": "./src/index.js",
|
|
13
|
+
"./src/lib/*": "./src/lib/*.js",
|
|
14
|
+
"./src/lib/*.js": "./src/lib/*.js",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
7
17
|
"files": [
|
|
8
18
|
"src",
|
|
9
19
|
"LICENSE-MIT",
|
|
@@ -20,11 +30,14 @@
|
|
|
20
30
|
"author": {
|
|
21
31
|
"name": "Ben Briggs",
|
|
22
32
|
"email": "beneb.info@gmail.com",
|
|
23
|
-
"url": "
|
|
33
|
+
"url": "https://beneb.info"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "cssnano/cssnano"
|
|
24
38
|
},
|
|
25
|
-
"repository": "cssnano/cssnano",
|
|
26
39
|
"dependencies": {
|
|
27
|
-
"postcss-selector-parser": "^7.1.
|
|
40
|
+
"postcss-selector-parser": "^7.1.4"
|
|
28
41
|
},
|
|
29
42
|
"bugs": {
|
|
30
43
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
@@ -33,11 +46,11 @@
|
|
|
33
46
|
"node": "^22.11.0 || ^24.11.0 || >=26.0"
|
|
34
47
|
},
|
|
35
48
|
"devDependencies": {
|
|
36
|
-
"postcss": "^8.5.
|
|
49
|
+
"postcss": "^8.5.25",
|
|
37
50
|
"postcss-scss": "^4.0.9",
|
|
38
51
|
"postcss-simple-vars": "^7.0.1"
|
|
39
52
|
},
|
|
40
53
|
"peerDependencies": {
|
|
41
|
-
"postcss": "^8.5.
|
|
54
|
+
"postcss": "^8.5.25"
|
|
42
55
|
}
|
|
43
56
|
}
|
package/src/index.js
CHANGED
|
@@ -9,7 +9,6 @@ const selectorParser = require('postcss-selector-parser');
|
|
|
9
9
|
* @property {(s: string) => boolean=} remove
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
|
-
* @type {import('postcss').PluginCreator<Options>}
|
|
13
12
|
* @param {Options} opts
|
|
14
13
|
* @return {import('postcss').Plugin}
|
|
15
14
|
*/
|
|
@@ -65,7 +64,7 @@ function pluginCreator(opts = {}) {
|
|
|
65
64
|
return replacerCache.get(key);
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
if (source.
|
|
67
|
+
if (!source.includes('/*')) {
|
|
69
68
|
const normalized = space(source).join(' ');
|
|
70
69
|
|
|
71
70
|
replacerCache.set(key, normalized);
|
|
@@ -112,7 +111,7 @@ function pluginCreator(opts = {}) {
|
|
|
112
111
|
if (replacerCache.has(key)) {
|
|
113
112
|
return replacerCache.get(key);
|
|
114
113
|
}
|
|
115
|
-
if (source.
|
|
114
|
+
if (!source.includes('/*')) {
|
|
116
115
|
const normalized = space(source).join(' ');
|
|
117
116
|
|
|
118
117
|
replacerCache.set(key, normalized);
|
|
@@ -149,7 +148,10 @@ function pluginCreator(opts = {}) {
|
|
|
149
148
|
|
|
150
149
|
return {
|
|
151
150
|
postcssPlugin: 'postcss-discard-comments',
|
|
152
|
-
|
|
151
|
+
/**
|
|
152
|
+
* @param {import('postcss').Root} css
|
|
153
|
+
* @param {import('postcss').Helpers} helpers
|
|
154
|
+
*/
|
|
153
155
|
OnceExit(css, { list }) {
|
|
154
156
|
css.walk((node) => {
|
|
155
157
|
if (node.type === 'comment' && remover.canRemove(node.text)) {
|
|
@@ -236,4 +238,6 @@ function pluginCreator(opts = {}) {
|
|
|
236
238
|
}
|
|
237
239
|
|
|
238
240
|
pluginCreator.postcss = true;
|
|
239
|
-
module.exports =
|
|
241
|
+
module.exports = /** @type {import('postcss').PluginCreator<Options>}*/ (
|
|
242
|
+
pluginCreator
|
|
243
|
+
);
|
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
class CommentRemover {
|
|
4
|
+
/** @param {import('../index.js').Options} options */
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} comment
|
|
10
|
+
* @return {boolean | undefined}
|
|
11
|
+
*/
|
|
12
|
+
canRemove(comment) {
|
|
13
|
+
const remove = this.options.remove;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (remove) {
|
|
16
|
+
return remove(comment);
|
|
17
|
+
} else {
|
|
18
|
+
const isImportant = comment.indexOf('!') === 0;
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (!isImportant) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
if (this.options.removeAll || this._hasFirst) {
|
|
25
|
+
return true;
|
|
26
|
+
} else if (this.options.removeAllButFirst && !this._hasFirst) {
|
|
27
|
+
this._hasFirst = true;
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
}
|
|
32
|
+
}
|
|
31
33
|
|
|
32
34
|
module.exports = CommentRemover;
|
package/types/index.d.ts
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @property {boolean=} removeAllButFirst
|
|
5
|
-
* @property {(s: string) => boolean=} remove
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* @type {import('postcss').PluginCreator<Options>}
|
|
9
|
-
* @param {Options} opts
|
|
10
|
-
* @return {import('postcss').Plugin}
|
|
11
|
-
*/
|
|
12
|
-
declare function pluginCreator(opts?: Options): import("postcss").Plugin;
|
|
13
|
-
declare namespace pluginCreator {
|
|
14
|
-
export { postcss, Options };
|
|
15
|
-
}
|
|
16
|
-
declare var postcss: true;
|
|
17
|
-
type Options = {
|
|
1
|
+
declare const _exports: import("postcss").PluginCreator<Options>;
|
|
2
|
+
export = _exports;
|
|
3
|
+
export type Options = {
|
|
18
4
|
removeAll?: boolean | undefined;
|
|
19
5
|
removeAllButFirst?: boolean | undefined;
|
|
20
6
|
remove?: ((s: string) => boolean) | undefined;
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;AAKI,YAAkB,OAAO,GACzB;IAAqB,SAAS,AAA9B,CACA,EADW,OAAO,YAAC,CACnB;IAAqB,iBAAiB,AAAtC,CACA,EADW,OAAO,YAAC,CACnB;IAAoC,MAAM,AAA1C,CACH,EADc,CAAA,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,aAAC,CACrC;CAAA,CAAA"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export = commentParser;
|
|
2
|
+
/**
|
|
3
|
+
* CSS Comment Parser with context awareness
|
|
4
|
+
* Properly handles comments inside strings, URLs, and escaped characters
|
|
5
|
+
*
|
|
6
|
+
* @param {string} input
|
|
7
|
+
* @return {[number, number, number][]}
|
|
8
|
+
*/
|
|
9
|
+
declare function commentParser(input: string): [number, number, number][];
|
|
3
10
|
//# sourceMappingURL=commentParser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commentParser.d.ts","sourceRoot":"","sources":["../../src/lib/commentParser.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commentParser.d.ts","sourceRoot":"","sources":["../../src/lib/commentParser.js"],"names":[],"mappings":";AAUA;;;;;;GAMG;+BACqC,KAAK,EAHlC,MAGkC,GAFjC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
export = CommentRemover;
|
|
2
|
-
/** @param {import('../index.js').Options} options */
|
|
3
|
-
declare function CommentRemover(options: import("../index.js").Options): void;
|
|
4
2
|
declare class CommentRemover {
|
|
5
|
-
/** @param {import('../index.js').Options} options */
|
|
6
|
-
constructor(options: import("../index.js").Options);
|
|
7
3
|
options: import("../index.js").Options;
|
|
4
|
+
_hasFirst: boolean | undefined;
|
|
5
|
+
/** @param {import('../index.js').Options} options */
|
|
6
|
+
constructor(options: import('../index.js').Options);
|
|
8
7
|
/**
|
|
9
8
|
* @param {string} comment
|
|
10
9
|
* @return {boolean | undefined}
|
|
11
10
|
*/
|
|
12
11
|
canRemove(comment: string): boolean | undefined;
|
|
13
|
-
_hasFirst: boolean | undefined;
|
|
14
12
|
}
|
|
15
13
|
//# sourceMappingURL=commentRemover.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commentRemover.d.ts","sourceRoot":"","sources":["../../src/lib/commentRemover.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commentRemover.d.ts","sourceRoot":"","sources":["../../src/lib/commentRemover.js"],"names":[],"mappings":"SAiCiB,cAAc;AA/B/B,cAAM,cAAc;IAGX,OAAO;IAqBH,SAAS;IAvBpB,qDAAqD;IACrD,YAAY,OAAO,EADP,OAAO,aAAa,EAAE,OACf,EAElB;IACD;;;OAGG;IACH,SAAS,CAAC,OAAO,EAHN,MAGM,GAFL,OAAO,GAAG,SAAS,CAqB9B;CACF"}
|