ts-simple-ast-extra
TypeScript icon, indicating that this package has built-in type declarations

0.3.15 • Public • Published

ts-simple-ast-extra

High level TypeScript Compiler API and TypeScript/JavaScript refactor APIs based on ts-morph (ex ts-simple-ast) library.

Contents

Summary

  • Browser support (out of the box)

  • Many APIs for project's code refactors.

    • in general based on TypeScript built in code fixes and refactors
    • Easy to use.
    • Configurable
    • Composable
    • Have tests but use at your own risk
  • APIs useful to me that unfortunately are out of topic to pull them to in ts-morph like astPath or generalNode abstraction or

  • utilities related with TypeScript Plugin development like abstract types, Tests Helpers, AST, repeated code, codefixes generic structure, etc

  • Access to not so public areas of TypeScript APIs or some encapsulated hacks

Install

npm install ts-simple-ast-extra

Usage

NOTE: Currently, although there is API documentation I would say the best source of documentation are the test.

  • There are many different kind of APIs. Each file in src implements a "topic".
  • Each file or "topic" has a test at spec folder using the same name. At the beggining there is alwasys a simple usage src/refactor contain many interesting code refactors at the project level

Refactors

In general they have the same API, you pass a SourceFile and the Project (they need access to the LanguageService):

addBracesToArrowFunctions

import {Project, addBracesToArrowFunctions} from 'ts-simple-ast-extra'
const project = new Project()
const f = project.createSourceFile('f1.ts',  `
  const c = a => a+1
  export f = (b:number h: Date[])=>null
`)
addBracesToArrowFunctions(project, f)
console.log(f.getText())
/*
const c = a => { 
  return a + 1; 
export f = (b:number h: Date[])=>{ 
  return null; 
}
*/

format

import {Project, format} from 'ts-simple-ast-extra'
const project = new Project()
const file = project.createSourceFile('f2.ts',  `
function f(){
alert(1);
log(2,function(){
return 1+g(a=>{
return 2
}              )
}    );
}`)
const output = format({
  file,
  project,
  trailingSemicolons: 'never',
  indentSize: 2,
})
console.log(f.getText())
/*
function f() {
  alert(1)
  log(2, function() {
    return 1 + g(a => {
      return 2
    })
  })
}
*/

API docs

See API docs

CHANGELOG

CHANGELOG.md

TODO

TODO.md

Related projects

  • ../typescript-ast-util - similar objectives but independent on any library accessing directly TypeScript API

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.3.1512latest

Version History

VersionDownloads (Last 7 Days)Published
0.3.1512
0.3.140
0.3.134
0.3.120
0.3.111
0.3.100
0.3.90
0.3.80
0.3.70
0.3.60
0.3.50
0.3.40
0.2.31
0.2.21
0.2.10
0.1.1610
0.1.151
0.1.140
0.1.130
0.1.120
0.1.110
0.1.100
0.1.90
0.1.80
0.1.70
0.1.60
0.1.50
0.1.40
0.1.30
0.1.20
0.1.10
0.1.00
0.0.190
0.0.180
0.0.170
0.0.160
0.0.150
0.0.140
0.0.130
0.0.120
0.0.110
0.0.100
0.0.9134
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20

Package Sidebar

Install

npm i ts-simple-ast-extra

Weekly Downloads

143

Version

0.3.15

License

MIT

Unpacked Size

214 kB

Total Files

128

Last publish

Collaborators

  • cancerberosgx