数通智联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
523 B

2 years ago
'use strict';
const { isAtRule, isRule } = require('./typeGuards');
/**
* Find the at-rule in which a rule is nested.
*
* Returns `null` if the rule is not nested within an at-rule.
*
* @param {import('postcss').Rule} rule
* @returns {null | import('postcss').AtRule}
*/
module.exports = function findAtRuleContext(rule) {
const parent = rule.parent;
if (!parent) {
return null;
}
if (isAtRule(parent)) {
return parent;
}
if (isRule(parent)) {
return findAtRuleContext(parent);
}
return null;
};