'use strict';

module.exports = function (context) {
  var specifierExportCount = 0;
  var hasDefaultExport = false;
  var hasStarExport = false;
  var namedExportNode = null;

  return {
    'ExportSpecifier': function ExportSpecifier(node) {
      if (node.exported.name === 'default') {
        hasDefaultExport = true;
      } else {
        specifierExportCount++;
        namedExportNode = node;
      }
    },

    'ExportNamedDeclaration': function ExportNamedDeclaration(node) {
      // if there are specifiers, node.declaration should be null
      if (!node.declaration) return;

      function captureDeclaration(identifierOrPattern) {
        if (identifierOrPattern.type === 'ObjectPattern') {
          // recursively capture
          identifierOrPattern.properties.forEach(function (property) {
            captureDeclaration(property.value);
          });
        } else {
          // assume it's a single standard identifier
          specifierExportCount++;
        }
      }

      if (node.declaration.declarations) {
        node.declaration.declarations.forEach(function (declaration) {
          captureDeclaration(declaration.id);
        });
      } else {
        // captures 'export function foo() {}' syntax
        specifierExportCount++;
      }

      namedExportNode = node;
    },

    'ExportDefaultDeclaration': function ExportDefaultDeclaration() {
      hasDefaultExport = true;
    },

    'ExportAllDeclaration': function ExportAllDeclaration() {
      hasStarExport = true;
    },

    'Program:exit': function ProgramExit() {
      if (specifierExportCount === 1 && !hasDefaultExport && !hasStarExport) {
        context.report(namedExportNode, 'Prefer default export.');
      }
    }
  };
};
//# sourceMappingURL=data:application/json;base64,[encoded data, 4244 characters]