GithubHelp home page GithubHelp logo

5to6's Introduction

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

5to6's People

Contributors

thomasloh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

5to6's Issues

Why no ES6 code conventions for this repo

Why haven't you used ES6 features like classes, let, imports for this repository. Since it being a converter to ES6, it would be better for it to follow ES6 conventions

Classes

It would be great if we could transpile constructor functions to classes.
Convert this:

function Fuu(fuu) {
    this.fuu = fuu;
}

Fuu.prototype.bar = function(arg) {
    console.log(arg);
}

Into this:

class Fuu {
    constuctor(fuu) {
        this.fuu = fuu;
    }

    bar(arg) {
        console.log(arg);
    }
}

Combine efforts?

A few weeks ago I created this...and just went to try to publish it today:
https://github.com/5to6/5to6

Looks like you beat me to it by a few days!

I think architecturally our 2 things look a bit different, but I think we have the same goals. Would you have any interesting in combining?

Error: Cannot find module 'Set'

After install it i get this error trying to run 5to6:

module.js:338
throw err;
^
Error: Cannot find module 'Set'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/home/jaydson/.nvm/v0.11.14/lib/node_modules/5to6/src/modules/convert-require-stmt-to-import-stmt.js:6:14)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/home/jaydson/.nvm/v0.11.14/lib/node_modules/5to6/src/index.js:10:3)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
jaydson@jaydson:~/Workspace/transpileption$

Factor out middlewarez?

Hey, I was wondering if you would be open to the idea of making the middleware that runs source transforms as seperate npm modules.

It would make it easier for people (such as myself) to develop/contribute middleware modules for other lexical transforms.

Also along with that maybe exposing an api to register/deregister middleware components to make customizing stuff easier.

I would be willing to do these things if you're open to the idea.

Keeps saying git is not installed. But it is

Windows Git is installed. Everything in the target folder (which is a copy, anyway, so I don't really care about git here) is committed to git.

git status says:
$ git status
On branch master
nothing to commit, working directory clean

yet running 5to6 exits with
git must to be installed. In case want to revert changes, can use git reset --h ard

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.