rollup-plugin-data-qa
Version:
[](https://www.npmjs.com/package/rollup-plugin-data-qa) [](https://github.com/semantic-releas
21 lines (20 loc) • 881 B
JavaScript
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 };