diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/postcss-discard-comments | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/postcss-discard-comments')
7 files changed, 429 insertions, 0 deletions
diff --git a/node_modules/postcss-discard-comments/CHANGELOG.md b/node_modules/postcss-discard-comments/CHANGELOG.md new file mode 100644 index 00000000..dbbd0ec1 --- /dev/null +++ b/node_modules/postcss-discard-comments/CHANGELOG.md @@ -0,0 +1,70 @@ +# 2.0.4 + +* Now compiled with Babel 6. + +# 2.0.3 + +* Fixes an issue where comments that were removed from selectors were replaced + by a single space. + +# 2.0.2 + +* Fixes an integration issue where comments inside values transformed by other + processors had their values reset to their original state before the + comments were removed. + +# 2.0.1 + +* Replaces a dependency on node-balanced with internal comments parser. + +# 2.0.0 + +* Upgraded to PostCSS 5 (thanks to @avanes). + +# 1.2.1 + +* Improved performance by iterating the AST in a single pass. + +# 1.2.0 + +* Adds support for user-directed removal of comments, with the `remove` + option (thanks to @dmitrykiselyov). +* `removeAllButFirst` now operates on each CSS tree, rather than the first one + passed to the plugin. +* Fixes to pass the PostCSS plugin guidelines. + +# 1.1.3 + +* As PostCSS handles the source map content, there is no need to check for + the existence of a '#' at position 0 of the comment. This patch fixes this + behaviour. + +# 1.1.2 + +* Fixes an issue where comment separated values were being incorrectly + transformed to not have spaces separating them instead, in `decl.value`. + e.g. `10px/*test*/20px` became `10px20px` in `decl.value` but not + `decl._value.raw`. + +# 1.1.1 + +* Fixes a bug where non-special comments, with an exclamation mark in any part + of the text, were not being removed. + +# 1.1.0 + +* Now uses the PostCSS `4.1` plugin API. +* Adds support for transforming comments inside `!important` values. + +# 1.0.2 + +* Adds a JSHint config, tidy up unnecessary lines of code. + +# 1.0.1 + +* Fixed a bug which affected initializing the plugin with no options. +* Stopped the plugin from trying to match comments in empty strings. + +# 1.0.0 + +* Initial release. diff --git a/node_modules/postcss-discard-comments/LICENSE-MIT b/node_modules/postcss-discard-comments/LICENSE-MIT new file mode 100644 index 00000000..fd0e863a --- /dev/null +++ b/node_modules/postcss-discard-comments/LICENSE-MIT @@ -0,0 +1,22 @@ +Copyright (c) Ben Briggs <beneb.info@gmail.com> (http://beneb.info) + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/postcss-discard-comments/README.md b/node_modules/postcss-discard-comments/README.md new file mode 100644 index 00000000..032e21e6 --- /dev/null +++ b/node_modules/postcss-discard-comments/README.md @@ -0,0 +1,118 @@ +# [postcss][postcss]-discard-comments [][ci] [][npm] [][deps] + +> Discard comments in your CSS files with PostCSS. + + +## Install + +With [npm](https://npmjs.org/package/postcss-discard-comments) do: + +``` +npm install postcss-discard-comments --save +``` + + +## Example + +### Input + +```css +h1/* heading */{ + margin: 0 auto +} +``` + +### Output + +```css +h1 { + margin: 0 auto +} +``` + +This module discards comments from your CSS files; by default, it will remove +all regular comments (`/* comment */`) and preserve comments marked as important +(`/*! important */`). + +Note that this module does not handle source map comments because they are not +available to it; PostCSS handles this internally, so if they are removed then +you will have to [configure source maps in PostCSS][maps]. + +[maps]: https://github.com/postcss/postcss/blob/master/docs/source-maps.md + + +## API + +### comments([options]) + +#### options + +##### remove(function) + +Type: `function` +Return: `boolean` +Variable: `comment` contains a comment without `/**/` + +For each comment, return true to remove, or false to keep the comment. + +```js +function(comment) {} +``` + +```js +var css = '/* headings *//*@ h1 */h1{margin:0 auto}/*@ h2 */h2{color:red}'; +console.log(postcss(comments({ + remove: function(comment) { return comment[0] == "@"; } +})).process(css).css); +//=> /* headings */h1{margin:0 auto}h2{color:red} +``` +**NOTE:** If you use the `remove` function other options will not be available. + +##### removeAll + +Type: `boolean` +Default: `false` + +Remove all comments marked as important. + +```js +var css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}'; +console.log(postcss(comments({removeAll: true})).process(css).css); +//=> h1{margin:0 auto}h2{color:red} +``` + +##### removeAllButFirst + +Type: `boolean` +Default: `false` + +Remove all comments marked as important, but the first one. + +```js +var css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}'; +console.log(postcss(comments({removeAllButFirst: true})).process(css).css); +//=> /*! heading */h1{margin:0 auto}h2{color:red} +``` + + +## Usage + +See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for +examples for your environment. + + +## Contributing + +Pull requests are welcome. If you add functionality, then please add unit tests +to cover it. + + +## License + +MIT © Ben Briggs + + +[ci]: https://travis-ci.org/ben-eb/postcss-discard-comments +[deps]: https://gemnasium.com/ben-eb/postcss-discard-comments +[npm]: http://badge.fury.io/js/postcss-discard-comments +[postcss]: https://github.com/postcss/postcss diff --git a/node_modules/postcss-discard-comments/dist/index.js b/node_modules/postcss-discard-comments/dist/index.js new file mode 100644 index 00000000..92de696d --- /dev/null +++ b/node_modules/postcss-discard-comments/dist/index.js @@ -0,0 +1,98 @@ +'use strict'; + +exports.__esModule = true; + +var _commentRemover = require('./lib/commentRemover'); + +var _commentRemover2 = _interopRequireDefault(_commentRemover); + +var _commentParser = require('./lib/commentParser'); + +var _commentParser2 = _interopRequireDefault(_commentParser); + +var _postcss = require('postcss'); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var space = _postcss.list.space; + +exports.default = (0, _postcss.plugin)('postcss-discard-comments', function () { + var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + + var remover = new _commentRemover2.default(opts); + + function matchesComments(source) { + return (0, _commentParser2.default)(source).filter(function (node) { + return node.type === 'comment'; + }); + } + + function replaceComments(source) { + var separator = arguments.length <= 1 || arguments[1] === undefined ? ' ' : arguments[1]; + + if (!source) { + return source; + } + var parsed = (0, _commentParser2.default)(source).reduce(function (value, node) { + if (node.type !== 'comment') { + return value + node.value; + } + if (remover.canRemove(node.value)) { + return value + separator; + } + return value + '/*' + node.value + '*/'; + }, ''); + + return space(parsed).join(' '); + } + + return function (css) { + css.walk(function (node) { + if (node.type === 'comment' && remover.canRemove(node.text)) { + node.remove(); + return; + } + + if (node.raws.between) { + node.raws.between = replaceComments(node.raws.between); + } + + if (node.type === 'decl') { + if (node.raws.value && node.raws.value.raw) { + if (node.raws.value.value === node.value) { + node.value = replaceComments(node.raws.value.raw); + } else { + node.value = replaceComments(node.value); + } + node.raws.value = null; + } + if (node.raws.important) { + node.raws.important = replaceComments(node.raws.important); + var b = matchesComments(node.raws.important); + node.raws.important = b.length ? node.raws.important : '!important'; + } + return; + } + + if (node.type === 'rule' && node.raws.selector && node.raws.selector.raw) { + node.raws.selector.raw = replaceComments(node.raws.selector.raw, ''); + return; + } + + if (node.type === 'atrule') { + if (node.raws.afterName) { + var commentsReplaced = replaceComments(node.raws.afterName); + if (!commentsReplaced.length) { + node.raws.afterName = commentsReplaced + ' '; + } else { + node.raws.afterName = ' ' + commentsReplaced + ' '; + } + } + if (node.raws.params && node.raws.params.raw) { + node.raws.params.raw = replaceComments(node.raws.params.raw); + } + } + }); + }; +}); +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/postcss-discard-comments/dist/lib/commentParser.js b/node_modules/postcss-discard-comments/dist/lib/commentParser.js new file mode 100644 index 00000000..1b2e487f --- /dev/null +++ b/node_modules/postcss-discard-comments/dist/lib/commentParser.js @@ -0,0 +1,41 @@ +'use strict'; + +exports.__esModule = true; +exports.default = commentParser; +function commentParser(input) { + var tokens = []; + var length = input.length; + var pos = 0; + var next = undefined; + + while (pos < length) { + next = input.indexOf('/*', pos); + + if (~next) { + tokens.push({ + type: 'other', + value: input.slice(pos, next) + }); + pos = next; + + next = input.indexOf('*/', pos + 2); + if (! ~next) { + throw new Error('postcss-discard-comments: Unclosed */'); + } + tokens.push({ + type: 'comment', + value: input.slice(pos + 2, next) + }); + pos = next + 2; + } else { + tokens.push({ + type: 'other', + value: input.slice(pos) + }); + pos = length; + } + } + + return tokens; +}; +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/postcss-discard-comments/dist/lib/commentRemover.js b/node_modules/postcss-discard-comments/dist/lib/commentRemover.js new file mode 100644 index 00000000..56019a30 --- /dev/null +++ b/node_modules/postcss-discard-comments/dist/lib/commentRemover.js @@ -0,0 +1,28 @@ +'use strict'; + +exports.__esModule = true; +function CommentRemover(options) { + this.options = options; +} + +CommentRemover.prototype.canRemove = function (comment) { + var remove = this.options.remove; + if (remove) { + return remove(comment); + } else { + var isImportant = comment.indexOf('!') === 0; + if (!isImportant) { + return true; + } else if (isImportant) { + if (this.options.removeAll || this._hasFirst) { + return true; + } else if (this.options.removeAllButFirst && !this._hasFirst) { + this._hasFirst = true; + return false; + } + } + } +}; + +exports.default = CommentRemover; +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/postcss-discard-comments/package.json b/node_modules/postcss-discard-comments/package.json new file mode 100644 index 00000000..dedc4374 --- /dev/null +++ b/node_modules/postcss-discard-comments/package.json @@ -0,0 +1,52 @@ +{ + "name": "postcss-discard-comments", + "version": "2.0.4", + "description": "Discard comments in your CSS files with PostCSS.", + "main": "dist/index.js", + "files": [ + "dist", + "LICENSE-MIT" + ], + "scripts": { + "pretest": "eslint src", + "prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/", + "test": "ava src/__tests__" + }, + "keywords": [ + "css", + "comments", + "postcss", + "postcss-plugin" + ], + "license": "MIT", + "devDependencies": { + "ava": "^0.11.0", + "babel-cli": "^6.5.1", + "babel-core": "^6.5.1", + "babel-plugin-add-module-exports": "^0.1.2", + "babel-preset-es2015": "^6.5.0", + "babel-preset-es2015-loose": "^7.0.0", + "babel-preset-stage-0": "^6.5.0", + "del-cli": "^0.2.0", + "eslint": "^1.10.3", + "eslint-config-cssnano": "^1.0.0", + "postcss-scss": "^0.1.3", + "postcss-simple-vars": "^1.2.0" + }, + "homepage": "https://github.com/ben-eb/postcss-discard-comments", + "author": { + "name": "Ben Briggs", + "email": "beneb.info@gmail.com", + "url": "http://beneb.info" + }, + "repository": "ben-eb/postcss-discard-comments", + "dependencies": { + "postcss": "^5.0.14" + }, + "ava": { + "require": "babel-core/register" + }, + "eslintConfig": { + "extends": "cssnano" + } +} |
