/transform

This project will automatically transform requireJS AMD module format to ES6 module format by parsing specified JS files and can smartly skip the files that are already ES6 module format. It derives from our product that try to migrate our existing ES5 to ES6. More features will be added.

Primary LanguageJavaScript

Note: Experimental

transform AMD module definition to ES6 syntax

Motivation

Converts (partial) ES5 code to ES6. Converted files are expected to be used with ES6 transpilers like Babel.

Uses recast to get code's AST and detect then modify certain syntax to the equivalent in ES6. Semantics don't change, only the syntax.

Supported conversions

define(['foo', 'bar'], function(Foo, Bar){
        Foo.xxx();
        Bar.yyy();
        return {
            value: 'xxx'
        };
});
=>
import Foo from 'foo';
import Bar from 'bar';

Foo.xxx();
Bar.yyy();
export default {
    value: 'xxx'
};

Usage

transform -s src    # converts all js or jsx files in "src" folder (relative to current directory)

Huge credit goes to recast by benjamn