'use strict'; var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };} module.exports = { meta: { type: 'suggestion', docs: { url: (0, _docsUrl2['default'])('prefer-default-export') }, schema: [] }, create: function () {function create(context) { var specifierExportCount = 0; var hasDefaultExport = false; var hasStarExport = false; var hasTypeExport = false; var namedExportNode = null; function captureDeclaration(identifierOrPattern) { if (identifierOrPattern && identifierOrPattern.type === 'ObjectPattern') { // recursively capture identifierOrPattern.properties. forEach(function (property) { captureDeclaration(property.value); }); } else if (identifierOrPattern && identifierOrPattern.type === 'ArrayPattern') { identifierOrPattern.elements. forEach(captureDeclaration); } else { // assume it's a single standard identifier specifierExportCount++; } } return { 'ExportDefaultSpecifier': function () {function ExportDefaultSpecifier() { hasDefaultExport = true; }return ExportDefaultSpecifier;}(), 'ExportSpecifier': function () {function ExportSpecifier(node) { if (node.exported.name === 'default') { hasDefaultExport = true; } else { specifierExportCount++; namedExportNode = node; } }return ExportSpecifier;}(), 'ExportNamedDeclaration': function () {function ExportNamedDeclaration(node) { // if there are specifiers, node.declaration should be null if (!node.declaration) return;var type = node.declaration.type; if ( type === 'TSTypeAliasDeclaration' || type === 'TypeAlias' || type === 'TSInterfaceDeclaration' || type === 'InterfaceDeclaration') { specifierExportCount++; hasTypeExport = true; return; } if (node.declaration.declarations) { node.declaration.declarations.forEach(function (declaration) { captureDeclaration(declaration.id); }); } else { // captures 'export function foo() {}' syntax specifierExportCount++; } namedExportNode = node; }return ExportNamedDeclaration;}(), 'ExportDefaultDeclaration': function () {function ExportDefaultDeclaration() { hasDefaultExport = true; }return ExportDefaultDeclaration;}(), 'ExportAllDeclaration': function () {function ExportAllDeclaration() { hasStarExport = true; }return ExportAllDeclaration;}(), 'Program:exit': function () {function ProgramExit() { if (specifierExportCount === 1 && !hasDefaultExport && !hasStarExport && !hasTypeExport) { context.report(namedExportNode, 'Prefer default export.'); } }return ProgramExit;}() };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