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
I'd like to access the CompilerHost instance from my custom transformers (via TransformationContext).
As far as I can see this wouldn't expose any "risky" patterns like #25147.
Use Cases
My specific use-case is resolving import declarations. This can be done using ts.resolveModuleName (#28276 (comment)), but this requires a CompilerHost instance.
Example
An example for my specific use-case would be:
consttransformer: ts.TransformerFactory<ts.SourceFile>=context=>{returnfile=>{returnts.visitEachChild(file,node=>{if(ts.isImportDeclaration(node)){constresolved=ts.resolveModuleName((node.moduleSpecifierasts.StringLiteral).text,file.fileName,context.getCompilerOptions(),context.getCompilerHost()// this is currently impossible)// do something interesting with resolved}returnnode;},context)}}
Search Terms
compiler host, CompilerHost,
transformation context, TransformationContext,
transformer, custom transformer
Suggestion
I'd like to access the
CompilerHost
instance from my custom transformers (viaTransformationContext
).As far as I can see this wouldn't expose any "risky" patterns like #25147.
Use Cases
My specific use-case is resolving import declarations. This can be done using
ts.resolveModuleName
(#28276 (comment)), but this requires aCompilerHost
instance.Example
An example for my specific use-case would be:
Workaround
Luckily there is a workaround for this:
But this feels redundant and somewhat "wrong".
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: