Skip to content
This repository has been archived by the owner on Sep 21, 2019. It is now read-only.

Commit

Permalink
Keep other static class members, such as defaultProps (#36)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Athena Yao authored and mohsen1 committed Mar 29, 2018
1 parent 1e17c1b commit a2338d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export function hasStaticModifier(classMember: ts.ClassElement) {
*/
export function isPropTypesMember(classMember: ts.ClassElement, sourceFile: ts.SourceFile) {
try {
return classMember.name !== undefined && classMember.name.getFullText(sourceFile) !== 'propTypes';
const name =
classMember.name !== undefined && ts.isIdentifier(classMember.name) ? classMember.name.escapedText : null;
return name === 'propTypes';
} catch (e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class SomeComponent extends React.Component<{
foo: number;
}, {
bar: string;
}> {
static propTypes = { foo: React.PropTypes.string };
static defaultProps = { foo: 'bar' };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class SomeComponent extends React.Component<
{
foo: number,
},
{
bar: string,
},
> {
static defaultProps = { foo: 'bar' };
}

0 comments on commit a2338d9

Please sign in to comment.