mirror of https://github.com/lukechilds/ava.git
James Talmage
9 years ago
6 changed files with 139 additions and 9 deletions
@ -0,0 +1,19 @@ |
|||||
|
module.exports = function (babel) { |
||||
|
var t = babel.types; |
||||
|
|
||||
|
return { |
||||
|
visitor: { |
||||
|
CallExpression: function (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'))); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
}; |
||||
|
|
||||
|
function isRequire(path) { |
||||
|
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require'); |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
module.exports = function (babel) { |
||||
|
var t = babel.types; |
||||
|
|
||||
|
return { |
||||
|
visitor: { |
||||
|
CallExpression: function (path) { |
||||
|
// skip require calls
|
||||
|
var firstArg = path.get('arguments')[0]; |
||||
|
if (!isRequire(path) && firstArg && firstArg.isStringLiteral() && !/repeated test/.test(firstArg.node.value)) { |
||||
|
firstArg.replaceWith(t.stringLiteral(firstArg.node.value.toUpperCase())); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
}; |
||||
|
|
||||
|
function isRequire(path) { |
||||
|
return path.isCallExpression() && path.get('callee').isIdentifier() && (path.get('callee').node.name === 'require'); |
||||
|
} |
@ -0,0 +1,4 @@ |
|||||
|
{ |
||||
|
"presets": ["es2015", "stage-2"], |
||||
|
"plugins": ["../babel-plugin-foo-to-bar"] |
||||
|
} |
@ -1,3 +1,4 @@ |
|||||
{ |
{ |
||||
"plugins": ["this-plugin-does-not-exist"] |
"presets": ["es2015", "stage-2"], |
||||
|
"plugins": ["../babel-plugin-test-doubler"] |
||||
} |
} |
||||
|
@ -1,3 +1,3 @@ |
|||||
import test from '../../../' |
import test from '../../../' |
||||
|
|
||||
test(t => t.pass()); |
test('foo', t => t.pass()); |
||||
|
Loading…
Reference in new issue