GithubHelp home page GithubHelp logo

graingert / lebab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lebab/lebab

0.0 2.0 0.0 1.66 MB

Turn your ES5 code into readable ES6 (sugar-syntax). It does the opposite of what Babel does.

Home Page: https://lebab.io/

License: MIT License

JavaScript 100.00%

lebab's Introduction

Build Status License JS.ORG

Lebab

Lebab

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.

Usage

Install it using npm:

$ npm install -g lebab

Convert your old-fashioned code using the lebab cli tool, enabling a specific transformation:

$ lebab es5.js -o es6.js --enable let

Features and known limitations

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.

Safe transforms

These transforms can be applied with relatively high confidence. They use pretty straight-forward and strict rules for changing the code. The resulting ES2015 code should be almost 100% equivalent of the original code.

  • arrow - callbacks to arrow functions
    • Converts bound functions like function(){}.bind(this)
    • not applied to unbound functions that use this
    • not applied to functions that use arguments
    • not applied to object properties (use obj-method transform)
    • converts immediate return { return x; } to => x
    • does not remove that = this assignments
    • BUG fails with immediately returning functions that have methods invoked
  • let - var to let/const
    • never modified variables are converted to const
    • properly recognizes block-scoping
    • splits single var declaration to multiple let/const declarations if needed
    • recognizes vars defined/assigned using destructuring
    • vars that conflict with block-scoping are not converted
    • repeated declarations of the same var are not converted
    • existing let/const are not converted
    • BUG fails with repeated variable definitions that use destructuring
  • arg-spread - use of apply() to spread operator
    • recognizes obj.method.apply(obj, args)
    • recognizes func.apply(undefined, args)
  • obj-method - function values in object to methods
  • obj-shorthand - {foo: foo} to {foo}
    • ignores numeric and NaN properties
    • does not convert string properties
  • no-strict - removal of "use strict" directives
    • does not touch stuff like x = "use strict";
  • commonjs - CommonJS module definition to ES6 modules
    • converts var foo = require("foo") to import foo from "foo"
    • converts var bar = require("foo").bar to import {bar} from "foo"
    • converts var {bar} = require("foo") to import {bar} from "foo"
    • only handles require() calls in var declarations
    • does not ensure that imported variable is treated as const
    • converts module.exports = <anything> to export default <anything>
    • converts exports.foo = function(){} to export function foo(){}
    • converts exports.Foo = class {} to export class Foo {}
    • converts exports.foo = 123 to export var foo = 123
    • converts exports.foo = bar to export {bar as foo}
    • does not check if named export conflicts with existing variable names
    • does not recognize imports/exports inside nested blocks/functions

Unsafe transforms

These transforms should be applied with caution. They use heuristics to detect common patterns that can be expressed with ES2015 syntax. There are no guarantees that the resulting code is equivalent of the original code.

What's next?

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.

lebab's People

Contributors

brendanannable avatar kramerc avatar lfilho avatar mohebifar avatar nene avatar nkt avatar rreverser avatar tb avatar

Watchers

 avatar  avatar

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.