Skip to content

Commit 53730d9

Browse files
author
Keyan Zhang
committed
displayName shouldn't show up twice
1 parent f06bcd6 commit 53730d9

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

transforms/__testfixtures__/class.input.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,10 @@ var MyComponent5 = React.createClass({
152152
);
153153
},
154154
});
155+
156+
var GoodName = React.createClass({
157+
displayName: 'GoodName',
158+
render() {
159+
return <div/>;
160+
},
161+
});

transforms/__testfixtures__/class.output.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,11 @@ class MyComponent5 extends React.Component {
146146
);
147147
}
148148
}
149+
150+
class GoodName extends React.Component {
151+
static displayName = 'GoodName';
152+
153+
render() {
154+
return <div/>;
155+
}
156+
}

transforms/class.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,11 @@ module.exports = (file, api, options) => {
344344
return result;
345345
};
346346

347-
const collectProperties = specPath => specPath.properties
347+
const collectNonStaticProperties = specPath => specPath.properties
348348
.filter(prop =>
349349
!(filterDefaultPropsField(prop) || filterGetInitialStateField(prop))
350350
)
351+
.filter(prop => (!STATIC_KEYS[prop.key.name]) && prop.key.name !== STATIC_KEY)
351352
.filter(prop =>
352353
isFunctionExpression(prop) ||
353354
isPrimPropertyWithTypeAnnotation(prop) ||
@@ -782,13 +783,6 @@ module.exports = (file, api, options) => {
782783
// 1. there's a `this.context` access, or
783784
// 2. there's a direct method call `this.x()`, or
784785
// 3. `this` is referenced alone
785-
//
786-
// It creates a class with the following order of properties/methods:
787-
// 1. static properties
788-
// 2. constructor (if necessary)
789-
// 3. new properties (`state = {...};`)
790-
// 4. arrow functions
791-
// 5. other methods
792786
const createESClass = (
793787
name,
794788
baseClassName,
@@ -908,7 +902,7 @@ module.exports = (file, api, options) => {
908902
const specPath = ReactUtils.getReactCreateClassSpec(classPath);
909903
const name = ReactUtils.getComponentName(classPath);
910904
const statics = collectStatics(specPath);
911-
const properties = collectProperties(specPath);
905+
const properties = collectNonStaticProperties(specPath);
912906
const comments = getComments(classPath);
913907

914908
const getInitialState = findGetInitialState(specPath);

0 commit comments

Comments
 (0)