Convert (partial) ES5 code to ES6
Switch branches/tags
Nothing to show
Clone or download
Thomas
Thomas 0.0.3
Latest commit 9b26187 Apr 17, 2015
Permalink
Failed to load latest commit information.
bin add readme and misc changes Mar 5, 2015
src use the correct Set Apr 17, 2015
.gitignore initial Mar 3, 2015
LICENSE add mit license Mar 5, 2015
README.md Update README.md Mar 10, 2015
package.json 0.0.3 Apr 17, 2015

README.md

Note: Experimental

5to6

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

var b = {
 abc: abc
}
=>
var b = {
 abc
}

{
 abc: function() {
   console.log('a')
 }
}
=>
{
 abc() {
   console.log('a')
 }
}

module.exports = Component
=>
export default Component

var Foo = require('foo')
=>
import Foo from 'foo'

var Bar = require('foo').Bar
=>
import {Bar} from 'foo'

require('foo')
=>
import 'foo'

var Foo = require('foo')
var Bar = Foo.Bar
var Baz = Foo.Baz
=>
import Foo, {Bar, Baz} from 'foo'

Install

sudo npm install 5to6 -g

Usage

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

5to6 -s .      # converts all js or jsx files in current directory

5to6 -s . -v   # verbose mode

Caveats

This lib was initially created to convert a particular project's codebase to ES6, so it assumes certain code structure. If your codebase is using the commonjs style modules structure, it should work. Codebase with everything in one big closure will not work. Again, this lib is experimental.

5to6 directly writes to file after conversion. So it depends on git, not for conversion, but for reversion in case output is not as expected etc.

To revert conversion, simply run

git reset --hard

Credits

Huge credit goes to recast by benjamn