ts-simple-ast

TypeScript compiler wrapper for static analysis and code manipulation.

NOTICE: ts-simple-ast has been renamed to ts-morph and version reset to 1.0.0. Switch at your leisure...
Last updated 8 months ago by dsherret .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ts-simple-ast 
SYNC missed versions from official npm registry.

ts-simple-ast

npm version Build Status Coverage Status stable

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

  1. Installing
  2. Instantiating
  3. Adding source files
  4. Getting source files
  5. Navigating
  6. Manipulating

Example

import { Project } from "ts-simple-ast";

// initialize
const project = new Project({
    // Optionally specify compiler options, tsconfig.json, virtual file system, and more here.
    // If you initialize with a tsconfig.json, then it will automatically populate the project
    // with the associated source files.
    // Read more: https://dsherret.github.io/ts-simple-ast/setup/
});

// add source files
project.addExistingSourceFiles("src/**/*.ts");
const myClassFile = project.createSourceFile("src/MyClass.ts", "export class MyClass {}");
const myEnumFile = project.createSourceFile("src/MyEnum.ts", {
    enums: [{
        name: "MyEnum",
        isExported: true,
        members: [{ name: "member" }]
    }]
});

// get information from ast
const myClass = myClassFile.getClassOrThrow("MyClass");
myClass.getName();          // returns: "MyClass"
myClass.hasExportKeyword(); // returns: true
myClass.isDefaultExport();  // returns: false

// manipulate ast
const myInterface = myClassFile.addInterface({
    name: "IMyInterface",
    isExported: true,
    properties: [{
        name: "myProp",
        type: "number"
    }]
});

myClass.rename("NewName");
myClass.addImplements(myInterface.getName());
myClass.addProperty({
    name: "myProp",
    initializer: "5"
});

project.getSourceFileOrThrow("src/ExistingFile.ts").delete();

// asynchronously save all the changes above
project.save();

// get underlying compiler node from the typescript AST from any node
const compilerNode = myClassFile.compilerNode;

Or navigate existing compiler nodes created with the TypeScript compiler (the ts named export is the TypeScript compiler):

import { createWrappedNode, ClassDeclaration, ts } from "ts-simple-ast";

// some code that creates a class declaration using the ts object
const classNode: ts.ClassDeclaration = ...;

// create and use a wrapped node
const classDec = createWrappedNode(classNode) as ClassDeclaration;
const firstProperty = classDec.getProperties()[0];

// ... do more stuff here ...

Resources

Current Tags

  • 21.0.4                                ...           latest (8 months ago)

