nextify

    0.0.1 • Public • Published

    These are experimental babel transforms for cleaning up your codebase with nice ES6+ idioms.

    Babel is usually used for turning nice source code into runnable source code. But in this case we can take advantage of its infrastructure to do the reverse: take an old codebase and make it nicer.

    For example, we can turn CoffeeScript into ES6 by first compilng it with our usual coffescript compiler, and then running it through these transforms to opportunistically clean up the resulting messes.

    Using them

    These are still experimental, good luck.

    1. npm install -g

    Transformations

    Fat-Arrowize

    This transform looks for opportunities to rewrite functions as arrow expressions, based on the use of this. Function expressions that don't access this are safe to rewrite, so:

    myList.map(function(x){ return x + 1; })

    becomes:

    myList.map(x => x + 1)

    We can also detect common patterns for binding this and greatly simplify them. For example, this is how CoffeeScript's fat arrow compiles:

    myList.map((function(_this) {
      return function(elt) {
        this.handle(elt);
      };
    })(this));

    which we can automatically convert to:

    myList.map(elt => this.handle(elt));

    Keywords

    none

    Install

    npm i nextify

    DownloadsWeekly Downloads

    0

    Version

    0.0.1

    License

    MIT

    Last publish

    Collaborators

    • avatar