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)

31 lines (30 loc) 983 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.astTransformer = void 0; const isNode = (obj) => { return (typeof obj === "object" && typeof obj?.end === "number" && typeof obj?.start === "number" && typeof obj?.type === "string"); }; const astTransformer = (ast, callback) => { if (!ast) { return ast; } for (const key of Object.keys(ast)) { if (["end", "start", "type"].includes(key)) { continue; } if (Array.isArray(ast[key])) { for (const nodeIndex in ast[key]) { ast[key][nodeIndex] = (0, exports.astTransformer)(ast[key][nodeIndex], callback); } } else if (isNode(ast[key])) { ast[key] = (0, exports.astTransformer)(ast[key], callback); } } const result = callback(ast); return typeof result !== "undefined" ? result : ast; }; exports.astTransformer = astTransformer;