babel-plugin-react-component-data-attribute
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -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>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10477
198