babel-plugin-transform-react-remove-display-name
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -38,9 +38,19 @@ "use strict"; | ||
function isExistsReactComponent(node, reactComponentsSet) { | ||
if (t.isMemberExpression(node) && | ||
return (t.isMemberExpression(node) && | ||
t.isIdentifier(node.object) && | ||
reactComponentsSet.has(node.object.name)) { | ||
return true; | ||
} | ||
return false; | ||
reactComponentsSet.has(node.object.name)); | ||
} | ||
function isValidHoc(node, reactComponentsSet) { | ||
return (t.isIdentifier(node.callee) && | ||
node.callee.name.startsWith('with') && | ||
node.arguments.some((arg) => { | ||
if (t.isIdentifier(arg) && reactComponentsSet.has(arg.name)) { | ||
return true; | ||
} | ||
else if (t.isCallExpression(arg)) { | ||
return isValidHoc(arg, reactComponentsSet); | ||
} | ||
return false; | ||
})); | ||
} | ||
function displayNameTransform({ template }) { | ||
@@ -80,2 +90,12 @@ const wrapWithEnvCheck = template(` | ||
}, | ||
VariableDeclarator(path, state) { | ||
const reactComponentsSet = state.get(stateProp); | ||
if (!t.isIdentifier(path.node.id) || | ||
path.node.id.name.charAt(0) !== path.node.id.name.charAt(0).toUpperCase() || | ||
!t.isCallExpression(path.node.init) || | ||
!isValidHoc(path.node.init, reactComponentsSet)) { | ||
return; | ||
} | ||
reactComponentsSet.add(path.node.id.name); | ||
}, | ||
AssignmentExpression(path, state) { | ||
@@ -82,0 +102,0 @@ const { node } = path; |
{ | ||
"name": "babel-plugin-transform-react-remove-display-name", | ||
"description": "Make React component `displayName` property available only in none production environment during the build", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "author": "felixmosh", |
12533
198