|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 | const plugin = 'postcss-discard-empty';
|
|---|
| 3 | /**
|
|---|
| 4 | * @param {import('postcss').Root} css
|
|---|
| 5 | * @param {import('postcss').Result} result
|
|---|
| 6 | * @return {void}
|
|---|
| 7 | */
|
|---|
| 8 | function discardAndReport(css, result) {
|
|---|
| 9 | /**
|
|---|
| 10 | * @param {import('postcss').AnyNode} node
|
|---|
| 11 | * @return {void}
|
|---|
| 12 | */
|
|---|
| 13 | function discardEmpty(node) {
|
|---|
| 14 | const { type } = node;
|
|---|
| 15 | /** @type {(import('postcss').ChildNode | import('postcss').ChildProps)[] | undefined} */
|
|---|
| 16 | const sub = /** @type {any} */ (node).nodes;
|
|---|
| 17 | if (sub) {
|
|---|
| 18 | /** @type {import('postcss').Container} */ (node).each(discardEmpty);
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | if (
|
|---|
| 22 | (type === 'decl' && !node.value && !node.prop.startsWith('--')) ||
|
|---|
| 23 | (type === 'rule' && !node.selector) ||
|
|---|
| 24 | (sub && !sub.length) ||
|
|---|
| 25 | (type === 'atrule' &&
|
|---|
| 26 | ((!sub && !node.params) ||
|
|---|
| 27 | (!node.params &&
|
|---|
| 28 | !(/** @type {import('postcss').ChildNode[]}*/ (sub).length))))
|
|---|
| 29 | ) {
|
|---|
| 30 | node.remove();
|
|---|
| 31 |
|
|---|
| 32 | result.messages.push({
|
|---|
| 33 | type: 'removal',
|
|---|
| 34 | plugin,
|
|---|
| 35 | node,
|
|---|
| 36 | });
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | css.each(discardEmpty);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * @type {import('postcss').PluginCreator<void>}
|
|---|
| 45 | * @return {import('postcss').Plugin}
|
|---|
| 46 | */
|
|---|
| 47 | function pluginCreator() {
|
|---|
| 48 | return {
|
|---|
| 49 | postcssPlugin: plugin,
|
|---|
| 50 | OnceExit(css, { result }) {
|
|---|
| 51 | discardAndReport(css, result);
|
|---|
| 52 | },
|
|---|
| 53 | };
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | pluginCreator.postcss = true;
|
|---|
| 57 | module.exports = pluginCreator;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.