Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper methods for getting corresponding accessor and support for static accessors #1

Closed
dsherret opened this issue Oct 18, 2019 · 1 comment · Fixed by #4
Closed

Comments

@dsherret
Copy link
Contributor

dsherret commented Oct 18, 2019

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:

  1. 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.
  2. 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.
  3. 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.

@dsherret dsherret changed the title Improvements? Helper methods for getting corresponding accessor and support for static accessors Oct 18, 2019
@dsherret
Copy link
Contributor Author

Oh, by the way, I think change:

s.getType().getText()

To:

s.getTypeNode().getText()

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant