odin-js-fundamentals-part-4/node_modules/eslint-plugin-import/lib/rules/no-named-as-default-member.js

96 lines
13 KiB
JavaScript
Raw Normal View History

2024-01-05 19:30:21 +00:00
'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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1uYW1lZC1hcy1kZWZhdWx0LW1lbWJlci5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwiY2F0ZWdvcnkiLCJkZXNjcmlwdGlvbiIsInVybCIsInNjaGVtYSIsImNyZWF0ZS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