Skip to content

Commit 3602f67

Browse files
committed
Fix displayName detection for class expressions (fixes #419)
1 parent 7105a01 commit 3602f67

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/rules/display-name.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ module.exports = Components.detect(function(context, components, utils) {
9090
node.parent.parent.type === 'VariableDeclarator'
9191
);
9292
var namedClass = (
93-
node.type === 'ClassDeclaration' &&
94-
node.id && node.id.name
93+
(node.type === 'ClassDeclaration' || node.type === 'ClassExpression') &&
94+
node.id &&
95+
node.id.name
9596
);
9697

9798
var namedFunctionDeclaration = (
@@ -168,6 +169,13 @@ module.exports = Components.detect(function(context, components, utils) {
168169
markDisplayNameAsDeclared(node);
169170
},
170171

172+
ClassExpression: function(node) {
173+
if (ignoreTranspilerName || !hasTranspilerName(node)) {
174+
return;
175+
}
176+
markDisplayNameAsDeclared(node);
177+
},
178+
171179
ClassDeclaration: function(node) {
172180
if (ignoreTranspilerName || !hasTranspilerName(node)) {
173181
return;

tests/lib/rules/display-name.js

+11
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,17 @@ ruleTester.run('display-name', rule, {
337337
ignoreTranspilerName: true
338338
}],
339339
parser: 'babel-eslint'
340+
}, {
341+
code: [
342+
'import React, {Component} from "react";',
343+
'function someDecorator(ComposedComponent) {',
344+
' return class MyDecorator extends Component {',
345+
' render() {return <ComposedComponent {...this.props} />;}',
346+
' };',
347+
'}',
348+
'module.exports = someDecorator;'
349+
].join('\n'),
350+
parser: 'babel-eslint'
340351
}
341352
],
342353

0 commit comments

Comments
 (0)