falafel-helpers

decorate falafel nodes with some fancy helpers

Usage no npm install needed!

<script type="module">
  import falafelHelpers from 'https://cdn.skypack.dev/falafel-helpers';
</script>

README

falafel-helpers

Wraps your falafel callback function, adding handy helpers:

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

var src = falafel(fs.readFileSync('test.js', 'utf8'), 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 src = falafel(fs.readFileSync('test.js', 'utf8'), helpers.wrap(function (node) {
    if (/Expression$/.test(node.type)) {
        node.wrap('debug(', ')');
    }
}, { falafelMap: true }));