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

21 lines (20 loc) 881 B
import { DATA_QA } from "../../pluginConstants.js"; import appendJsxSpreadAttribute from "../../utils/magicString/appendJsxSpreadAttribute/index.js"; import isJsxElement from "../../utils/react/isJsxElement/index.js"; import { isEmpty, last } from "lodash-es"; //#region src/core/injectJsxElement/index.ts function injectJsxElement({ node, code, componentName, childOverrideParent }) { if (!isJsxElement(node)) return false; const openingElement = node.openingElement; if (!openingElement) return false; const attributes = openingElement.attributes; appendJsxSpreadAttribute({ code, startPosition: childOverrideParent && !isEmpty(attributes) ? last(attributes).end : !isEmpty(attributes) ? attributes[0].start : openingElement.name.end, attrs: { [DATA_QA]: componentName }, childOverrideParent }); return true; } //#endregion export { injectJsxElement as default };