babel-plugin-simple-logger

1.1.1 • Public • Published

babel-plugin-simple-logger

npm npm

Special thanks to Michael Jungo for helping me put the first version together.

This Babel plugin looks for the string literal "log" after the opening bracket of a function and replaces it with console.log(<function name>, <arg1>, <arg2>, etc...).

const add = (a, b) => { 'log'
    return a + b
}
 
// becomes...
 
const add = (a, b) => {
    console.log('add', a, b)
    return a + b
}

Installation & Usage

Install the package

yarn add babel-plugin-simple-logger --dev

Incorporate the plugin

// .babelrc
...
"env": {
    "development": {
        "presets": ["react", "env", "stage-0"],
        "plugins": ["simple-logger"]
    },
...
}

Test it out

function greeter(name='world') { 'log'
    return `Hello, ${name}!`
}
 
greeter("Gus")
 
// logs...
 
greeter "Gus"

Note: Arrow functions with implicit returns (e.g. (a, b) => a + b) aren't candidates for logging with this plugin's syntax.

Package Sidebar

Install

npm i babel-plugin-simple-logger

Weekly Downloads

9

Version

1.1.1

License

ISC

Last publish

Collaborators

  • gnordhielm