Skip to content

Instantly share code, notes, and snippets.

@zthxxx
Created September 28, 2021 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zthxxx/917e5d9b46049ad3792ba0221feed9f5 to your computer and use it in GitHub Desktop.
Save zthxxx/917e5d9b46049ad3792ba0221feed9f5 to your computer and use it in GitHub Desktop.
module.exports = ({ types: t }) => ({
name: 'require-context',
visitor: {
CallExpression: path => {
if (
t.isMemberExpression(path.node.callee, { computed: false })
&& t.isIdentifier(path.get('callee').node.object, { name: 'require' })
&& t.isIdentifier(path.get('callee').node.property, { name: 'context' })
) {
path.replaceWith(
t.callExpression(t.identifier('__requireContext'), [
...path.node.arguments,
]),
)
}
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment