Skip to content

Commit a4ef270

Browse files
committed
Improve error message for getName edge case
1 parent 7c3f927 commit a4ef270

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/visitors/transpileCssProp.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
// @see https://github.com/satya164/babel-plugin-css-prop
33
import { useCssProp } from '../utils/options'
44

5-
const getTag = (node, t) => {
5+
const getName = (node, t) => {
66
if (typeof node.name === 'string') return node.name
77
if (t.isJSXMemberExpression(node)) {
8-
return `${getTag(node.object, t)}.${node.property.name}`
8+
return `${getName(node.object, t)}.${node.property.name}`
99
}
10-
throw path.buildCodeFrameError('Failed to get the name')
10+
throw path.buildCodeFrameError(
11+
`Cannot infer name from node with type "${
12+
node.type
13+
}". Please submit an issue at github.com/styled-components/babel-plugin-styled-components with your code so we can take a look at your use case!`
14+
)
1115
}
1216

1317
export default t => (path, state) => {
@@ -29,7 +33,7 @@ export default t => (path, state) => {
2933
}
3034

3135
const elem = path.parentPath
32-
const name = getTag(elem.node.name, t)
36+
const name = getName(elem.node.name, t)
3337
const id = path.scope.generateUidIdentifier(
3438
'Styled' + name.replace(/^([a-z])/, (match, p1) => p1.toUpperCase())
3539
)

0 commit comments

Comments
 (0)