UNPKG

449 BJavaScriptView Raw
1'use strict';
2
3/**
4 * Find the at-rule in which a rule is nested.
5 *
6 * Returns `null` if the rule is not nested within an at-rule.
7 *
8 * @param {import('postcss').Rule} rule
9 * @returns {null | import('postcss').AtRule}
10 */
11module.exports = function findAtRuleContext(rule) {
12 const parent = rule.parent;
13
14 if (parent.type === 'root') {
15 return null;
16 }
17
18 if (parent.type === 'atrule') {
19 return parent;
20 }
21
22 return findAtRuleContext(parent);
23};