// Input
class Foo {
templateString = 'some value';
}
// Output
import __LIB__ from '@scope/lib/path/to/lib';
class Foo {
templateString = (function compiledTemplate(deps) {
// ...
return result;
})({lib: __LIB__});
}
其实我有两个问题:
- 如何从字符串创建 AST 片段?
- 如何添加导入?
PS我尝试了各种方法createSourceFile
,ts.createImportDeclaration
但它们都导致了这个或那个错误:[