PromoCursed/node_modules/eslint-plugin-import/lib/rules/no-named-as-default-member.js
2024-08-20 23:25:37 +04:00

96 lines
13 KiB
JavaScript

'use strict';
var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
var _importDeclaration = require('../importDeclaration');var _importDeclaration2 = _interopRequireDefault(_importDeclaration);
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'suggestion',
docs: {
category: 'Helpful warnings',
description: 'Forbid use of exported name as property of default export.',
url: (0, _docsUrl2['default'])('no-named-as-default-member') },
schema: [] },
create: function () {function create(context) {
var fileImports = new Map();
var allPropertyLookups = new Map();
function storePropertyLookup(objectName, propName, node) {
var lookups = allPropertyLookups.get(objectName) || [];
lookups.push({ node: node, propName: propName });
allPropertyLookups.set(objectName, lookups);
}
return {
ImportDefaultSpecifier: function () {function ImportDefaultSpecifier(node) {
var declaration = (0, _importDeclaration2['default'])(context);
var exportMap = _ExportMap2['default'].get(declaration.source.value, context);
if (exportMap == null) {return;}
if (exportMap.errors.length) {
exportMap.reportErrors(context, declaration);
return;
}
fileImports.set(node.local.name, {
exportMap: exportMap,
sourcePath: declaration.source.value });
}return ImportDefaultSpecifier;}(),
MemberExpression: function () {function MemberExpression(node) {
var objectName = node.object.name;
var propName = node.property.name;
storePropertyLookup(objectName, propName, node);
}return MemberExpression;}(),
VariableDeclarator: function () {function VariableDeclarator(node) {
var isDestructure = node.id.type === 'ObjectPattern' &&
node.init != null &&
node.init.type === 'Identifier';
if (!isDestructure) {return;}
var objectName = node.init.name;var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try {
for (var _iterator = node.id.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var _ref = _step.value;var key = _ref.key;
if (key == null) {continue;} // true for rest properties
storePropertyLookup(objectName, key.name, key);
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}}
}return VariableDeclarator;}(),
'Program:exit': function () {function ProgramExit() {
allPropertyLookups.forEach(function (lookups, objectName) {
var fileImport = fileImports.get(objectName);
if (fileImport == null) {return;}var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try {
for (var _iterator2 = lookups[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var _ref2 = _step2.value;var propName = _ref2.propName,node = _ref2.node;
// the default import can have a "default" property
if (propName === 'default') {continue;}
if (!fileImport.exportMap.namespace.has(propName)) {continue;}
context.report({
node: node,
message: 'Caution: `' + String(objectName) + '` also has a named export `' + String(propName) + '`. Check if you meant to write `import {' + String(propName) + '} from \'' + String(fileImport.sourcePath) + '\'` instead.' });
}} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}}
});
}return ProgramExit;}() };
}return create;}() }; /**
* @fileoverview Rule to warn about potentially confused use of name exports
* @author Desmond Brand
* @copyright 2016 Desmond Brand. All rights reserved.
* See LICENSE in root directory for full license.
*/
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1uYW1lZC1hcy1kZWZhdWx0LW1lbWJlci5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwiY2F0ZWdvcnkiLCJkZXNjcmlwdGlvbiIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJma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