You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
13 KiB
107 lines
13 KiB
'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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1uYW1lZC1hcy1kZWZhdWx0LW1lbWJlci5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwiY29udGV4dCIsImZpbGVJbXBvcnRzIiwiTWFwIiwiYWxsUHJvcGVydHlMb29rdXBzIiwiaGFuZGxlSW1wb3J0RGVmYXVsdCIsIm5vZGUiLCJkZWNsYXJhdGlvbiIsImV4cG9ydE1hcCIsIkV4cG9ydHMiLCJnZXQiLCJzb3VyY2UiLCJ2YWx1ZSIsImVycm9ycyIsImxlbmd0aCIsInJlcG9ydEVycm9ycyIsInNldCIsImxvY2FsIiwibmFtZSIsInNvdXJjZVBhdGgiLCJzdG9yZVByb3BlcnR5TG9va3VwIiwib2JqZWN0TmFtZSIsInByb3BOYW1lIiwibG9va3VwcyIsInB1c2giLCJoYW5kbGVQcm9wTG9va3VwIiwib2JqZWN0IiwicHJvcGVydHkiLCJoYW5kbGVEZXN0cnVjdHVyaW5nQXNzaWdubWVudCIsImlzRGVzdHJ1Y3R1cmUiLCJpZCIsImluaXQiLCJwcm9wZXJ0aWVzIiwia2V5IiwiaGFuZGxlUHJvZ3JhbUV4aXQiLCJmb3JFYWNoIiwiZmlsZUltcG9ydCIsIm5hbWVzcGFjZSIsImhhcyIsInJlcG9ydCIsIm1lc3NhZ2UiXSwibWFwcGluZ3MiOiI7Ozs7OztBQU1BLHlDO0FBQ0EseUQ7QUFDQSxxQzs7QUFFQTtBQUNBO0FBQ0E7O0FBRUFBLE9BQU9DLE9BQVAsR0FBaUI7QUFDZkMsUUFBTTtBQUNKQyxVQUFNLFlBREY7QUFFSkMsVUFBTTtBQUNKQyxXQUFLLDBC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