function replaceDOMReferences()

in transforms/React-DOM-to-react-dom-factories.js [111:135]


    function replaceDOMReferences(j, root) {
      let hasModifications = false;

      const isDOMIdentifier = path =>
        path.node.name === DOMModuleName &&
        path.parent.parent.node.type === 'CallExpression';

      root
        .find(j.Identifier)
        .filter(isDOMIdentifier)
        .forEach(path => {
          hasModifications = true;

          const DOMargs = path.parent.parent.node.arguments;
          const DOMFactoryPath = path.parent.node.property;
          const DOMFactoryType = DOMFactoryPath.name;

          // DOM.div(... -> createElement(...
          j(path.parent).replaceWith(j.identifier('createElement'));
          // createElement(... -> createElement('div', ...
          DOMargs.unshift(j.literal(DOMFactoryType));
        });

      return hasModifications;
    }