Skip to content

Commit 5ebe744

Browse files
committed
fix(arrow-function): Check if there's a parent before catching the name
1 parent c4778fe commit 5ebe744

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "babel-plugin-transform-react-qa-classes",
3-
"version": "semantic-release",
3+
"version": "0.0.6",
44
"description": "Add component's name in `data-qa` attributes to React Components Edit",
55
"repository": "https://github.com/davesnx/babel-plugin-transform-react-qa-classes",
66
"author": "davesnx <dsnxmoreno@gmail.com>",

src/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ export default function ({types: t}) {
55
visitor: {
66
ArrowFunctionExpression (path, state) {
77
const options = checkValidOptions(state)
8+
if (!path.parent) return
89
const componentName = path.parent.id.name
910

1011
const functionBody = path.get('body').get('body')
11-
const returnStatement = functionBody.find((c) => {
12-
return c.type === 'ReturnStatement'
13-
})
14-
12+
const returnStatement = functionBody.find((c) => c.type === 'ReturnStatement')
1513
const arg = returnStatement.get('argument')
1614
if (!arg.isJSXElement()) return
1715

@@ -49,7 +47,7 @@ export default function ({types: t}) {
4947
openingElement.node.attributes.push(
5048
t.jSXAttribute(
5149
t.jSXIdentifier(options.attribute),
52-
t.stringLiteral(options.format(name.node.name))
50+
t.stringLiteral(options.format(name.node && name.node.name))
5351
)
5452
)
5553
}

0 commit comments

Comments
 (0)