'use strict';
const helperModuleImports = require('@babel/helper-module-imports');
module.exports = function autoImporter(babel) {
function getAssignIdent(path, file, state) {
if (state.id) {
return state.id;
}
state.id = helperModuleImports.addDefault(path, 'shared/assign', {
nameHint: 'assign',
});
return state.id;
}
return {
pre: function() {
this.id = null;
},
visitor: {
CallExpression: function(path, file) {
if (/shared(\/|\\)assign/.test(file.filename)) {
return;
}
if (path.get('callee').matchesPattern('Object.assign')) {
const id = getAssignIdent(path, file, this);
path.node.callee = id;
}
},
MemberExpression: function(path, file) {
if (/shared(\/|\\)assign/.test(file.filename)) {
return;
}
if (path.matchesPattern('Object.assign')) {
const id = getAssignIdent(path, file, this);
path.replaceWith(id);
}
},
},
};
};