1.1.1 • Published 6 years ago

babel-plugin-simple-logger v1.1.1

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

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.