Constnium/node_modules/eslint-plugin-import/lib/rules/export.js
2022-06-23 02:27:43 +02:00

228 lines
No EOL
30 KiB
JavaScript

'use strict';var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);
var _arrayIncludes = require('array-includes');var _arrayIncludes2 = _interopRequireDefault(_arrayIncludes);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
/*
Notes on TypeScript namespaces aka TSModuleDeclaration:
There are two forms:
- active namespaces: namespace Foo {} / module Foo {}
- ambient modules; declare module "eslint-plugin-import" {}
active namespaces:
- cannot contain a default export
- cannot contain an export all
- cannot contain a multi name export (export { a, b })
- can have active namespaces nested within them
ambient namespaces:
- can only be defined in .d.ts files
- cannot be nested within active namespaces
- have no other restrictions
*/
var rootProgram = 'root';
var tsTypePrefix = 'type:';
/**
* Detect function overloads like:
* ```ts
* export function foo(a: number);
* export function foo(a: string);
* export function foo(a: number|string) { return a; }
* ```
* @param {Set<Object>} nodes
* @returns {boolean}
*/
function isTypescriptFunctionOverloads(nodes) {
var types = new Set(Array.from(nodes, function (node) {return node.parent.type;}));
return types.has('TSDeclareFunction') && (
types.size === 1 ||
types.size === 2 && types.has('FunctionDeclaration'));
}
/**
* Detect merging Namespaces with Classes, Functions, or Enums like:
* ```ts
* export class Foo { }
* export namespace Foo { }
* ```
* @param {Set<Object>} nodes
* @returns {boolean}
*/
function isTypescriptNamespaceMerging(nodes) {
var types = new Set(Array.from(nodes, function (node) {return node.parent.type;}));
var noNamespaceNodes = Array.from(nodes).filter(function (node) {return node.parent.type !== 'TSModuleDeclaration';});
return types.has('TSModuleDeclaration') && (
types.size === 1
// Merging with functions
|| types.size === 2 && (types.has('FunctionDeclaration') || types.has('TSDeclareFunction')) ||
types.size === 3 && types.has('FunctionDeclaration') && types.has('TSDeclareFunction')
// Merging with classes or enums
|| types.size === 2 && (types.has('ClassDeclaration') || types.has('TSEnumDeclaration')) && noNamespaceNodes.length === 1);
}
/**
* Detect if a typescript namespace node should be reported as multiple export:
* ```ts
* export class Foo { }
* export function Foo();
* export namespace Foo { }
* ```
* @param {Object} node
* @param {Set<Object>} nodes
* @returns {boolean}
*/
function shouldSkipTypescriptNamespace(node, nodes) {
var types = new Set(Array.from(nodes, function (node) {return node.parent.type;}));
return !isTypescriptNamespaceMerging(nodes) &&
node.parent.type === 'TSModuleDeclaration' && (
types.has('TSEnumDeclaration') ||
types.has('ClassDeclaration') ||
types.has('FunctionDeclaration') ||
types.has('TSDeclareFunction'));
}
module.exports = {
meta: {
type: 'problem',
docs: {
url: (0, _docsUrl2['default'])('export') },
schema: [] },
create: function () {function create(context) {
var namespace = new Map([[rootProgram, new Map()]]);
function addNamed(name, node, parent, isType) {
if (!namespace.has(parent)) {
namespace.set(parent, new Map());
}
var named = namespace.get(parent);
var key = isType ? '' + tsTypePrefix + String(name) : name;
var nodes = named.get(key);
if (nodes == null) {
nodes = new Set();
named.set(key, nodes);
}
nodes.add(node);
}
function getParent(node) {
if (node.parent && node.parent.type === 'TSModuleBlock') {
return node.parent.parent;
}
// just in case somehow a non-ts namespace export declaration isn't directly
// parented to the root Program node
return rootProgram;
}
return {
ExportDefaultDeclaration: function () {function ExportDefaultDeclaration(node) {
addNamed('default', node, getParent(node));
}return ExportDefaultDeclaration;}(),
ExportSpecifier: function () {function ExportSpecifier(node) {
addNamed(
node.exported.name || node.exported.value,
node.exported,
getParent(node.parent));
}return ExportSpecifier;}(),
ExportNamedDeclaration: function () {function ExportNamedDeclaration(node) {
if (node.declaration == null) return;
var parent = getParent(node);
// support for old TypeScript versions
var isTypeVariableDecl = node.declaration.kind === 'type';
if (node.declaration.id != null) {
if ((0, _arrayIncludes2['default'])([
'TSTypeAliasDeclaration',
'TSInterfaceDeclaration'],
node.declaration.type)) {
addNamed(node.declaration.id.name, node.declaration.id, parent, true);
} else {
addNamed(node.declaration.id.name, node.declaration.id, parent, isTypeVariableDecl);
}
}
if (node.declaration.declarations != null) {var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try {
for (var _iterator = node.declaration.declarations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var declaration = _step.value;
(0, _ExportMap.recursivePatternCapture)(declaration.id, function (v) {return (
addNamed(v.name, v, parent, isTypeVariableDecl));});
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}}
}
}return ExportNamedDeclaration;}(),
ExportAllDeclaration: function () {function ExportAllDeclaration(node) {
if (node.source == null) return; // not sure if this is ever true
// `export * as X from 'path'` does not conflict
if (node.exported && node.exported.name) return;
var remoteExports = _ExportMap2['default'].get(node.source.value, context);
if (remoteExports == null) return;
if (remoteExports.errors.length) {
remoteExports.reportErrors(context, node);
return;
}
var parent = getParent(node);
var any = false;
remoteExports.forEach(function (v, name) {
if (name !== 'default') {
any = true; // poor man's filter
addNamed(name, node, parent);
}
});
if (!any) {
context.report(
node.source, 'No named exports found in module \'' + String(
node.source.value) + '\'.');
}
}return ExportAllDeclaration;}(),
'Program:exit': function () {function ProgramExit() {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try {
for (var _iterator2 = namespace[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var _ref = _step2.value;var _ref2 = _slicedToArray(_ref, 2);var named = _ref2[1];var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try {
for (var _iterator3 = named[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var _ref3 = _step3.value;var _ref4 = _slicedToArray(_ref3, 2);var name = _ref4[0];var nodes = _ref4[1];
if (nodes.size <= 1) continue;
if (isTypescriptFunctionOverloads(nodes) || isTypescriptNamespaceMerging(nodes)) continue;var _iteratorNormalCompletion4 = true;var _didIteratorError4 = false;var _iteratorError4 = undefined;try {
for (var _iterator4 = nodes[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {var node = _step4.value;
if (shouldSkipTypescriptNamespace(node, nodes)) continue;
if (name === 'default') {
context.report(node, 'Multiple default exports.');
} else {
context.report(
node, 'Multiple exports of name \'' + String(
name.replace(tsTypePrefix, '')) + '\'.');
}
}} catch (err) {_didIteratorError4 = true;_iteratorError4 = err;} finally {try {if (!_iteratorNormalCompletion4 && _iterator4['return']) {_iterator4['return']();}} finally {if (_didIteratorError4) {throw _iteratorError4;}}}
}} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3['return']) {_iterator3['return']();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}}
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}}
}return ProgramExit;}() };
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9leHBvcnQuanMiXSwibmFtZXMiOlsicm9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dGVyXG4gICAgICAgICAgICBhZGROYW1lZChuYW1lLCBub2RlLCBwYXJlbnQpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSk7XG5cbiAgICAgICAgaWYgKCFhbnkpIHtcbiAgICAgICAgICBjb250ZXh0LnJlcG9ydChcbiAgICAgICAgICAgIG5vZGUuc291cmNlLFxuICAgICAgICAgICAgYE5vIG5hbWVkIGV4cG9ydHMgZm91bmQgaW4gbW9kdWxlICcke25vZGUuc291cmNlLnZhbHVlfScuYCxcbiAgICAgICAgICApO1xuICAgICAgICB9XG4gICAgICB9LFxuXG4gICAgICAnUHJvZ3JhbTpleGl0JzogZnVuY3Rpb24gKCkge1xuICAgICAgICBmb3IgKGNvbnN0IFssIG5hbWVkXSBvZiBuYW1lc3BhY2UpIHtcbiAgICAgICAgICBmb3IgKGNvbnN0IFtuYW1lLCBub2Rlc10gb2YgbmFtZWQpIHtcbiAgICAgICAgICAgIGlmIChub2Rlcy5zaXplIDw9IDEpIGNvbnRpbnVlO1xuXG4gICAgICAgICAgICBpZiAoaXNUeXBlc2NyaXB0RnVuY3Rpb25PdmVybG9hZHMobm9kZXMpIHx8IGlzVHlwZXNjcmlwdE5hbWVzcGFjZU1lcmdpbmcobm9kZXMpKSBjb250aW51ZTtcblxuICAgICAgICAgICAgZm9yIChjb25zdCBub2RlIG9mIG5vZGVzKSB7XG4gICAgICAgICAgICAgIGlmIChzaG91bGRTa2lwVHlwZXNjcmlwdE5hbWVzcGFjZShub2RlLCBub2RlcykpIGNvbnRpbnVlO1xuXG4gICAgICAgICAgICAgIGlmIChuYW1lID09PSAnZGVmYXVsdCcpIHtcbiAgICAgICAgICAgICAgICBjb250ZXh0LnJlcG9ydChub2RlLCAnTXVsdGlwbGUgZGVmYXVsdCBleHBvcnRzLicpO1xuICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGNvbnRleHQucmVwb3J0KFxuICAgICAgICAgICAgICAgICAgbm9kZSxcbiAgICAgICAgICAgICAgICAgIGBNdWx0aXBsZSBleHBvcnRzIG9mIG5hbWUgJyR7bmFtZS5yZXBsYWNlKHRzVHlwZVByZWZpeCwgJycpfScuYCxcbiAgICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9LFxuICAgIH07XG4gIH0sXG59O1xuIl19