You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the tweet and this is an excellent use case for the library!
I noticed a few things that might improve this:
Check out the GetAccessorDeclaration#getSetAccessor() helper method. This will help you get the set accessor for a get accessor. A similar method exists on SetAccessorDeclaration. I actually went to look at these methods just a little while ago though and there were a few bugs in them (one of the first methods I wrote in the library). Upgrade to ts-morph 4.3.1 and those issues are fixed (it didn't work outside class declarations and didn't check if isStatic() was equal for both of the nodes). I just did a release right now.
I think you will probably want to take into account the static modifier as well, but I'm not sure how those end up in declaration files.
f.copy(...) will return the copied source file, so you could copy first then modify that source file. That will save an additional trip to the file system.
TODO: Just thought of this, but replaceWithText will also replace the js docs so we need to also include those here.
Also, perhaps I should add a toProperty() method in ts-morph that would change get and set accessors to either property declarations or property assignments depending on the parent.
The text was updated successfully, but these errors were encountered:
dsherret
changed the title
Improvements?
Helper methods for getting corresponding accessor and support for static accessors
Oct 18, 2019
I know that's a little confusing coming from the compiler API where nodes and types are completely separate, but #getType() gets the type from the type checker.
Hey Nathan,
Thanks for the tweet and this is an excellent use case for the library!
I noticed a few things that might improve this:
GetAccessorDeclaration#getSetAccessor()
helper method. This will help you get the set accessor for a get accessor. A similar method exists onSetAccessorDeclaration
. I actually went to look at these methods just a little while ago though and there were a few bugs in them (one of the first methods I wrote in the library). Upgrade to ts-morph 4.3.1 and those issues are fixed (it didn't work outside class declarations and didn't check ifisStatic()
was equal for both of the nodes). I just did a release right now.f.copy(...)
will return the copied source file, so you could copy first then modify that source file. That will save an additional trip to the file system.TODO: Just thought of this, but
replaceWithText
will also replace the js docs so we need to also include those here.Also, perhaps I should add a
toProperty()
method in ts-morph that would change get and set accessors to either property declarations or property assignments depending on the parent.The text was updated successfully, but these errors were encountered: