-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (26 loc) · 748 Bytes
/
Copy pathindex.js
File metadata and controls
29 lines (26 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
module.exports = (api) => {
api.assertVersion('^7.0.0 || ^8.0.0');
const t = api.types;
const contextTemplate = api.template.smart(
`(function () {
function req() {}
req.keys = function () { return []; }
req.resolve = function () {};
return req;
}())`);
return {
name: 'transform-require-context',
visitor: {
MemberExpression(path) {
const node = path.node;
if (t.isCallExpression(path.parent) &&
t.isIdentifier(node.object, { name: 'require' }) &&
t.isIdentifier(node.property, { name: 'context' }) &&
!path.scope.hasOwnBinding('require')) {
path.parentPath.replaceWith(contextTemplate());
}
}
}
}
};