Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit bb84580

Browse files
committed
Remove indent on selector walker
1 parent 39756e6 commit bb84580

File tree

1 file changed

+46
-48
lines changed

1 file changed

+46
-48
lines changed

index.js

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,62 +26,60 @@ module.exports = postcss.plugin('postcss-dir-pseudo-class', (opts) => (root) =>
2626
// update the rule selector
2727
rule.selector = selectorParser((selectors) => {
2828
// for each (comma separated) selector
29-
selectors.nodes.forEach(
30-
(selector) => {
31-
// walk all selector nodes that are :dir pseudo-classes
32-
selector.walk((node) => {
33-
if ('pseudo' === node.type && ':dir' === node.value) {
34-
// previous and next selector nodes
35-
const prev = node.prev();
36-
const next = node.next();
29+
selectors.nodes.forEach((selector) => {
30+
// walk all selector nodes that are :dir pseudo-classes
31+
selector.walk((node) => {
32+
if ('pseudo' === node.type && ':dir' === node.value) {
33+
// previous and next selector nodes
34+
const prev = node.prev();
35+
const next = node.next();
3736

38-
const prevIsSpaceCombinator = prev && prev.type && 'combinator' === prev.type && ' ' === prev.value;
39-
const nextIsSpaceCombinator = next && next.type && 'combinator' === next.type && ' ' === next.value;
37+
const prevIsSpaceCombinator = prev && prev.type && 'combinator' === prev.type && ' ' === prev.value;
38+
const nextIsSpaceCombinator = next && next.type && 'combinator' === next.type && ' ' === next.value;
4039

41-
// preserve the selector tree
42-
if (prevIsSpaceCombinator && (nextIsSpaceCombinator || !next)) {
43-
node.replaceWith(
44-
selectorParser.universal()
45-
);
46-
} else {
47-
node.remove();
48-
}
49-
50-
// conditionally prepend a combinator before inserting the [dir] attribute
51-
const first = selector.nodes[0];
52-
const firstIsSpaceCombinator = first && 'combinator' === first.type && ' ' === first.value;
53-
const firstIsRoot = first && 'pseudo' === first.type && ':root' === first.value;
54-
55-
if (first && !firstIsRoot && !firstIsSpaceCombinator) {
56-
selector.prepend(
57-
selectorParser.combinator({
58-
value: ' '
59-
})
60-
);
61-
}
62-
63-
// value of the :dir pseudo-class
64-
const value = node.nodes.toString();
40+
// preserve the selector tree
41+
if (prevIsSpaceCombinator && (nextIsSpaceCombinator || !next)) {
42+
node.replaceWith(
43+
selectorParser.universal()
44+
);
45+
} else {
46+
node.remove();
47+
}
6548

66-
// whether that value matches the presumed direction
67-
const isdir = opts && Object(opts).dir === value;
49+
// conditionally prepend a combinator before inserting the [dir] attribute
50+
const first = selector.nodes[0];
51+
const firstIsSpaceCombinator = first && 'combinator' === first.type && ' ' === first.value;
52+
const firstIsRoot = first && 'pseudo' === first.type && ':root' === first.value;
6853

54+
if (first && !firstIsRoot && !firstIsSpaceCombinator) {
6955
selector.prepend(
70-
// prepend :root if the direction is presumed
71-
isdir ? selectorParser.pseudo({
72-
value: ':root'
73-
})
74-
// otherwise, prepend the dir attribute
75-
: selectorParser.attribute({
76-
attribute: 'dir',
77-
operator: '=',
78-
value: `"${ value }"`
56+
selectorParser.combinator({
57+
value: ' '
7958
})
8059
);
8160
}
82-
});
83-
}
84-
);
61+
62+
// value of the :dir pseudo-class
63+
const value = node.nodes.toString();
64+
65+
// whether that value matches the presumed direction
66+
const isdir = opts && Object(opts).dir === value;
67+
68+
selector.prepend(
69+
// prepend :root if the direction is presumed
70+
isdir ? selectorParser.pseudo({
71+
value: ':root'
72+
})
73+
// otherwise, prepend the dir attribute
74+
: selectorParser.attribute({
75+
attribute: 'dir',
76+
operator: '=',
77+
value: `"${ value }"`
78+
})
79+
);
80+
}
81+
});
82+
});
8583
}).process(rule.selector).result;
8684
});
8785
});

0 commit comments

Comments
 (0)