%PDF- %PDF-
Direktori : /var/www/html/node_modules/eslint-plugin-import/lib/rules/ |
Current File : /var/www/html/node_modules/eslint-plugin-import/lib/rules/prefer-default-export.js |
'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;}() }; }return create;}() }; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9wcmVmZXItZGVmYXVsdC1leHBvcnQuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJzcGVjaWZpZXJFeHBvcnRDb3VudCIsImhhc0RlZmF1bHRFeHBvcnQiLCJoYXNTdGFyRXhwb3J0IiwiaGFzVHlwZUV4cG9ydCIsIm5hbWVkRXhwb3J0Tm9kZSIsImNhcHR1cmVEZWNsYXJhdGlvbiIsImlkZW50aWZpZXJPclBhdHRlcm4iLCJwcm9wZXJ0aWVzIiwiZm9yRWFjaCIsInByb3BlcnR5IiwidmFsdWUiLCJlbGVtZW50cyIsIm5vZGUiLCJleHBvcnRlZCIsIm5hbWUiLCJkZWNsYXJhdGlvbiIsImRlY2xhcmF0aW9ucyIsImlkIiwicmVwb3J0Il0sIm1hcHBpbmdzIjoiQUFBQTs7QUFFQSxxQzs7QUFFQUEsT0FBT0MsT0FBUCxHQUFpQjtBQUNmQyxRQUFNO0FBQ0pDLFVBQU0sWUFERjtBQUVKQyxVQUFNO0FBQ0pDLFdBQUssMEJBQVEsdUJBQVIsQ0FERCxFQUZGOztBQUtKQyxZQUFRLEVBTEosRUFEUzs7O0FBU2ZDLFFBVGUsK0JBU1JDLE9BVFEsRUFTQztBQUNkLFVBQUlDLHVCQUF1QixDQUEzQjtBQUNBLFVBQUlDLG1CQUFtQixLQUF2QjtBQUNBLFVBQUlDLGdCQUFnQixLQUFwQjtBQUNBLFVBQUlDLGdCQUFnQixLQUFwQjtBQUNBLFVBQUlDLGtCQUFr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