postcss-discard-comments 5.0.2 → 5.0.3

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,10 +1,10 @@
1
1
  {
2
2
  "name": "postcss-discard-comments",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "description": "Discard comments in your CSS files with PostCSS.",
5
- "main": "dist/index.js",
5
+ "main": "src/index.js",
6
6
  "files": [
7
- "dist",
7
+ "src",
8
8
  "LICENSE-MIT"
9
9
  ],
10
10
  "keywords": [
@@ -33,9 +33,5 @@
33
33
  "peerDependencies": {
34
34
  "postcss": "^8.2.15"
35
35
  },
36
- "scripts": {
37
- "prebuild": "rimraf dist",
38
- "build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
39
- },
40
36
  "readme": "# [postcss][postcss]-discard-comments\n\n> Discard comments in your CSS files with PostCSS.\n\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-discard-comments) do:\n\n```\nnpm install postcss-discard-comments --save\n```\n\n\n## Example\n\n### Input\n\n```css\nh1/* heading */{\n margin: 0 auto\n}\n```\n\n### Output\n\n```css\nh1 {\n margin: 0 auto\n}\n```\n\nThis module discards comments from your CSS files; by default, it will remove\nall regular comments (`/* comment */`) and preserve comments marked as important\n(`/*! important */`).\n\nNote that this module does not handle source map comments because they are not\navailable to it; PostCSS handles this internally, so if they are removed then\nyou will have to [configure source maps in PostCSS][maps].\n\n[maps]: https://github.com/postcss/postcss/blob/master/docs/source-maps.md\n\n\n## API\n\n### comments([options])\n\n#### options\n\n##### remove(function)\n\nType: `function`\nReturn: `boolean`\nVariable: `comment` contains a comment without `/**/`\n\nFor each comment, return true to remove, or false to keep the comment.\n\n```js\nfunction(comment) {}\n```\n\n```js\nvar css = '/* headings *//*@ h1 */h1{margin:0 auto}/*@ h2 */h2{color:red}';\nconsole.log(postcss(comments({\n remove: function(comment) { return comment[0] == \"@\"; }\n})).process(css).css);\n//=> /* headings */h1{margin:0 auto}h2{color:red}\n```\n**NOTE:** If you use the `remove` function other options will not be available.\n\n##### removeAll\n\nType: `boolean`\nDefault: `false`\n\nRemove all comments marked as important.\n\n```js\nvar css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';\nconsole.log(postcss(comments({removeAll: true})).process(css).css);\n//=> h1{margin:0 auto}h2{color:red}\n```\n\n##### removeAllButFirst\n\nType: `boolean`\nDefault: `false`\n\nRemove all comments marked as important, but the first one.\n\n```js\nvar css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';\nconsole.log(postcss(comments({removeAllButFirst: true})).process(css).css);\n//=> /*! heading */h1{margin:0 auto}h2{color:red}\n```\n\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n\n[postcss]: https://github.com/postcss/postcss\n"
41
37
  }
@@ -1,18 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _commentRemover = _interopRequireDefault(require("./lib/commentRemover"));
9
-
10
- var _commentParser = _interopRequireDefault(require("./lib/commentParser"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1
+ 'use strict';
2
+ const CommentRemover = require('./lib/commentRemover');
3
+ const commentParser = require('./lib/commentParser');
13
4
 
14
5
  function pluginCreator(opts = {}) {
15
- const remover = new _commentRemover.default(opts);
6
+ const remover = new CommentRemover(opts);
16
7
  const matcherCache = new Map();
17
8
  const replacerCache = new Map();
18
9
 
@@ -21,8 +12,10 @@ function pluginCreator(opts = {}) {
21
12
  return matcherCache.get(source);
22
13
  }
23
14
 
24
- const result = (0, _commentParser.default)(source).filter(([type]) => type);
15
+ const result = commentParser(source).filter(([type]) => type);
16
+
25
17
  matcherCache.set(source, result);
18
+
26
19
  return result;
27
20
  }
28
21
 
@@ -33,7 +26,7 @@ function pluginCreator(opts = {}) {
33
26
  return replacerCache.get(key);
34
27
  }
35
28
 
36
- const parsed = (0, _commentParser.default)(source).reduce((value, [type, start, end]) => {
29
+ const parsed = commentParser(source).reduce((value, [type, start, end]) => {
37
30
  const contents = source.slice(start, end);
38
31
 
39
32
  if (!type) {
@@ -46,20 +39,22 @@ function pluginCreator(opts = {}) {
46
39
 
47
40
  return `${value}/*${contents}*/`;
48
41
  }, '');
42
+
49
43
  const result = space(parsed).join(' ');
44
+
50
45
  replacerCache.set(key, result);
46
+
51
47
  return result;
52
48
  }
53
49
 
54
50
  return {
55
51
  postcssPlugin: 'postcss-discard-comments',
56
52
 
57
- OnceExit(css, {
58
- list
59
- }) {
60
- css.walk(node => {
53
+ OnceExit(css, { list }) {
54
+ css.walk((node) => {
61
55
  if (node.type === 'comment' && remover.canRemove(node.text)) {
62
56
  node.remove();
57
+
63
58
  return;
64
59
  }
65
60
 
@@ -79,22 +74,39 @@ function pluginCreator(opts = {}) {
79
74
  }
80
75
 
81
76
  if (node.raws.important) {
82
- node.raws.important = replaceComments(node.raws.important, list.space);
77
+ node.raws.important = replaceComments(
78
+ node.raws.important,
79
+ list.space
80
+ );
81
+
83
82
  const b = matchesComments(node.raws.important);
83
+
84
84
  node.raws.important = b.length ? node.raws.important : '!important';
85
85
  }
86
86
 
87
87
  return;
88
88
  }
89
89
 
90
- if (node.type === 'rule' && node.raws.selector && node.raws.selector.raw) {
91
- node.raws.selector.raw = replaceComments(node.raws.selector.raw, list.space, '');
90
+ if (
91
+ node.type === 'rule' &&
92
+ node.raws.selector &&
93
+ node.raws.selector.raw
94
+ ) {
95
+ node.raws.selector.raw = replaceComments(
96
+ node.raws.selector.raw,
97
+ list.space,
98
+ ''
99
+ );
100
+
92
101
  return;
93
102
  }
94
103
 
95
104
  if (node.type === 'atrule') {
96
105
  if (node.raws.afterName) {
97
- const commentsReplaced = replaceComments(node.raws.afterName, list.space);
106
+ const commentsReplaced = replaceComments(
107
+ node.raws.afterName,
108
+ list.space
109
+ );
98
110
 
99
111
  if (!commentsReplaced.length) {
100
112
  node.raws.afterName = commentsReplaced + ' ';
@@ -104,16 +116,16 @@ function pluginCreator(opts = {}) {
104
116
  }
105
117
 
106
118
  if (node.raws.params && node.raws.params.raw) {
107
- node.raws.params.raw = replaceComments(node.raws.params.raw, list.space);
119
+ node.raws.params.raw = replaceComments(
120
+ node.raws.params.raw,
121
+ list.space
122
+ );
108
123
  }
109
124
  }
110
125
  });
111
- }
112
-
126
+ },
113
127
  };
114
128
  }
115
129
 
116
130
  pluginCreator.postcss = true;
117
- var _default = pluginCreator;
118
- exports.default = _default;
119
- module.exports = exports.default;
131
+ module.exports = pluginCreator;
@@ -1,11 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = commentParser;
7
-
8
- function commentParser(input) {
1
+ 'use strict';
2
+ module.exports = function commentParser(input) {
9
3
  const tokens = [];
10
4
  const length = input.length;
11
5
  let pos = 0;
@@ -17,6 +11,7 @@ function commentParser(input) {
17
11
  if (~next) {
18
12
  tokens.push([0, pos, next]);
19
13
  pos = next;
14
+
20
15
  next = input.indexOf('*/', pos + 2);
21
16
  tokens.push([1, pos + 2, next]);
22
17
  pos = next + 2;
@@ -27,6 +22,4 @@ function commentParser(input) {
27
22
  }
28
23
 
29
24
  return tokens;
30
- }
31
-
32
- module.exports = exports.default;
25
+ };
@@ -1,10 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
1
+ 'use strict';
8
2
  function CommentRemover(options) {
9
3
  this.options = options;
10
4
  }
@@ -30,6 +24,4 @@ CommentRemover.prototype.canRemove = function (comment) {
30
24
  }
31
25
  };
32
26
 
33
- var _default = CommentRemover;
34
- exports.default = _default;
35
- module.exports = exports.default;
27
+ module.exports = CommentRemover;