1 | module.exports = babelPluginTransformReactEs6ClassDisplayName;
|
2 |
|
3 | function babelPluginTransformReactEs6ClassDisplayName (babel) {
|
4 | return {
|
5 | visitor: {
|
6 | ClassDeclaration: function (path) {
|
7 | addDisplayName.call(path, babel.types);
|
8 | }
|
9 | }
|
10 | };
|
11 | }
|
12 |
|
13 | function addDisplayName (t) {
|
14 | if (this.node.superClass.property.name === 'Component') {
|
15 | this.insertAfter([
|
16 | t.expressionStatement(t.assignmentExpression(
|
17 | '=',
|
18 | t.memberExpression(this.node.id, t.identifier('displayName')),
|
19 | t.stringLiteral(this.node.id.name)
|
20 | ))
|
21 | ]);
|
22 | }
|
23 | }
|