UNPKG

rollup-plugin-react-scoped-css

Version:

A rollup plugin designed to allow scoped css to be run in react (Compatible with vite and rollup)

34 lines (33 loc) 990 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.astIterator = void 0; const isNode = (key, value) => { if (key === "loc") return false; return (typeof value === "object" && typeof value?.end === "number" && typeof value?.start === "number" && typeof value?.type === "string"); }; const astIterator = function* (ast) { if (!ast) { return; } for (const key of Object.keys(ast)) { // Skip useless keys if (["end", "start", "type"].includes(key)) { continue; } // If key value is an array, iterate over it if (Array.isArray(ast[key])) { for (const nodeIndex in ast[key]) { yield* (0, exports.astIterator)(ast[key][nodeIndex]); } } else if (isNode(key, ast[key])) { yield* (0, exports.astIterator)(ast[key]); } } yield ast; }; exports.astIterator = astIterator;