0.1.1 • Published 6 years ago

babel-plugin-arrow-functions-implicit-return v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Arrow functions implicit return

This plugin allows you to use arrow functions like do expressions.

Examples

const shows = ["Death Note", "Steins;Gate", "Maho shojo XD"];
const nextShow = prevShow => {
    const prevIndex = shows.findIndex(show => show === prevShow) || 0;
    shows[(prevIndex + 1) % shows.length];
};

With JSX

const getUserNav = () => {
    <UserConsumer>
        {
            (user) => {
                if(user){
                    <span>Hello {user.name}!<span>;
                } else {
                    <a onClick={showLogin}>Login</a>;
                }
            }
        }
    </UserConsumer>
};

Installation

npm install --save-dev babel-plugin-arrow-functions-implicit-return

Usage

Via .babelrc (Recommended)

.babelrc

{
    "plugins": ["arrow-functions-implicit-return"]
}

Via CLI

babel --plugins arrow-functions-implicit-return script.js

Via Node API

require("babel-core").transform("code", {
    plugins: ["arrow-functions-implicit-return"]
});