-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (24 loc) · 694 Bytes
/
index.js
File metadata and controls
27 lines (24 loc) · 694 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
'use strict';
const template = require('@babel/template');
module.exports = ({types: t}) => {
const contextTemplate = template.smart(
`(function () {
function req() {}
req.keys = function () { return []; }
req.resolve = function () {};
return req;
}())`);
return {
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());
}
}
}
}
};