exit()

in packages/babel-preset-fbjs/plugins/inline-requires.js [43:118]


      exit(path, state) {
        const t = babel.types;
        const ignoredRequires = new Set();
        const inlineableCalls = new Set(['require']);

        if (state.opts != null) {
          if (state.opts.ignoredRequires != null) {
            for (const name of state.opts.ignoredRequires) {
              ignoredRequires.add(name);
            }
          }
          if (state.opts.inlineableCalls != null) {
            for (const name of state.opts.inlineableCalls) {
              inlineableCalls.add(name);
            }
          }
        }

        path.scope.crawl();
        path.traverse(
          {
            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();
              }
            },
          },
          {
            ignoredRequires,
            inlineableCalls,
            membersAssigned: new Map(),
          },
        );
      },