Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-jsx-remove-qa

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-jsx-remove-qa - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

ref.js

97

index.js

@@ -1,53 +0,64 @@

export default function RemoveQAClasses({ types: t }) {
return {
visitor: {
JSXOpeningElement: function transform(path) {
if (path.node.hasStrippedQAClass) {
return;
}
const classNameRegEx = /\s?qa-([-\w])*/g;
const RemoveQAClasses = ({ types: t }) => {
const visitor = {
JSXOpeningElement: (path, state) => {
if (path.node.hasStrippedQAClass) {
return;
}
const validClassNameAttributes = attr => {
const isIdent = (
t.isJSXIdentifier(attr.name, { name: 'className' })
);
return t.isJSXAttribute(attr) && isIdent;
};
let attributeIdentifiers = 'className';
const classnameAttributes = path.node.attributes.filter(validClassNameAttributes);
if (state.opts && state.opts.attributes) {
attributeIdentifiers = [attributeIdentifiers, ...state.opts.attributes];
}
if (!classnameAttributes.length) {
return;
}
const classNameRegEx = /\s?qa-([-\w])*/g;
let newClassNameValue;
classnameAttributes.forEach(attr => {
if (!t.isStringLiteral(attr.value)) {
return;
const validClassNameAttributes = attr => {
const isIdent = attributeIdentifiers.find(
attribute => {
return t.isJSXIdentifier(attr.name, { name: attribute });
}
);
return t.isJSXAttribute(attr) && isIdent;
};
const removeQAClassNames = currentAttr => {
if (attr !== currentAttr) {
return currentAttr;
}
const newClassNameValue = attr.value.value.replace(classNameRegEx, '').trim();
const isStringLiteral = attr => t.isStringLiteral(attr.value);
return t.jSXAttribute(
t.jSXIdentifier(attr.name.name),
t.stringLiteral(newClassNameValue)
);
};
const replaceClassNameValues = attr => {
const replaceQAClassName = currentAttr => {
if (attr !== currentAttr) {
return currentAttr;
}
newClassNameValue = attr.value.value.replace(classNameRegEx, 'BOB!!!').trim();
const attrs = path.node.attributes.map(removeQAClassNames);
return t.jSXAttribute(
t.jSXIdentifier(attr.name.name),
t.stringLiteral(newClassNameValue)
);
};
const node = t.jSXOpeningElement(
path.node.name,
attrs,
path.node.selfClosing
);
node.hasStrippedQAClass = true;
path.replaceWith(node);
});
}
},
const attrs = path.node.attributes.map(replaceQAClassName);
const node = t.jSXOpeningElement(
path.node.name,
attrs,
path.node.selfClosing
);
node.hasStrippedQAClass = true;
path.replaceWith(node);
};
path.node.attributes
.filter(validClassNameAttributes)
.filter(isStringLiteral)
.forEach(replaceClassNameValues);
}
};
}
return {
visitor
};
};
export default RemoveQAClasses;
{
"name": "babel-plugin-jsx-remove-qa",
"version": "0.1.1",
"version": "0.2.0",
"description": "babel plugin to remove-qa-classes",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc