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

babel-plugin-react-component-data-attribute

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-react-component-data-attribute - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

54

lib/index.js

@@ -44,5 +44,16 @@ 'use strict';

const name = nameForReactComponent(path, state.file);
const overrides = name && getoverrides(name, state.opts.overrides);
let process;
if (overrides != null && overrides.process != null) {
process = overrides.process;
} else {
process = name != null && shouldProcessPotentialComponent(path, name, state);
}
return {
name: name || '',
process: name != null && shouldProcessPotentialComponent(path, name, state)
name: overrides && overrides.name || name || '',
process,
overrides
};

@@ -102,5 +113,2 @@ }

JSXElement(path, { name, source }) {
// We never want to go into a tree of JSX elements, only ever process the top-level item
path.skip();
// Bail early if we are in a different function than the component

@@ -118,2 +126,10 @@ if (path.getFunctionParent() !== source) {

// We never want to go into a tree of JSX elements, only ever process the top-level item
path.skip();
// If we are in a regular prop (not children, bail out)
if (path.parentPath.isJSXExpressionContainer()) {
return;
}
const hasDataAttribute = node.attributes.some(attribute => t.isJSXIdentifier(attribute.name, { name: DATA_ATTRIBUTE }));

@@ -183,3 +199,4 @@ if (hasDataAttribute) {

const name = _evaluatePotentialCom.name,
process = _evaluatePotentialCom.process;
process = _evaluatePotentialCom.process,
overrides = _evaluatePotentialCom.overrides;

@@ -190,4 +207,9 @@ if (!process) {

path.get('body.body').filter(bodyPath => bodyPath.isClassMethod() && bodyPath.get('key').isIdentifier({ name: 'render' })).forEach(renderPath => {
renderPath.traverse(functionVisitor, { name, source: renderPath });
path.get('body.body').filter(bodyPath => {
const key = bodyPath.node.key;
return bodyPath.isClassMethod() && t.isIdentifier(key) && !key.computed && overrides.methods.includes(key.name);
}).forEach(renderPath => {
renderPath.traverse(functionVisitor, { name, source: renderPath, overrides });
});

@@ -199,3 +221,4 @@ },

const name = _evaluatePotentialCom2.name,
process = _evaluatePotentialCom2.process;
process = _evaluatePotentialCom2.process,
overrides = _evaluatePotentialCom2.overrides;

@@ -207,5 +230,5 @@ if (!process) {

if (path.isArrowFunctionExpression() && !path.get('body').isBlockStatement()) {
path.traverse(returnStatementVisitor, { name, source: path });
path.traverse(returnStatementVisitor, { name, source: path, overrides });
} else {
path.traverse(functionVisitor, { name, source: path });
path.traverse(functionVisitor, { name, source: path, overrides });
}

@@ -223,2 +246,11 @@ }

};
}
function getoverrides(component, overrides = {}) {
const overide = overrides.hasOwnProperty(component) ? overrides[component] : {};
return {
name: overide.name || component,
process: overide.process,
methods: overide.methods || ['render']
};
}
{
"name": "babel-plugin-react-component-data-attribute",
"description": "Babel plugin to add a data attribute containing its component’s name to the top-level DOM node",
"version": "0.4.0",
"version": "0.5.0",
"main": "lib/index.js",

@@ -6,0 +6,0 @@ "author": "Chris Sauve <chrismsauve@gmail.com>",

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