mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-18 20:15:38 +00:00
28 lines
504 B
JavaScript
28 lines
504 B
JavaScript
import { isAtRule, isRule } from './typeGuards.mjs';
|
|
|
|
/**
|
|
* 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}
|
|
*/
|
|
export default function findAtRuleContext(rule) {
|
|
const parent = rule.parent;
|
|
|
|
if (!parent) {
|
|
return null;
|
|
}
|
|
|
|
if (isAtRule(parent)) {
|
|
return parent;
|
|
}
|
|
|
|
if (isRule(parent)) {
|
|
return findAtRuleContext(parent);
|
|
}
|
|
|
|
return null;
|
|
}
|