UNPKG

rollup-plugin-data-qa

Version:

[![npm](https://img.shields.io/npm/dm/rollup-plugin-data-qa.svg)](https://www.npmjs.com/package/rollup-plugin-data-qa) [![semantic-release](https://img.shields.io/badge/semantic-release-e10079.svg?logo=semantic-release)](https://github.com/semantic-releas

70 lines (69 loc) 2.9 kB
const require_index = require("../react/isJsxElement/index.cjs"); const require_index$1 = require("../../core/injectJsxElement/index.cjs"); const require_index$2 = require("../react/isReactFragment/index.cjs"); const require_index$3 = require("../react/isReactNode/index.cjs"); const require_index$4 = require("../../core/injectReactFunctionComponent/index.cjs"); const require_index$5 = require("../../core/injectStyledComponent/index.cjs"); const require_index$6 = require("../formatName/index.cjs"); const require_index$7 = require("../react/findStyledComponentName/index.cjs"); let estree_walker = require("estree-walker"); let lodash_es = require("lodash-es"); //#region src/utils/transformAst/index.ts function transformAst({ ast, code, format, childOverrideParent, disabledReactFunctionComponent, disabledStyledComponent, styledComponentNames }) { const formattedNameCache = /* @__PURE__ */ new Map(); const styledComponentNameSet = new Set(styledComponentNames); const componentStack = []; let styledComponentName = ""; const getFormattedName = (name) => { const cached = formattedNameCache.get(name); if (cached) return cached; const formattedName = require_index$6.default(name, format); formattedNameCache.set(name, formattedName); return formattedName; }; (0, estree_walker.walk)(ast, { enter(node, parent) { if (require_index$2.default(node)) return this.skip(); const isAttrsObjectExpression = !disabledStyledComponent && node.type === "ObjectExpression" && parent?.callee?.property?.name === "attrs"; if (node.type === "ObjectExpression" && !isAttrsObjectExpression) { if (!disabledReactFunctionComponent) return this.skip(); return; } if (require_index$3.default(node) || require_index.default(node)) { if (!disabledReactFunctionComponent && !(0, lodash_es.isEmpty)(componentStack)) { if ((require_index.default(node) ? require_index$1.default : require_index$4.default)({ code, componentName: getFormattedName((0, lodash_es.last)(componentStack)), node, childOverrideParent })) return this.skip(); } if (!disabledStyledComponent) return this.skip(); return; } const nodeName = node.id?.name; if (nodeName && !disabledReactFunctionComponent) componentStack.push(nodeName); if (!disabledStyledComponent) { styledComponentName = require_index$7.default(node) || styledComponentName; if (styledComponentName) { if (require_index$5.default({ code, styledComponentName: getFormattedName(styledComponentName), styledComponentNames: styledComponentNameSet, node, parent, childOverrideParent })) { styledComponentName = ""; return this.skip(); } } } }, leave(node) { if (node.id?.name && !disabledReactFunctionComponent) componentStack.pop(); } }); } //#endregion exports.default = transformAst;