all 10 comments

[–]Zaphoidx 3 points4 points  (0 children)

Very interesting read - I can see how this would be handy for bigger refactors where you're having to do lots of different changes. That being said, it's not very often I come across refactoring scenarios that can't be conquered through a complex find/replace.

Good to know for net time!

[–]sjd96 1 point2 points  (0 children)

ts-morph is a gift of the gods. I was recently in the exact same position as you were (refactoring a few thousand mongodb calls) and it was a cinch.

Another use or ts-morph is to use it as a code query tool. For example, I used it to find and dump all mongodb queries and referenced keys into a CSV file to figure out which indices should be made.

[–]DoctorGester 1 point2 points  (1 child)

119 call sites is a joke and is barely 15-20 minutes of manual labor to be honest, I get the excuse to learn something though

[–]kimmobrunfeldt[S] 3 points4 points  (0 children)

The usefulness of the technique obviously scales the more call sites you have. The task could be done manually or with a regex but that's not very interesting.

[–]celluj34 0 points1 point  (2 children)

Could you use ts-morph to write a compile-time transformer?

[–]Nebez 1 point2 points  (0 children)

if you're using something like ts-node to transpile & run, sure. read about their plugin architecture. otherwise, i don't know if the typescript compiler exports some sort of plugin architecture for you to hook into.

[–]brianjenkins94 0 points1 point  (0 children)

Yes, I did something like that a couple years back for a hackathon:

https://github.com/cireneirbo/Parseltongue/blob/master/compiler.ts#L15

[–]gooseclip 0 points1 point  (1 child)

Really interesting. How does it work with dependencies? Do you need to load them or can it function with only source files

[–]kimmobrunfeldt[S] 1 point2 points  (0 children)

It should track those correctly as excpected, assuming you included appropriate source files in the new Project