var falafel = require('falafel');
module.exports = replace;

function replace (src, deps) {
    return falafel(src, function (node) {
        if (isRequire(node)) {
            var value = node.arguments[0].value;
            if (has(deps, value) && deps[value]) {
                node.update('require(' + JSON.stringify(deps[value]) + ')');
            }
        }
    }).toString();
}

function isRequire (node) {
    var c = node.callee;
    return c
        && node.type === 'CallExpression'
        && c.type === 'Identifier'
        && c.name === 'require'
        && node.arguments[0]
        && node.arguments[0].type === 'Literal'
    ;
}

function has (obj, key) {
    return Object.prototype.hasOwnProperty.call(obj, key);
}

var falafel = require('falafel');
module.exports = replace;

function replace (src, deps) {
    return falafel(src, {ecmaVersion: 6}, function (node) {
        if (isRequire(node)) {
            var value = node.arguments[0].value;
            if (has(deps, value) && deps[value]) {
                node.update('require(' + JSON.stringify(deps[value]) + ')');
            }
        }
    }).toString();
}

function isRequire (node) {
    var c = node.callee;
    return c
        && node.type === 'CallExpression'
        && c.type === 'Identifier'
        && c.name === 'require'
        && node.arguments[0]
        && node.arguments[0].type === 'Literal'
    ;
}

function has (obj, key) {
    return Object.prototype.hasOwnProperty.call(obj, key);
}

Set "{ecmaVersion: 6}" for falafel's acorn
Set "{ecmaVersion: 6}" for falafel's acorn
