-
Notifications
You must be signed in to change notification settings - Fork 68
Keep other static class members, such as defaultProps #36
Conversation
Thanks for this work. I'll help you to get this merged. To answer your question, yes. I've seen Also copying @vincentbel to review as he helped a lot with this project as well. |
This is correct. You can use the function What you actually do when faced with a synthetic node is really dependent on the application. Reading the |
|
Signed CLA! |
src/helpers/index.ts
Outdated
@@ -97,7 +97,11 @@ 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 && classMember.name.kind === ts.SyntaxKind.Identifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use ts.IsIdentifier(classMember.name)
Thanks for the tip. Updated! |
I've been trying this out against our codebase, and I found that it was stripping out all static class members, not just propTypes.
Tracked down the issue to
isPropTypesMember
wheregetFullText
returns a string surrounded by whitespace; so I've fixed that in 95f6b0e.That makes it so that we check if
propTypes
===propTypes
, instead of if thepropTypes
!==propTypes
. And that makes it strip out propTypes, but keep all other static class members which is what I think we want!Now here's the hacky part:
that caused
end-to-end initial-state-and-proprypes
andend-to-end initial-state-and-proprypes-and-set-state
to fail becausegetFullText
returns empty in those cases (Going into the very nitty-gritty, theIdentifierType
in these cases haspos: -1, end: -1
).I'm using
escapedText
here as a fallback but this feels like a gigantic hack; have you run into this before, and do you know what might be the best way to fix it?