typescript - 使用 Typescript Compiler API 重写 typescript 文件

标签 typescript typescript2.0

我正在尝试使用 Typescript Compiler API 来创建一个用于合并 TypeScript 文件的工具。我想知道有没有办法:

  1. 通过解析 .ts 文件生成 AST 后更改它。
  2. 序列化将 AST 改回 .ts 文件

我已阅读 documentation在编译器 API 上,但它似乎只涵盖了使用 AST 的只读用例,而我对修改源文件更感兴趣。

提前感谢您的帮助。

最佳答案

Change AST after it was produced by parsing .ts file. Serialize changed AST back to .ts file

这两个都是发射器插件,你需要添加一个自定义的transformer。最好的文档仍在 PR 中 https://github.com/Microsoft/TypeScript/pull/13940 🌹

关于typescript - 使用 Typescript Compiler API 重写 typescript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43829884/

相关文章:

javascript - Grunt 从 typescript 源生成空文件

typescript - tsc - 忽略命令行错误

jquery - 类方法中的 Typescript "this"

typescript - 从模块声明文件中的命名空间合并接口(interface)

javascript - 错误 TS2345 : Argument of type '(a: Test, b: Test) => boolean | 1' is not assignable to parameter of type '(a: Test, b: Test) => number'

javascript - typescript :_this2.onClick 不是函数

javascript - typescript 不强制类型

typescript - 从包类型扩展命名空间

javascript - Angular 6 : subscribe component to a service event

typescript - visual studio code - html 字符串的语法突出显示?