GoScrobble/web/node_modules/eslint-plugin-import/lib/rules/no-named-as-default-member.js

107 lines
13 KiB
JavaScript
Raw Permalink Normal View History

2022-04-25 02:47:15 +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: {
url: (0, _docsUrl2['default'])('no-named-as-default-member') },
schema: [] },
create: function () {function create(context) {
var fileImports = new Map();
var allPropertyLookups = new Map();
function handleImportDefault(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 });
}
function storePropertyLookup(objectName, propName, node) {
var lookups = allPropertyLookups.get(objectName) || [];
lookups.push({ node: node, propName: propName });
allPropertyLookups.set(objectName, lookups);
}
function handlePropLookup(node) {
var objectName = node.object.name;
var propName = node.property.name;
storePropertyLookup(objectName, propName, node);
}
function handleDestructuringAssignment(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;}}}
}
function handleProgramExit() {
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 {
'ImportDefaultSpecifier': handleImportDefault,
'MemberExpression': handlePropLookup,
'VariableDeclarator': handleDestructuringAssignment,
'Program:exit': handleProgramExit };
}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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1uYW1lZC1hcy1kZWZhdWx0LW1lbWJlci5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwiY29udGV4dCIsImZpbGVJbXBvcnRzIiwiTWFwIiwiYWxsUHJvcGVydHlMb29rdXBzIiwiaGFuZGxlSW1wb3J0RG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