ts-simple-ast
TypeScript Compiler API wrapper. Provides a simple way to navigate and manipulate TypeScript and JavaScript code.
NOTICE - LIBRARY RENAMED!
ts-simple-ast has been renamed to ts-morph.
Library Development - Progress Update (06 January 2019)
View information on breaking changes in breaking-changes.md.
This library is still under early active development. Most common code manipulation/generation use cases are implemented, but there's still a lot of work to do.
Please open an issue if you find a feature missing or bug that isn't in the issue tracker.
Report
View a generated report on what nodes have been wrapped in the wrapped-nodes.md file.
Documentation
Work in progress: https://dsherret.github.io/ts-simple-ast/
Getting Started
Example
; // initialize; // add source filesproject.addExistingSourceFiles"src/**/*.ts";;; // get information from ast;myClass.getName; // returns: "MyClass"myClass.hasExportKeyword; // returns: truemyClass.isDefaultExport; // returns: false // manipulate ast; myClass.rename"NewName";myClass.addImplementsmyInterface.getName;myClass.addProperty; project.getSourceFileOrThrow"src/ExistingFile.ts".delete; // asynchronously save all the changes aboveproject.save; // get underlying compiler node from the typescript AST from any node;
Or navigate existing compiler nodes created with the TypeScript compiler (the ts
named export is the TypeScript compiler):
; // some code that creates a class declaration using the ts object; // create and use a wrapped node;; // ... do more stuff here ...