postcss-discard-comments 5.0.3 → 5.1.0

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/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "postcss-discard-comments",
3
- "version": "5.0.3",
3
+ "version": "5.1.0",
4
4
  "description": "Discard comments in your CSS files with PostCSS.",
5
5
  "main": "src/index.js",
6
+ "types": "types/index.d.ts",
6
7
  "files": [
7
8
  "src",
8
- "LICENSE-MIT"
9
+ "LICENSE-MIT",
10
+ "types"
9
11
  ],
10
12
  "keywords": [
11
13
  "css",
package/src/index.js CHANGED
@@ -2,11 +2,25 @@
2
2
  const CommentRemover = require('./lib/commentRemover');
3
3
  const commentParser = require('./lib/commentParser');
4
4
 
5
+ /** @typedef {object} Options
6
+ * @property {boolean=} removeAll
7
+ * @property {boolean=} removeAllButFirst
8
+ * @property {(s: string) => boolean=} remove
9
+ */
10
+ /**
11
+ * @type {import('postcss').PluginCreator<Options>}
12
+ * @param {Options} opts
13
+ * @return {import('postcss').Plugin}
14
+ */
5
15
  function pluginCreator(opts = {}) {
6
16
  const remover = new CommentRemover(opts);
7
17
  const matcherCache = new Map();
8
18
  const replacerCache = new Map();
9
19
 
20
+ /**
21
+ * @param {string} source
22
+ * @return {[number, number, number][]}
23
+ */
10
24
  function matchesComments(source) {
11
25
  if (matcherCache.has(source)) {
12
26
  return matcherCache.get(source);
@@ -19,6 +33,11 @@ function pluginCreator(opts = {}) {
19
33
  return result;
20
34
  }
21
35
 
36
+ /**
37
+ * @param {string} source
38
+ * @param {(s: string) => string[]} space
39
+ * @return {string}
40
+ */
22
41
  function replaceComments(source, space, separator = ' ') {
23
42
  const key = source + '@|@' + separator;
24
43
 
@@ -59,7 +78,10 @@ function pluginCreator(opts = {}) {
59
78
  }
60
79
 
61
80
  if (node.raws.between) {
62
- node.raws.between = replaceComments(node.raws.between, list.space);
81
+ node.raws.between = replaceComments(
82
+ /** @type {string} */ (node.raws.between),
83
+ list.space
84
+ );
63
85
  }
64
86
 
65
87
  if (node.type === 'decl') {
@@ -70,7 +92,9 @@ function pluginCreator(opts = {}) {
70
92
  node.value = replaceComments(node.value, list.space);
71
93
  }
72
94
 
73
- node.raws.value = null;
95
+ /** @type {null | {value: string, raw: string}} */ (
96
+ node.raws.value
97
+ ) = null;
74
98
  }
75
99
 
76
100
  if (node.raws.important) {
@@ -1,5 +1,11 @@
1
1
  'use strict';
2
+
3
+ /**
4
+ * @param {string} input
5
+ * @return {[number, number, number][]}
6
+ */
2
7
  module.exports = function commentParser(input) {
8
+ /** @type [number, number, number][] */
3
9
  const tokens = [];
4
10
  const length = input.length;
5
11
  let pos = 0;
@@ -1,8 +1,13 @@
1
1
  'use strict';
2
+
3
+ /** @param {import('../index.js').Options} options */
2
4
  function CommentRemover(options) {
3
5
  this.options = options;
4
6
  }
5
-
7
+ /**
8
+ * @param {string} comment
9
+ * @return {boolean | undefined}
10
+ */
6
11
  CommentRemover.prototype.canRemove = function (comment) {
7
12
  const remove = this.options.remove;
8
13
 
@@ -0,0 +1,21 @@
1
+ export = pluginCreator;
2
+ /** @typedef {object} Options
3
+ * @property {boolean=} removeAll
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
+ type Options = {
17
+ removeAll?: boolean | undefined;
18
+ removeAllButFirst?: boolean | undefined;
19
+ remove?: ((s: string) => boolean) | undefined;
20
+ };
21
+ declare var postcss: true;
@@ -0,0 +1,2 @@
1
+ declare function _exports(input: string): [number, number, number][];
2
+ export = _exports;
@@ -0,0 +1,14 @@
1
+ export = CommentRemover;
2
+ /** @param {import('../index.js').Options} options */
3
+ declare function CommentRemover(options: import('../index.js').Options): void;
4
+ declare class CommentRemover {
5
+ /** @param {import('../index.js').Options} options */
6
+ constructor(options: import('../index.js').Options);
7
+ options: import("../index.js").Options;
8
+ /**
9
+ * @param {string} comment
10
+ * @return {boolean | undefined}
11
+ */
12
+ canRemove(comment: string): boolean | undefined;
13
+ _hasFirst: boolean | undefined;
14
+ }