source: frontend/node_modules/stylehacks/src/plugins/htmlCombinatorCommentBody.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2const parser = require('postcss-selector-parser');
3const exists = require('../exists');
4const isMixin = require('../isMixin');
5const BasePlugin = require('../plugin');
6const { IE_5_5, IE_6, IE_7 } = require('../dictionary/browsers');
7const { SELECTOR } = require('../dictionary/identifiers');
8const { RULE } = require('../dictionary/postcss');
9const { BODY, HTML } = require('../dictionary/tags');
10
11module.exports = class HtmlCombinatorCommentBody extends BasePlugin {
12 /** @param {import('postcss').Result} result */
13 constructor(result) {
14 super([IE_5_5, IE_6, IE_7], [RULE], result);
15 }
16
17 /**
18 * @param {import('postcss').Rule} rule
19 * @return {void}
20 */
21 detect(rule) {
22 if (isMixin(rule)) {
23 return;
24 }
25 if (rule.raws.selector && rule.raws.selector.raw) {
26 parser(this.analyse(rule)).processSync(rule.raws.selector.raw);
27 }
28 }
29
30 /** @param {import('postcss').Rule} rule
31 * @return {parser.SyncProcessor<void>}
32 */
33 analyse(rule) {
34 return (selectors) => {
35 selectors.each((selector) => {
36 if (
37 exists(selector, 0, HTML) &&
38 (exists(selector, 1, '>') || exists(selector, 1, '~')) &&
39 selector.at(2) &&
40 selector.at(2).type === 'comment' &&
41 exists(selector, 3, ' ') &&
42 exists(selector, 4, BODY) &&
43 exists(selector, 5, ' ') &&
44 selector.at(6)
45 ) {
46 this.push(rule, {
47 identifier: SELECTOR,
48 hack: selector.toString(),
49 });
50 }
51 });
52 };
53 }
54};
Note: See TracBrowser for help on using the repository browser.