-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
33 lines (31 loc) · 795 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module.exports = babelPluginTransformReactEs6ClassDisplayName;
function babelPluginTransformReactEs6ClassDisplayName (babel) {
return {
visitor: {
ClassDeclaration: function (path) {
addDisplayName.call(path, babel.types);
}
}
};
}
function addDisplayName (t) {
if (
this.node.superClass &&
(
this.node.superClass.name === 'Component' ||
(
this.node.superClass.object &&
this.node.superClass.object.name === 'React' &&
this.node.superClass.property.name === 'Component'
)
)
) {
this.insertAfter([
t.expressionStatement(t.assignmentExpression(
'=',
t.memberExpression(this.node.id, t.identifier('displayName')),
t.stringLiteral(this.node.id.name)
))
]);
}
}