246 Versions

  • 21.0.4 [deprecated]           ...           8 months ago
  • 21.0.3 [deprecated]           ...           8 months ago
  • 21.0.2 [deprecated]           ...           9 months ago
  • 21.0.1 [deprecated]           ...           9 months ago
  • 21.0.0 [deprecated]           ...           9 months ago
  • 20.0.0 [deprecated]           ...           10 months ago
  • 19.1.0 [deprecated]           ...           10 months ago
  • 19.0.0 [deprecated]           ...           a year ago
  • 18.1.0 [deprecated]           ...           a year ago
  • 18.0.1 [deprecated]           ...           a year ago
  • 18.0.0 [deprecated]           ...           a year ago
  • 17.1.1 [deprecated]           ...           a year ago
  • 17.1.0 [deprecated]           ...           a year ago
  • 17.0.1 [deprecated]           ...           a year ago
  • 17.0.0 [deprecated]           ...           a year ago
  • 16.0.4 [deprecated]           ...           a year ago
  • 16.0.3 [deprecated]           ...           a year ago
  • 16.0.2 [deprecated]           ...           a year ago
  • 16.0.1 [deprecated]           ...           a year ago
  • 16.0.0 [deprecated]           ...           a year ago
  • 15.1.0 [deprecated]           ...           a year ago
  • 15.0.2 [deprecated]           ...           a year ago
  • 15.0.1 [deprecated]           ...           a year ago
  • 15.0.0 [deprecated]           ...           a year ago
  • 14.4.5 [deprecated]           ...           a year ago
  • 14.4.4 [deprecated]           ...           a year ago
  • 14.4.3 [deprecated]           ...           a year ago
  • 14.4.2 [deprecated]           ...           a year ago
  • 14.4.1 [deprecated]           ...           a year ago
  • 14.4.0 [deprecated]           ...           a year ago
  • 14.3.0 [deprecated]           ...           a year ago
  • 14.2.1 [deprecated]           ...           a year ago
  • 14.2.0 [deprecated]           ...           a year ago
  • 14.1.1 [deprecated]           ...           a year ago
  • 14.1.0 [deprecated]           ...           a year ago
  • 14.0.1 [deprecated]           ...           a year ago
  • 14.0.0 [deprecated]           ...           a year ago
  • 13.0.0 [deprecated]           ...           a year ago
  • 12.7.2 [deprecated]           ...           a year ago
  • 12.7.1 [deprecated]           ...           a year ago
  • 12.7.0 [deprecated]           ...           a year ago
  • 12.6.2 [deprecated]           ...           a year ago
  • 12.6.1 [deprecated]           ...           a year ago
  • 12.6.0 [deprecated]           ...           a year ago
  • 12.5.4 [deprecated]           ...           a year ago
  • 12.5.3 [deprecated]           ...           a year ago
  • 12.5.2 [deprecated]           ...           a year ago
  • 12.5.1 [deprecated]           ...           a year ago
  • 12.5.0 [deprecated]           ...           a year ago
  • 12.4.1 [deprecated]           ...           a year ago
  • 12.4.0 [deprecated]           ...           a year ago
  • 12.3.0 [deprecated]           ...           a year ago
  • 12.2.0 [deprecated]           ...           a year ago
  • 12.1.0 [deprecated]           ...           a year ago
  • 12.0.0 [deprecated]           ...           a year ago
  • 11.3.0 [deprecated]           ...           a year ago
  • 11.2.2 [deprecated]           ...           a year ago
  • 11.2.1 [deprecated]           ...           a year ago
  • 11.2.0 [deprecated]           ...           a year ago
  • 11.1.1 [deprecated]           ...           a year ago
  • 11.1.0 [deprecated]           ...           a year ago
  • 11.0.0 [deprecated]           ...           a year ago
  • 10.5.0 [deprecated]           ...           a year ago
  • 10.4.0 [deprecated]           ...           a year ago
  • 10.3.3 [deprecated]           ...           a year ago
  • 10.3.2 [deprecated]           ...           a year ago
  • 10.3.1 [deprecated]           ...           a year ago
  • 10.3.0 [deprecated]           ...           2 years ago
  • 10.2.0 [deprecated]           ...           2 years ago
  • 10.1.0 [deprecated]           ...           2 years ago
  • 10.0.1 [deprecated]           ...           2 years ago
  • 9.5.0 [deprecated]           ...           2 years ago
  • 9.4.2 [deprecated]           ...           2 years ago
  • 9.4.1 [deprecated]           ...           2 years ago
  • 9.4.0 [deprecated]           ...           2 years ago
  • 9.3.0 [deprecated]           ...           2 years ago
  • 9.2.0 [deprecated]           ...           2 years ago
  • 9.1.0 [deprecated]           ...           2 years ago
  • 9.0.1 [deprecated]           ...           2 years ago
  • 9.0.0 [deprecated]           ...           2 years ago
  • 8.2.4 [deprecated]           ...           2 years ago
  • 8.2.3 [deprecated]           ...           2 years ago
  • 8.2.2 [deprecated]           ...           2 years ago
  • 8.2.1 [deprecated]           ...           2 years ago
  • 8.2.0 [deprecated]           ...           2 years ago
  • 8.1.0 [deprecated]           ...           2 years ago
  • 8.0.0 [deprecated]           ...           2 years ago
  • 7.1.0 [deprecated]           ...           2 years ago
  • 7.0.1 [deprecated]           ...           2 years ago
  • 7.0.0 [deprecated]           ...           2 years ago
  • 6.12.0 [deprecated]           ...           2 years ago
  • 6.11.1 [deprecated]           ...           2 years ago
  • 6.10.0 [deprecated]           ...           2 years ago
  • 6.9.0 [deprecated]           ...           2 years ago
  • 6.8.0 [deprecated]           ...           2 years ago
  • 6.7.0 [deprecated]           ...           2 years ago
  • 6.6.0 [deprecated]           ...           2 years ago
  • 6.5.0 [deprecated]           ...           2 years ago
  • 6.4.0 [deprecated]           ...           2 years ago
  • 6.3.0 [deprecated]           ...           2 years ago
  • 6.2.0 [deprecated]           ...           2 years ago
  • 6.1.0 [deprecated]           ...           2 years ago
  • 6.0.1 [deprecated]           ...           2 years ago
  • 6.0.0 [deprecated]           ...           2 years ago
  • 5.6.0 [deprecated]           ...           2 years ago
  • 5.5.1 [deprecated]           ...           2 years ago
  • 5.5.0 [deprecated]           ...           2 years ago
  • 5.4.0 [deprecated]           ...           2 years ago
  • 5.3.2 [deprecated]           ...           2 years ago
  • 5.3.1 [deprecated]           ...           2 years ago
  • 5.3.0 [deprecated]           ...           2 years ago
  • 5.2.0 [deprecated]           ...           2 years ago
  • 5.1.0 [deprecated]           ...           2 years ago
  • 5.0.0 [deprecated]           ...           2 years ago
  • 4.2.1 [deprecated]           ...           2 years ago
  • 4.2.0 [deprecated]           ...           2 years ago
  • 4.1.0 [deprecated]           ...           2 years ago
  • 4.0.1 [deprecated]           ...           2 years ago
  • 4.0.0 [deprecated]           ...           2 years ago
  • 3.2.0 [deprecated]           ...           2 years ago
  • 3.1.0 [deprecated]           ...           2 years ago
  • 3.0.2 [deprecated]           ...           2 years ago
  • 3.0.1 [deprecated]           ...           2 years ago
  • 3.0.0 [deprecated]           ...           2 years ago
  • 2.0.0 [deprecated]           ...           2 years ago
  • 1.3.0 [deprecated]           ...           2 years ago
  • 1.2.0 [deprecated]           ...           2 years ago
  • 1.1.0 [deprecated]           ...           2 years ago
  • 1.0.1 [deprecated]           ...           2 years ago
  • 0.99.0 [deprecated]           ...           2 years ago
  • 0.98.0 [deprecated]           ...           2 years ago
  • 0.97.1 [deprecated]           ...           2 years ago
  • 0.97.0 [deprecated]           ...           2 years ago
  • 0.96.0 [deprecated]           ...           2 years ago
  • 0.95.0 [deprecated]           ...           2 years ago
  • 0.94.0 [deprecated]           ...           2 years ago
  • 0.93.0 [deprecated]           ...           2 years ago
  • 0.92.0 [deprecated]           ...           2 years ago
  • 0.91.0 [deprecated]           ...           2 years ago
  • 0.90.0 [deprecated]           ...           2 years ago
  • 0.89.0 [deprecated]           ...           2 years ago
  • 0.88.0 [deprecated]           ...           2 years ago
  • 0.87.0 [deprecated]           ...           2 years ago
  • 0.86.0 [deprecated]           ...           2 years ago
  • 0.85.0 [deprecated]           ...           2 years ago
  • 0.84.0 [deprecated]           ...           2 years ago
  • 0.83.0 [deprecated]           ...           2 years ago
  • 0.82.0 [deprecated]           ...           2 years ago
  • 0.81.1 [deprecated]           ...           2 years ago
  • 0.81.0 [deprecated]           ...           2 years ago
  • 0.80.0 [deprecated]           ...           2 years ago
  • 0.79.0 [deprecated]           ...           2 years ago
  • 0.78.1 [deprecated]           ...           2 years ago
  • 0.78.0 [deprecated]           ...           2 years ago
  • 0.77.0 [deprecated]           ...           2 years ago
  • 0.76.0 [deprecated]           ...           2 years ago
  • 0.75.0 [deprecated]           ...           2 years ago
  • 0.74.0 [deprecated]           ...           2 years ago
  • 0.73.0 [deprecated]           ...           2 years ago
  • 0.72.2 [deprecated]           ...           2 years ago
  • 0.72.1 [deprecated]           ...           2 years ago
  • 0.72.0 [deprecated]           ...           2 years ago
  • 0.71.1 [deprecated]           ...           2 years ago
  • 0.71.0 [deprecated]           ...           2 years ago
  • 0.70.1 [deprecated]           ...           2 years ago
  • 0.70.0 [deprecated]           ...           2 years ago
  • 0.69.0 [deprecated]           ...           2 years ago
  • 0.68.0 [deprecated]           ...           2 years ago
  • 0.67.0 [deprecated]           ...           2 years ago
  • 0.66.0 [deprecated]           ...           2 years ago
  • 0.65.0 [deprecated]           ...           2 years ago
  • 0.64.0 [deprecated]           ...           2 years ago
  • 0.63.0 [deprecated]           ...           2 years ago
  • 0.62.0 [deprecated]           ...           2 years ago
  • 0.61.2 [deprecated]           ...           2 years ago
  • 0.61.1 [deprecated]           ...           2 years ago
  • 0.61.0 [deprecated]           ...           2 years ago
  • 0.60.0 [deprecated]           ...           2 years ago
  • 0.59.0 [deprecated]           ...           2 years ago
  • 0.58.0 [deprecated]           ...           2 years ago
  • 0.57.0 [deprecated]           ...           2 years ago
  • 0.56.1 [deprecated]           ...           2 years ago
  • 0.56.0 [deprecated]           ...           2 years ago
  • 0.55.0 [deprecated]           ...           2 years ago
  • 0.54.0 [deprecated]           ...           2 years ago
  • 0.53.0 [deprecated]           ...           2 years ago
  • 0.52.0 [deprecated]           ...           2 years ago
  • 0.51.0 [deprecated]           ...           2 years ago
  • 0.50.0 [deprecated]           ...           2 years ago
  • 0.49.0 [deprecated]           ...           2 years ago
  • 0.48.2 [deprecated]           ...           2 years ago
  • 0.48.1 [deprecated]           ...           2 years ago
  • 0.48.0 [deprecated]           ...           2 years ago
  • 0.47.0 [deprecated]           ...           2 years ago
  • 0.46.0 [deprecated]           ...           2 years ago
  • 0.45.0 [deprecated]           ...           2 years ago
  • 0.44.1 [deprecated]           ...           2 years ago
  • 0.44.0 [deprecated]           ...           2 years ago
  • 0.43.0 [deprecated]           ...           2 years ago
  • 0.42.1 [deprecated]           ...           2 years ago
  • 0.41.0 [deprecated]           ...           2 years ago
  • 0.40.0 [deprecated]           ...           2 years ago
  • 0.39.0 [deprecated]           ...           2 years ago
  • 0.38.1 [deprecated]           ...           2 years ago
  • 0.38.0 [deprecated]           ...           2 years ago
  • 0.37.1 [deprecated]           ...           2 years ago
  • 0.37.0 [deprecated]           ...           2 years ago
  • 0.36.0 [deprecated]           ...           2 years ago
  • 0.35.0 [deprecated]           ...           2 years ago
  • 0.34.0 [deprecated]           ...           2 years ago
  • 0.33.0 [deprecated]           ...           2 years ago
  • 0.32.0 [deprecated]           ...           2 years ago
  • 0.31.0 [deprecated]           ...           2 years ago
  • 0.30.1 [deprecated]           ...           2 years ago
  • 0.30.0 [deprecated]           ...           2 years ago
  • 0.29.0 [deprecated]           ...           2 years ago
  • 0.28.2 [deprecated]           ...           2 years ago
  • 0.28.1 [deprecated]           ...           2 years ago
  • 0.28.0 [deprecated]           ...           2 years ago
  • 0.27.0 [deprecated]           ...           2 years ago
  • 0.26.0 [deprecated]           ...           2 years ago
  • 0.25.0 [deprecated]           ...           2 years ago
  • 0.24.0 [deprecated]           ...           2 years ago
  • 0.23.0 [deprecated]           ...           2 years ago
  • 0.22.0 [deprecated]           ...           2 years ago
  • 0.21.0 [deprecated]           ...           2 years ago
  • 0.20.0 [deprecated]           ...           2 years ago
  • 0.19.0 [deprecated]           ...           2 years ago
  • 0.18.0 [deprecated]           ...           2 years ago
  • 0.17.0 [deprecated]           ...           2 years ago
  • 0.16.0 [deprecated]           ...           2 years ago
  • 0.15.0 [deprecated]           ...           2 years ago
  • 0.14.0 [deprecated]           ...           2 years ago
  • 0.13.0 [deprecated]           ...           2 years ago
  • 0.12.0 [deprecated]           ...           2 years ago
  • 0.11.0 [deprecated]           ...           2 years ago
  • 0.10.0 [deprecated]           ...           2 years ago
  • 0.9.0 [deprecated]           ...           2 years ago
  • 0.8.0 [deprecated]           ...           2 years ago
  • 0.7.0 [deprecated]           ...           2 years ago
  • 0.6.0 [deprecated]           ...           2 years ago
  • 0.5.0 [deprecated]           ...           2 years ago
  • 0.4.0 [deprecated]           ...           3 years ago
  • 0.3.0 [deprecated]           ...           3 years ago
  • 0.2.0 [deprecated]           ...           3 years ago
  • 0.1.0 [deprecated]           ...           3 years ago
Maintainers (1)
Downloads
Today 26
This Week 26
This Month 317
Last Day 6
Last Week 255
Last Month 1,387
Dependencies (9)
Dev Dependencies (33)
Dependents (134)

Copyright 2014 - 2016 © taobao.org |