mohebifar / lebab
- суббота, 21 мая 2016 г. в 03:15:27
JavaScript
Turn your ES5 code into readable ES6 (sugar-syntax). It does the opposite of what Babel does.
Lebab transpiles your ES5 code to ES2015. It does exactly the opposite of what Babel does. If you want to understand what Lebab exactly does, try the live demo.
Install it using npm:
$ npm install -g lebab
Transpile your old-fashioned code using the lebab
cli tool.
$ lebab es5.js -o es6.js
Or convert just the features of your choice:
$ lebab es5.js -o es6.js --enable let,arrow,commonjs
Lebab is not magic. It uses heuristics to figure out likely ES6 equivalent, but it doesn't guarantee that the resulting code is 100% equivalent.
Therefore the recommended way of using Lebab is to apply one transform at a time, read what exactly the transform does and what are its limitations, apply it for your code and inspect the diff carefully.
Foo.prototype.method = function(){ ... };
Foo.prototype = { ...methods... };
Object.defineProperty()
${...}
.toString()
and .valueOf()
function(){}.bind(this)
this
arguments
obj-method
transform){ return x; }
to => x
that = this
assignmentsvar
to let
/const
const
let
/const
as var
a = a || 2
a = a || 2
a = a ? a : 2
a = a === undefined ? 2 : a
a = typeof a === 'undefined' ? 2 : a
a = a || 2
does produce strictly equivalent codeobj.method.apply(obj, args)
func.apply(undefined, args)
{foo: foo}
to {foo}
NaN
properties"use strict"
directives
x = "use strict";
var foo = require("foo")
to import foo from "foo"
var bar = require("foo").bar
to import {bar} from "foo"
var {bar} = require("foo")
to import {bar} from "foo"
require()
calls in var
declarationsconst
module.exports = <anything>
to export default <anything>
exports.foo = function(){}
to export function foo(){}
exports.Foo = class {}
to export class Foo {}
exports.foo = 123
to export var foo = 123
exports.foo = bar
to export {bar as foo}
Which feature should Lebab implement next? Let us know by creating an issue or voicing your opinion in existing one.
Want to contribute? Read how Lebab looks for patterns in syntax trees.