You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

22 lines
577 B

'use strict';
function isRequire(path) {
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require');
}
module.exports = babel => {
const t = babel.types;
return {
visitor: {
CallExpression: path => {
// skip require calls
var firstArg = path.get('arguments')[0];
if (!isRequire(path) && firstArg && firstArg.isStringLiteral() && /foo/i.test(firstArg.node.value)) {
firstArg.replaceWith(t.stringLiteral(firstArg.node.value.replace('foo', 'bar').replace('FOO', 'BAR')));
}
}
}
};
};