Closed alber70g closed 3 years ago
Nevermind, I've found a solution. I can just run ts.transform(sourceFile, [transformer]);
@alber70g Yep - that works! Another option is to pass nullTransformationContext
, which is exported from the typescript
package.
I think it's an internal type, but you can use ts-expose-internals to access its type
@nonara Thanks. The alternative nullTransformationContext
is nice as well. That way I don't need to use the ts.TransformerFactory
and just return a ts.Transformer
. Thank you!
I'm working on scripts that helps do major refactorings in our applications. It involves also moving files, rewriting imports, rewriting code etc. I've created a transformer, and would like to run this as step within a bigger process.
The thing is, currently we just parse the file and get a
ts.SourceFile
and modify this when needed, and write it back to disk. I'm missing thecontext
parameter that's needed in thets.visitEachChild(node, visitor, context)
.Is it possible to run this program from nodejs? If so, how?