function hasDestructuredElement()

in packages/flow-upgrade/src/codemods/ReactUtils.js [162:212]


  function hasDestructuredElement(path: any, reactName?: ?string): boolean {
    // All of the places where we want to treat as React.
    const REACT_MODULES = new Set(['React', 'react', 'react-native']);
    reactName = reactName || getImportedReactName(path);
    return (
      path
        .find(j.ImportDeclaration, {
          specifiers: specifiers =>
            specifiers.find(
              specifier =>
                specifier &&
                specifier.type === 'ImportSpecifier' &&
                specifier.imported &&
                specifier.imported.type === 'Identifier' &&
                specifier.imported.name === 'Element' &&
                specifier.local &&
                specifier.local.type === 'Identifier' &&
                specifier.local.name === 'Element',
            ),
          source: {
            type: 'Literal',
            value: value => REACT_MODULES.has(value),
          },
        })
        .size() > 0 ||
      path
        .find(j.VariableDeclarator, {
          init: {
            type: 'Identifier',
            name: reactName,
          },
          id: {
            type: 'ObjectPattern',
            properties: properties =>
              !!properties.find(
                property =>
                  property &&
                  !property.method &&
                  property.shorthand &&
                  property.key &&
                  property.key.type === 'Identifier' &&
                  property.key.name === 'Element' &&
                  property.value &&
                  property.value.type === 'Identifier' &&
                  property.value.name === 'Element',
              ),
          },
        })
        .size() > 0
    );
  }