Skip to content
This repository was archived by the owner on Oct 3, 2022. It is now read-only.

Commit a2338d9

Browse files
Athena Yaomohsen1
Athena Yao
authored andcommitted
Keep other static class members, such as defaultProps (lyft#36)
* Add test for defaultProps * Check if the name == "propTypes", not != " propTypes" * More ways of getting the class member name (hacky) * Check if we're an identifier; if we are we can just always use name.escapedText * Use ts.isIdentifier helper function instead of direct comparison on .kind
1 parent 1e17c1b commit a2338d9

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/helpers/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ export function hasStaticModifier(classMember: ts.ClassElement) {
9797
*/
9898
export function isPropTypesMember(classMember: ts.ClassElement, sourceFile: ts.SourceFile) {
9999
try {
100-
return classMember.name !== undefined && classMember.name.getFullText(sourceFile) !== 'propTypes';
100+
const name =
101+
classMember.name !== undefined && ts.isIdentifier(classMember.name) ? classMember.name.escapedText : null;
102+
return name === 'propTypes';
101103
} catch (e) {
102104
return false;
103105
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class SomeComponent extends React.Component<{
2+
foo: number;
3+
}, {
4+
bar: string;
5+
}> {
6+
static propTypes = { foo: React.PropTypes.string };
7+
static defaultProps = { foo: 'bar' };
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class SomeComponent extends React.Component<
2+
{
3+
foo: number,
4+
},
5+
{
6+
bar: string,
7+
},
8+
> {
9+
static defaultProps = { foo: 'bar' };
10+
}

0 commit comments

Comments
 (0)