4 ms·
I've worked a lot with ASTs in the past, and am now working with TypeScript quite a bit. I actually find their AST implementation very nice, and pretty easy to
by Nitramp 8y ago
I've worked a lot with ASTs in the past, and am now working with TypeScript quite a bit. I actually find their AST implementation very nice, and pretty easy to get started on:
import * as ts from 'typescript'
const sourceFile = ts.createSourceFile('myclass.ts', `class MyClass { ... }`, ScriptTarget.Latest);
ts.forEachChild(sourceFile, (node) => {
switch (node.kind) {
...
}
});
It doesn't get much easier than that in my book. The AST is also fully typed and TS comes with a lot of helper methods, including the transformers package to hook into TS' output pipeline. It's pretty neat.