How to use falafel - 4 common examples

To help you get started, we’ve selected a few falafel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github antimatter15 / gayfish / src / app.js View on Github external
// modules: 'amd',
        stage: 0
    }).code;

    var progressTracker = '__track$loop__'
    function removeMerp(src){
        console.log('removing merp', src)
        return falafel(src, function(node){
            if(node.type == 'CallExpression' &&
                node.callee.type == 'Identifier' &&
                node.callee.name == progressTracker){
                node.update('0')
            }
        }).toString()
    }
    var result = falafel(middle, function (node) {
        if(node.type === 'ForStatement'){
            if(node.test.type == 'BinaryExpression' && 
                node.test.right.type == 'Literal' && 
                node.test.left.type == 'Identifier' &&
                node.test.operator == '<'){
                node.update.update(node.update.source() + ','+progressTracker+'(' + node.test.left.name + ', ' + node.test.right.value + ')')
                node.body.update(removeMerp(node.body.source()))
            }
        }else if(node.type === 'CallExpression'){
            if(node.callee.type == 'MemberExpression' && 
                ['forEach', 'map'].indexOf(node.callee.property.name) != -1 &&
                node.arguments[0].type == 'FunctionExpression') {
                var thing = node.arguments[0].body;
                thing.update('{'+progressTracker+'(arguments[1], arguments[2].length);' + thing.source().slice(1))
                // removeMerp(
            }
github antimatter15 / gayfish / src / app.js View on Github external
function removeMerp(src){
        console.log('removing merp', src)
        return falafel(src, function(node){
            if(node.type == 'CallExpression' &&
                node.callee.type == 'Identifier' &&
                node.callee.name == progressTracker){
                node.update('0')
            }
        }).toString()
    }
    var result = falafel(middle, function (node) {
github rebem / layers-loader / lib / transform.js View on Github external
export default function(source, file, options) {
    const consumerPaths = options.layers.map(layer => layer.path).concat(options.consumers || []);
    const isFileInheritable = consumerPaths.some(layerPath => {
        return file.indexOf(layerPath) === 0;
    });

    if (!isFileInheritable) {
        return Promise.resolve(source);
    }

    const requiresPromises = [];
    const out = falafel(source, node => {
        if (
            node.type === 'CallExpression' &&
            node.callee.type === 'Identifier' &&
            node.callee.name === 'require' &&
            node.arguments[0].value.charAt(0) === '#'
        ) {
            const rawRequireValue = node.arguments[0].value;

            requiresPromises.push(
                getResults(rawRequireValue, file, options.layers).then(origResult => {
                    const result = {
                        ...origResult
                    };

                    if (result.component) {
                        result.component = stringifyRequest(this, result.component).replace(/"/g, '');
github rebem / layers-loader / lib / inject / loader.js View on Github external
export default function(source) {
    if (this.cacheable) {
        this.cacheable();
    }

    const result = falafel(source, node => {
        if (
            node.type === 'CallExpression' &&
            node.callee.type === 'Identifier' &&
            node.callee.name === 'require'
        ) {
            const value = node.arguments[0].value;

            node.update(`typeof __inject__('${value}') !== 'undefined' ? __inject__('${value}') : require('${value}')`);
        }
    });

    return `
exports['default'] = function(__injections__) {
    var exports = {};

    function __inject__(value) {

falafel

transform the ast on a recursive walk

MIT
Latest version published 3 years ago

Package Health Score

68 / 100
Full package analysis

Popular falafel functions