Coder Social home page Coder Social logo

jesperorb / jscodeshift-typescript Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 0.0 100 KB

A repo demonstrating jscodeshift in combination with TypeScript and JSX

JavaScript 0.93% TypeScript 93.23% Handlebars 5.84%
jscodeshift codemod codemods typescript jsx ast plopjs

jscodeshift-typescript's Introduction

JSCodeShift TypeScript (JSX)

JsCodeShift is a automatic code refactoring tool. It converts files into AST, tinkers with the tree and the puts it back together into a nice new file.

This repo contains examples on how to use JSCodeShift in combination with TypeScript and JSX. Test it with Jest and generate scaffolding for new transform with PlopJS.

ASTExplorer is a great tool for exploring how the AST looks like. (set parser to @typescript-eslint/parser instead of acorn to enable JSX and TypeScript)

Get started

Clone the repo and install dependencies

yarn

Running via cli

You can run the included example on a file of your choice via the following command. Either create a new file or run it against on any of the .input.-files. This is the same process as running the tests.

npx jscodeshift --parser=tsx -t ./src/transforms/remove-jsx-prop/remove-jsx-prop.ts {filepath to files you want to run transform on}

Test

yarn test

Each transform has two textfixtures, on input and one output. defineTest sets up to automatically do snapshot testing between these two files.

Generate transformer

yarn plop

Dependencies

  • jscodeshift to run the codemods
  • esbuild/esbuild-jest to run tests in TypeScript (faster than ts-jest)
  • plop to generate scaffolding
  • ts-node to run plop with TypeScript files.

Todo

  • Set up interface merging for Collection as types are not added when using .registerMethods() making custom methods hard to handle in typescript

jscodeshift-typescript's People

Contributors

jesperorb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.