postcss-discard-comments 4.0.0-rc.2 → 4.0.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/README.md +1 -1
- package/dist/index.js +11 -26
- package/dist/lib/commentParser.js +4 -4
- package/dist/lib/commentRemover.js +2 -2
- package/package.json +8 -8
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/
|
|
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
|
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
8
|
-
|
|
9
7
|
var _postcss = require('postcss');
|
|
10
8
|
|
|
11
9
|
var _commentRemover = require('./lib/commentRemover');
|
|
@@ -18,31 +16,18 @@ var _commentParser2 = _interopRequireDefault(_commentParser);
|
|
|
18
16
|
|
|
19
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () {
|
|
23
|
-
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
19
|
+
const { space } = _postcss.list;
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
exports.default = (0, _postcss.plugin)('postcss-discard-comments', (opts = {}) => {
|
|
22
|
+
const remover = new _commentRemover2.default(opts);
|
|
26
23
|
|
|
27
24
|
function matchesComments(source) {
|
|
28
|
-
return (0, _commentParser2.default)(source).filter(
|
|
29
|
-
var _ref2 = _slicedToArray(_ref, 1),
|
|
30
|
-
type = _ref2[0];
|
|
31
|
-
|
|
32
|
-
return type;
|
|
33
|
-
});
|
|
25
|
+
return (0, _commentParser2.default)(source).filter(([type]) => type);
|
|
34
26
|
}
|
|
35
27
|
|
|
36
|
-
function replaceComments(source) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var parsed = (0, _commentParser2.default)(source).reduce(function (value, _ref3) {
|
|
40
|
-
var _ref4 = _slicedToArray(_ref3, 3),
|
|
41
|
-
type = _ref4[0],
|
|
42
|
-
start = _ref4[1],
|
|
43
|
-
end = _ref4[2];
|
|
44
|
-
|
|
45
|
-
var contents = source.slice(start, end);
|
|
28
|
+
function replaceComments(source, separator = ' ') {
|
|
29
|
+
const parsed = (0, _commentParser2.default)(source).reduce((value, [type, start, end]) => {
|
|
30
|
+
const contents = source.slice(start, end);
|
|
46
31
|
if (!type) {
|
|
47
32
|
return value + contents;
|
|
48
33
|
}
|
|
@@ -55,8 +40,8 @@ exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () {
|
|
|
55
40
|
return space(parsed).join(' ');
|
|
56
41
|
}
|
|
57
42
|
|
|
58
|
-
return
|
|
59
|
-
css.walk(
|
|
43
|
+
return css => {
|
|
44
|
+
css.walk(node => {
|
|
60
45
|
if (node.type === 'comment' && remover.canRemove(node.text)) {
|
|
61
46
|
node.remove();
|
|
62
47
|
return;
|
|
@@ -77,7 +62,7 @@ exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () {
|
|
|
77
62
|
}
|
|
78
63
|
if (node.raws.important) {
|
|
79
64
|
node.raws.important = replaceComments(node.raws.important);
|
|
80
|
-
|
|
65
|
+
const b = matchesComments(node.raws.important);
|
|
81
66
|
node.raws.important = b.length ? node.raws.important : '!important';
|
|
82
67
|
}
|
|
83
68
|
return;
|
|
@@ -90,7 +75,7 @@ exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () {
|
|
|
90
75
|
|
|
91
76
|
if (node.type === 'atrule') {
|
|
92
77
|
if (node.raws.afterName) {
|
|
93
|
-
|
|
78
|
+
const commentsReplaced = replaceComments(node.raws.afterName);
|
|
94
79
|
if (!commentsReplaced.length) {
|
|
95
80
|
node.raws.afterName = commentsReplaced + ' ';
|
|
96
81
|
} else {
|
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = commentParser;
|
|
7
7
|
function commentParser(input) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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);
|
|
@@ -8,11 +8,11 @@ function CommentRemover(options) {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
CommentRemover.prototype.canRemove = function (comment) {
|
|
11
|
-
|
|
11
|
+
const remove = this.options.remove;
|
|
12
12
|
if (remove) {
|
|
13
13
|
return remove(comment);
|
|
14
14
|
} else {
|
|
15
|
-
|
|
15
|
+
const isImportant = comment.indexOf('!') === 0;
|
|
16
16
|
if (!isImportant) {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-discard-comments",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
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": "^
|
|
23
|
-
"postcss-scss": "^0.
|
|
24
|
-
"postcss-simple-vars": "^
|
|
22
|
+
"cross-env": "^5.0.0",
|
|
23
|
+
"postcss-scss": "^1.0.0",
|
|
24
|
+
"postcss-simple-vars": "^4.0.0"
|
|
25
25
|
},
|
|
26
|
-
"homepage": "https://github.com/
|
|
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": "
|
|
32
|
+
"repository": "cssnano/cssnano",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"postcss": "^6.0.0"
|
|
35
35
|
},
|
|
36
36
|
"bugs": {
|
|
37
|
-
"url": "https://github.com/
|
|
37
|
+
"url": "https://github.com/cssnano/cssnano/issues"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
|
-
"node": ">=
|
|
40
|
+
"node": ">=6.9.0"
|
|
41
41
|
}
|
|
42
42
|
}
|