Skip to content

Commit

Permalink
Fix displayName detection for class expressions (fixes #419)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Feb 22, 2016
1 parent 7105a01 commit 3602f67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ module.exports = Components.detect(function(context, components, utils) {
node.parent.parent.type === 'VariableDeclarator'
);
var namedClass = (
node.type === 'ClassDeclaration' &&
node.id && node.id.name
(node.type === 'ClassDeclaration' || node.type === 'ClassExpression') &&
node.id &&
node.id.name
);

var namedFunctionDeclaration = (
Expand Down Expand Up @@ -168,6 +169,13 @@ module.exports = Components.detect(function(context, components, utils) {
markDisplayNameAsDeclared(node);
},

ClassExpression: function(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
}
markDisplayNameAsDeclared(node);
},

ClassDeclaration: function(node) {
if (ignoreTranspilerName || !hasTranspilerName(node)) {
return;
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,17 @@ ruleTester.run('display-name', rule, {
ignoreTranspilerName: true
}],
parser: 'babel-eslint'
}, {
code: [
'import React, {Component} from "react";',
'function someDecorator(ComposedComponent) {',
' return class MyDecorator extends Component {',
' render() {return <ComposedComponent {...this.props} />;}',
' };',
'}',
'module.exports = someDecorator;'
].join('\n'),
parser: 'babel-eslint'
}
],

Expand Down

0 comments on commit 3602f67

Please sign in to comment.