postcss-discard-comments 4.0.0-rc.0 → 4.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/README.md CHANGED
@@ -103,7 +103,7 @@ examples for your environment.
103
103
 
104
104
  ## Contributors
105
105
 
106
- See [CONTRIBUTORS.md](https://github.com/ben-eb/cssnano/blob/master/CONTRIBUTORS.md).
106
+ See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
107
107
 
108
108
 
109
109
  ## License
package/dist/index.js CHANGED
@@ -1,53 +1,73 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var _postcss = require('postcss');
7
+ var _postcss = require("postcss");
8
8
 
9
- var _commentRemover = require('./lib/commentRemover');
9
+ var _commentRemover = require("./lib/commentRemover");
10
10
 
11
11
  var _commentRemover2 = _interopRequireDefault(_commentRemover);
12
12
 
13
- var _commentParser = require('./lib/commentParser');
13
+ var _commentParser = require("./lib/commentParser");
14
14
 
15
15
  var _commentParser2 = _interopRequireDefault(_commentParser);
16
16
 
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
 
19
- var space = _postcss.list.space;
20
- exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () {
21
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
+ const { space } = _postcss.list;
22
20
 
23
- var remover = new _commentRemover2.default(opts);
21
+ exports.default = (0, _postcss.plugin)("postcss-discard-comments", (opts = {}) => {
22
+ const remover = new _commentRemover2.default(opts);
23
+ const matcherCache = {};
24
+ const replacerCache = {};
24
25
 
25
26
  function matchesComments(source) {
26
- return (0, _commentParser2.default)(source).filter(function (node) {
27
- return node.type === 'comment';
28
- });
27
+ if (matcherCache[source]) {
28
+ return matcherCache[source];
29
+ }
30
+
31
+ const result = (0, _commentParser2.default)(source).filter(([type]) => type);
32
+
33
+ matcherCache[source] = result;
34
+
35
+ return result;
29
36
  }
30
37
 
31
- function replaceComments(source) {
32
- var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' ';
38
+ function replaceComments(source, separator = " ") {
39
+ const key = source + "@|@" + separator;
40
+
41
+ if (replacerCache[key]) {
42
+ return replacerCache[key];
43
+ }
33
44
 
34
- var parsed = (0, _commentParser2.default)(source).reduce(function (value, node) {
35
- if (node.type !== 'comment') {
36
- return value + node.value;
45
+ const parsed = (0, _commentParser2.default)(source).reduce((value, [type, start, end]) => {
46
+ const contents = source.slice(start, end);
47
+
48
+ if (!type) {
49
+ return value + contents;
37
50
  }
38
- if (remover.canRemove(node.value)) {
51
+
52
+ if (remover.canRemove(contents)) {
39
53
  return value + separator;
40
54
  }
41
- return value + '/*' + node.value + '*/';
42
- }, '');
43
55
 
44
- return space(parsed).join(' ');
56
+ return `${value}/*${contents}*/`;
57
+ }, "");
58
+
59
+ const result = space(parsed).join(" ");
60
+
61
+ replacerCache[key] = result;
62
+
63
+ return result;
45
64
  }
46
65
 
47
- return function (css) {
48
- css.walk(function (node) {
49
- if (node.type === 'comment' && remover.canRemove(node.text)) {
66
+ return css => {
67
+ css.walk(node => {
68
+ if (node.type === "comment" && remover.canRemove(node.text)) {
50
69
  node.remove();
70
+
51
71
  return;
52
72
  }
53
73
 
@@ -55,37 +75,45 @@ exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () {
55
75
  node.raws.between = replaceComments(node.raws.between);
56
76
  }
57
77
 
58
- if (node.type === 'decl') {
78
+ if (node.type === "decl") {
59
79
  if (node.raws.value && node.raws.value.raw) {
60
80
  if (node.raws.value.value === node.value) {
61
81
  node.value = replaceComments(node.raws.value.raw);
62
82
  } else {
63
83
  node.value = replaceComments(node.value);
64
84
  }
85
+
65
86
  node.raws.value = null;
66
87
  }
88
+
67
89
  if (node.raws.important) {
68
90
  node.raws.important = replaceComments(node.raws.important);
69
- var b = matchesComments(node.raws.important);
70
- node.raws.important = b.length ? node.raws.important : '!important';
91
+
92
+ const b = matchesComments(node.raws.important);
93
+
94
+ node.raws.important = b.length ? node.raws.important : "!important";
71
95
  }
96
+
72
97
  return;
73
98
  }
74
99
 
75
- if (node.type === 'rule' && node.raws.selector && node.raws.selector.raw) {
76
- node.raws.selector.raw = replaceComments(node.raws.selector.raw, '');
100
+ if (node.type === "rule" && node.raws.selector && node.raws.selector.raw) {
101
+ node.raws.selector.raw = replaceComments(node.raws.selector.raw, "");
102
+
77
103
  return;
78
104
  }
79
105
 
80
- if (node.type === 'atrule') {
106
+ if (node.type === "atrule") {
81
107
  if (node.raws.afterName) {
82
- var commentsReplaced = replaceComments(node.raws.afterName);
108
+ const commentsReplaced = replaceComments(node.raws.afterName);
109
+
83
110
  if (!commentsReplaced.length) {
84
- node.raws.afterName = commentsReplaced + ' ';
111
+ node.raws.afterName = commentsReplaced + " ";
85
112
  } else {
86
- node.raws.afterName = ' ' + commentsReplaced + ' ';
113
+ node.raws.afterName = " " + commentsReplaced + " ";
87
114
  }
88
115
  }
116
+
89
117
  if (node.raws.params && node.raws.params.raw) {
90
118
  node.raws.params.raw = replaceComments(node.raws.params.raw);
91
119
  }
@@ -93,4 +121,4 @@ exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () {
93
121
  });
94
122
  };
95
123
  });
96
- module.exports = exports['default'];
124
+ module.exports = exports["default"];
@@ -5,32 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = commentParser;
7
7
  function commentParser(input) {
8
- var tokens = [];
9
- var length = input.length;
10
- var pos = 0;
11
- var next = void 0;
8
+ const tokens = [];
9
+ const length = input.length;
10
+ let pos = 0;
11
+ let next;
12
12
 
13
13
  while (pos < length) {
14
14
  next = input.indexOf('/*', pos);
15
15
 
16
16
  if (~next) {
17
- tokens.push({
18
- type: 'other',
19
- value: input.slice(pos, next)
20
- });
17
+ tokens.push([0, pos, next]);
21
18
  pos = next;
22
19
 
23
20
  next = input.indexOf('*/', pos + 2);
24
- tokens.push({
25
- type: 'comment',
26
- value: input.slice(pos + 2, next)
27
- });
21
+ tokens.push([1, pos + 2, next]);
28
22
  pos = next + 2;
29
23
  } else {
30
- tokens.push({
31
- type: 'other',
32
- value: input.slice(pos)
33
- });
24
+ tokens.push([0, pos, length]);
34
25
  pos = length;
35
26
  }
36
27
  }
@@ -8,11 +8,13 @@ function CommentRemover(options) {
8
8
  }
9
9
 
10
10
  CommentRemover.prototype.canRemove = function (comment) {
11
- var remove = this.options.remove;
11
+ const remove = this.options.remove;
12
+
12
13
  if (remove) {
13
14
  return remove(comment);
14
15
  } else {
15
- var isImportant = comment.indexOf('!') === 0;
16
+ const isImportant = comment.indexOf('!') === 0;
17
+
16
18
  if (!isImportant) {
17
19
  return true;
18
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-discard-comments",
3
- "version": "4.0.0-rc.0",
3
+ "version": "4.0.2",
4
4
  "description": "Discard comments in your CSS files with PostCSS.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -19,24 +19,24 @@
19
19
  "license": "MIT",
20
20
  "devDependencies": {
21
21
  "babel-cli": "^6.0.0",
22
- "cross-env": "^3.0.0",
23
- "postcss-scss": "^0.3.0",
24
- "postcss-simple-vars": "^3.0.0"
22
+ "cross-env": "^5.0.0",
23
+ "postcss-scss": "^2.0.0",
24
+ "postcss-simple-vars": "^5.0.1"
25
25
  },
26
- "homepage": "https://github.com/ben-eb/cssnano",
26
+ "homepage": "https://github.com/cssnano/cssnano",
27
27
  "author": {
28
28
  "name": "Ben Briggs",
29
29
  "email": "beneb.info@gmail.com",
30
30
  "url": "http://beneb.info"
31
31
  },
32
- "repository": "ben-eb/cssnano",
32
+ "repository": "cssnano/cssnano",
33
33
  "dependencies": {
34
- "postcss": "^6.0.0"
34
+ "postcss": "^7.0.0"
35
35
  },
36
36
  "bugs": {
37
- "url": "https://github.com/ben-eb/cssnano/issues"
37
+ "url": "https://github.com/cssnano/cssnano/issues"
38
38
  },
39
39
  "engines": {
40
- "node": ">=4"
40
+ "node": ">=6.9.0"
41
41
  }
42
42
  }
package/CHANGELOG.md DELETED
@@ -1,75 +0,0 @@
1
- # 4.0.0-rc.0
2
-
3
- * Breaking: Drops support for Node 0.12, we now require at least Node 4.
4
- * Breaking: Update PostCSS to 6.0.0.
5
-
6
- # 2.0.4
7
-
8
- * Now compiled with Babel 6.
9
-
10
- # 2.0.3
11
-
12
- * Fixes an issue where comments that were removed from selectors were replaced
13
- by a single space.
14
-
15
- # 2.0.2
16
-
17
- * Fixes an integration issue where comments inside values transformed by other
18
- processors had their values reset to their original state before the
19
- comments were removed.
20
-
21
- # 2.0.1
22
-
23
- * Replaces a dependency on node-balanced with internal comments parser.
24
-
25
- # 2.0.0
26
-
27
- * Upgraded to PostCSS 5 (thanks to @avanes).
28
-
29
- # 1.2.1
30
-
31
- * Improved performance by iterating the AST in a single pass.
32
-
33
- # 1.2.0
34
-
35
- * Adds support for user-directed removal of comments, with the `remove`
36
- option (thanks to @dmitrykiselyov).
37
- * `removeAllButFirst` now operates on each CSS tree, rather than the first one
38
- passed to the plugin.
39
- * Fixes to pass the PostCSS plugin guidelines.
40
-
41
- # 1.1.3
42
-
43
- * As PostCSS handles the source map content, there is no need to check for
44
- the existence of a '#' at position 0 of the comment. This patch fixes this
45
- behaviour.
46
-
47
- # 1.1.2
48
-
49
- * Fixes an issue where comment separated values were being incorrectly
50
- transformed to not have spaces separating them instead, in `decl.value`.
51
- e.g. `10px/*test*/20px` became `10px20px` in `decl.value` but not
52
- `decl._value.raw`.
53
-
54
- # 1.1.1
55
-
56
- * Fixes a bug where non-special comments, with an exclamation mark in any part
57
- of the text, were not being removed.
58
-
59
- # 1.1.0
60
-
61
- * Now uses the PostCSS `4.1` plugin API.
62
- * Adds support for transforming comments inside `!important` values.
63
-
64
- # 1.0.2
65
-
66
- * Adds a JSHint config, tidy up unnecessary lines of code.
67
-
68
- # 1.0.1
69
-
70
- * Fixed a bug which affected initializing the plugin with no options.
71
- * Stopped the plugin from trying to match comments in empty strings.
72
-
73
- # 1.0.0
74
-
75
- * Initial release.