// 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__});
}
實際上在修改NodeArrays,我有兩個問題:插入任意文本和打字稿編譯器API
- 如何創建字符串AST片段?
- 如何添加導入?
P.S. I tried各種方法createSourceFile
和ts.createImportDeclaration
,但他們都帶來這樣或那樣的錯誤:[
您是否嘗試過使用替換節點的適當文本創建標識符?換句話說:''createIdentifier('(function compiledTemplate(deps){/*...*/}')''。 –
這是工作0_o ,但是如何在'@ scope/lib'中添加'import lib;'? – RubaXa