in packages/babel-preset-fbjs/plugins/inline-requires.js [64:110]
CallExpression(path, state) {
const parseResult =
parseInlineableAlias(path, state) ||
parseInlineableMemberAlias(path, state);
if (parseResult == null) {
return;
}
const {
declarationPath,
moduleName,
requireFnName,
} = parseResult;
const init = declarationPath.node.init;
const name = declarationPath.node.id
? declarationPath.node.id.name
: null;
const binding = declarationPath.scope.getBinding(name);
if (binding.constantViolations.length > 0) {
return;
}
deleteLocation(init);
babel.traverse(init, {
noScope: true,
enter: path => deleteLocation(path.node),
});
let thrown = false;
for (const referencePath of binding.referencePaths) {
excludeMemberAssignment(moduleName, referencePath, state);
try {
referencePath.scope.rename(requireFnName);
referencePath.replaceWith(t.cloneDeep(init));
} catch (error) {
thrown = true;
}
}
// If a replacement failed (e.g. replacing a type annotation),
// avoid removing the initial require just to be safe.
if (!thrown) {
declarationPath.remove();
}
},