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 lebabTranspile your old-fashioned code using the lebab cli tool.
$ lebab es5.js -o es6.jsOr convert just the features of your choice:
$ lebab es5.js -o es6.js --enable let,arrow,commonjsLebab 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)thisargumentsobj-method transform){ return x; } to => xthat = this assignmentsvar to let/const
constlet/const as vara = a || 2
a = a || 2a = a ? a : 2a = a === undefined ? 2 : aa = typeof a === 'undefined' ? 2 : aa = 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 declarationsconstmodule.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 = 123exports.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.