decorate falafel nodes with some fancy helpers
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE
README.md
index.js
package.json

README.md

falafel-helpers

Wraps your falafel callback function, adding handy helpers:

var falafelHelpers = require('falafel-helpers');

var srcBefore = fs.readFileSync('test.js', 'utf8');
var srcAfter = falafel(srcBefore, helpers.wrap(function (node) {
	if (/Expression$/.test(node.type)) {
		node.wrap('debug(', ')');
	} else if (node.type === 'BlockStatement') {
		node.before('console.log("entering block");');
		node.after('console.log("exiting block");', true); // second argument makes it use a try-finally to always execute the inserted code
	}
});

Also works with falafel-map:

var falafelHelpers = require('falafel-helpers');

var srcBefore = fs.readFileSync('test.js', 'utf8');
var srcAfter = falafel(srcBefore, helpers.wrap(function (node) {
	if (/Expression$/.test(node.type)) {
		node.wrap('debug(', ')');
	}
}, { falafelMap: true }));