Code Monkey home page Code Monkey logo

ast-koans's Introduction

Idea

How to given two file, generate the AST convert code automatically?

REPL for AST code power with TDD

  1. write expected first, then write AST
  2. run test until match expectation

Playground !

  1. AST explorer You can toggle the visibility of properties in AST Explorer with the checkboxes above the tree.
  2. GoGoCode PlayGround

Existing codemods

  1. js-codemod no-vars Convert all instances of "var" into either "let" or "const", based on the variable usage.

    For example, "let" if the variable is reassigned at a later time and "const" when the variable is never reassigned.

  2. js-codemod template-literals Replace instances of string concatenation with template literals e.g.

    const sayHello = 'Hi my name is ' + name; // after transform const sayHello = Hi my name is ${name};

  3. Codemod scripts to transform code to next generation JS

some helper to help

  1. A utility to help you explore jscodeshift

Example test data

var foo
foo = "foo"

var bar
bar = {foo: "foobar"}

var g
g = /abc/g

Business

Rename one variable in real time to auto rename all references

Esprima: Rename Refactoring

Improvements:

  1. Editor size should be full screen.
  2. Edit too quickly would fail to rename references.
  3. Edit after variable name does NOT take effect.
  4. Auto generate unique variable name.

Determineal: 0. Make sure there are not occurrens of "fn" and "anon" in source code. 2. There are not duplicate function name.

  1. Prefix function with fn_
  2. Anoymonus function parameter f?anX (? is the tail of function name like fn?, X is the uniq number)
  3. Variable name prefix by function abbreviation, if variable "a" inside function "fn_l" then renamed to "fl_a" if variable "b" inside annoymous function then renamed to "f?_anX_b"

Why not use auto-rename tools? function a() {var foo = "foo"} function b() {var foo = "bar"}

Generate the uniq function name and variable name: (seems like de-uglify) function a1cb13() {var _faxcb = "foo"} function fasdfz() {var abc2_3 = "bar"}

You should write an AST diff tool

  1. So that when you rename variable, you are confident what you change and would not omit some replacements.

ast-koans's People

Contributors

snowman avatar

Watchers

 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.