Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: