function getInlineableModule()

in packages/babel-preset-fbjs/plugins/inline-requires.js [220:262]


function getInlineableModule(path, state) {
  const node = path.node;
  const isInlineable =
    node.type === 'CallExpression' &&
    node.callee.type === 'Identifier' &&
    state.inlineableCalls.has(node.callee.name) &&
    node['arguments'].length >= 1;

  if (!isInlineable) {
    return null;
  }

  // require('foo');
  let moduleName =
    node['arguments'][0].type === 'StringLiteral'
      ? node['arguments'][0].value
      : null;

  // require(require.resolve('foo'));
  if (moduleName == null) {
    moduleName =
      node['arguments'][0].type === 'CallExpression' &&
      node['arguments'][0].callee.type === 'MemberExpression' &&
      node['arguments'][0].callee.object.type === 'Identifier' &&
      state.inlineableCalls.has(node['arguments'][0].callee.object.name) &&
      node['arguments'][0].callee.property.type === 'Identifier' &&
      node['arguments'][0].callee.property.name === 'resolve' &&
      node['arguments'][0]['arguments'].length >= 1 &&
      node['arguments'][0]['arguments'][0].type === 'StringLiteral'
        ? node['arguments'][0]['arguments'][0].value
        : null;
  }

  // Check if require is in any parent scope
  const fnName = node.callee.name;
  const isRequireInScope = path.scope.getBinding(fnName) != null;

  return moduleName == null ||
    state.ignoredRequires.has(moduleName) ||
    isRequireInScope
    ? null
    : { moduleName, requireFnName: fnName };
}