如何编写 Typescript 插件?

Jam*_*wuh 12 javascript plugins abstract-syntax-tree transpiler typescript

是否有编写 Typescript 插件的文档/示例?


将 Typescript 引入我的项目的想法让我最后一次受到了极大的启发。不过,目前我看到的,这是因为我的不能失败尝试找到写一个打字稿插件的任何文档。我需要这个插件来在编译期间组合类元数据,然后生成资产。这并不容易,但我已经为babel编写了这样的代码,现在我很感兴趣是否可以用 Typescript 做同样的事情。

Mis*_*saz 9

您可以下载https://github.com/microsoft/typescript或通过 npm。

npm install typescript
Run Code Online (Sandbox Code Playgroud)

然后将其包含到您的项目中,并通过Compiler APITypeScript Language Service使用 TypeScripts 代码。如果需要,您可以编写自己的编译器。维基上描述了基础知识。

https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API

https://github.com/Microsoft/TypeScript/wiki/Using-the-Language-Service-API


rob*_*obd 7

现在有一些可用于语言服务插件的文档:

https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin

但请注意,语言服务不是由tsc命令调用的,而是仅从应用程序(我认为通常是 IDE/编辑器)调用。

https://github.com/cevek/ttypescript项目补丁支持 Transformer,这对于需要命令支持的人来说可能是一个途径tsctsc