mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-18 03:55:32 +00:00
26 lines
531 B
JavaScript
26 lines
531 B
JavaScript
import { Node } from 'postcss';
|
|
|
|
import { isDocument } from './typeGuards.mjs';
|
|
|
|
/**
|
|
* @param {Node} node
|
|
* @returns {boolean}
|
|
*/
|
|
export default function isInDocument(node) {
|
|
let current = node;
|
|
|
|
while (current) {
|
|
if (isDocument(current)) return true;
|
|
|
|
// Check for unofficial 'document' property from parsers like postcss-html
|
|
if ('document' in current && current.document instanceof Node && isDocument(current.document))
|
|
return true;
|
|
|
|
if (!current.parent) break;
|
|
|
|
current = current.parent;
|
|
}
|
|
|
|
return false;
|
|
}
|