Files
test-repo/scripts/build/babel-plugins/transform-custom-require.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

22 lines
473 B
JavaScript
Raw Normal View History

2018-05-24 15:30:45 -03:00
"use strict";
// `eval("require")` -> `require`
2018-05-24 15:30:45 -03:00
module.exports = function (babel) {
const t = babel.types;
2018-06-28 15:56:25 -03:00
2018-05-24 15:30:45 -03:00
return {
visitor: {
2018-06-28 15:56:25 -03:00
CallExpression(path) {
2020-01-14 23:30:18 +08:00
const { node } = path;
if (
t.isIdentifier(node.callee, { name: "eval" }) &&
node.arguments.length === 1 &&
t.isLiteral(node.arguments[0], { value: "require" })
) {
path.replaceWith(t.identifier("require"));
}
2018-05-24 15:30:45 -03:00
},
},
};
};