Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = void 0;
|
---|
| 7 |
|
---|
| 8 | var _alphanumSort = _interopRequireDefault(require("alphanum-sort"));
|
---|
| 9 |
|
---|
| 10 | var _uniqs = _interopRequireDefault(require("uniqs"));
|
---|
| 11 |
|
---|
| 12 | var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
---|
| 13 |
|
---|
| 14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 15 |
|
---|
| 16 | function parseSelectors(selectors, callback) {
|
---|
| 17 | return (0, _postcssSelectorParser.default)(callback).processSync(selectors);
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | function unique(rule) {
|
---|
| 21 | rule.selector = (0, _alphanumSort.default)((0, _uniqs.default)(rule.selectors), {
|
---|
| 22 | insensitive: true
|
---|
| 23 | }).join();
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | function pluginCreator() {
|
---|
| 27 | return {
|
---|
| 28 | postcssPlugin: 'postcss-unique-selectors',
|
---|
| 29 |
|
---|
| 30 | OnceExit(css) {
|
---|
| 31 | css.walkRules(nodes => {
|
---|
| 32 | let comments = [];
|
---|
| 33 | nodes.selector = parseSelectors(nodes.selector, selNode => {
|
---|
| 34 | selNode.walk(sel => {
|
---|
| 35 | if (sel.type === 'comment') {
|
---|
| 36 | comments.push(sel.value);
|
---|
| 37 | sel.remove();
|
---|
| 38 | return;
|
---|
| 39 | } else {
|
---|
| 40 | return sel;
|
---|
| 41 | }
|
---|
| 42 | });
|
---|
| 43 | });
|
---|
| 44 | unique(nodes);
|
---|
| 45 | nodes.selectors = nodes.selectors.concat(comments);
|
---|
| 46 | });
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | };
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | pluginCreator.postcss = true;
|
---|
| 53 | var _default = pluginCreator;
|
---|
| 54 | exports.default = _default;
|
---|
| 55 | module.exports = exports.default; |
---|
Note:
See
TracBrowser
for help on using the repository browser.