JSPM

ts-simple-ast

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 32591
  • Score
    100M100P100Q27131F
  • License MIT

Base project for typescript libraries

Package Exports

  • ts-simple-ast
  • ts-simple-ast/dist/utils

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-simple-ast) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ts-simple-ast

Build Status Coverage Status experimental

TypeScript compiler wrapper. Provides a simple way to navigate and manipulate the TypeScript AST.

DON'T USE THIS YET! This is a prototype and there's still a lot more work that needs to go into this. So far I barely have anything, but I will be working on this a lot over the next few months. I believe it will replace ts-type-info eventually as this is much more powerful.

Simple Layer

ts-simple-ast adds an abstraction layer over the compiler while still providing access to the underlying TypeScript compiler AST.

  1. Simple Layer - Provides a simple way for navigating and manipulating the AST.
  2. Compiler Layer - TypeScript compiler objects.

Changes made in the simple layer will be made to the underlying compiler layer.

Example

const ast = new TsSimpleAst();
const sourceFile = ast.addSourceFileFromText("MyFile.ts", "enum MyEnum {}\nlet myEnum: MyEnum;\nexport default MyEnum;");
const enumDeclaration = sourceFile.getEnumDeclarations()[0];
enumDeclaration.getName(); // "MyEnum"
enumDeclaration.setName("NewName");
enumDeclaration.addMember({
    name: "myNewMember"
});
enumDeclaration.setIsDefaultExport(false);
sourceFile.getFullText(); // "enum NewName {\n    myNewMember\n}\nlet myEnum: NewName;"
const sourceFileNode = sourceFile.getCompilerNode(); // underlying compiler node from the typescript AST