diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 1018c5d..04a2c29 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -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; } diff --git a/test/react-remove-static-prop-types-member-transform/other-static-members/input.tsx b/test/react-remove-static-prop-types-member-transform/other-static-members/input.tsx new file mode 100644 index 0000000..ed98022 --- /dev/null +++ b/test/react-remove-static-prop-types-member-transform/other-static-members/input.tsx @@ -0,0 +1,8 @@ +class SomeComponent extends React.Component<{ + foo: number; +}, { + bar: string; +}> { + static propTypes = { foo: React.PropTypes.string }; + static defaultProps = { foo: 'bar' }; +} diff --git a/test/react-remove-static-prop-types-member-transform/other-static-members/output.tsx b/test/react-remove-static-prop-types-member-transform/other-static-members/output.tsx new file mode 100644 index 0000000..c37607e --- /dev/null +++ b/test/react-remove-static-prop-types-member-transform/other-static-members/output.tsx @@ -0,0 +1,10 @@ +class SomeComponent extends React.Component< + { + foo: number, + }, + { + bar: string, + }, +> { + static defaultProps = { foo: 'bar' }; +}