'use strict'; var _ExportMap = require('../ExportMap'); var _ExportMap2 = _interopRequireDefault(_ExportMap); var _importDeclaration = require('../importDeclaration'); var _importDeclaration2 = _interopRequireDefault(_importDeclaration); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ /** * @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. */ module.exports = { meta: { docs: {} }, create: function (context) { const fileImports = new Map(); const allPropertyLookups = new Map(); function handleImportDefault(node) { const declaration = (0, _importDeclaration2.default)(context); const 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, sourcePath: declaration.source.value }); } function storePropertyLookup(objectName, propName, node) { const lookups = allPropertyLookups.get(objectName) || []; lookups.push({ node, propName }); allPropertyLookups.set(objectName, lookups); } function handlePropLookup(node) { const objectName = node.object.name; const propName = node.property.name; storePropertyLookup(objectName, propName, node); } function handleDestructuringAssignment(node) { const isDestructure = node.id.type === 'ObjectPattern' && node.init != null && node.init.type === 'Identifier'; if (!isDestructure) return; const objectName = node.init.name; for (const _ref of node.id.properties) { const key = _ref.key; if (key == null) continue; // true for rest properties storePropertyLookup(objectName, key.name, key); } } function handleProgramExit() { allPropertyLookups.forEach((lookups, objectName) => { const fileImport = fileImports.get(objectName); if (fileImport == null) return; for (const _ref2 of lookups) { const propName = _ref2.propName; const 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, message: `Caution: \`${objectName}\` also has a named export ` + `\`${propName}\`. Check if you meant to write ` + `\`import {${propName}} from '${fileImport.sourcePath}'\` ` + 'instead.' }); } }); } return { 'ImportDefaultSpecifier': handleImportDefault, 'MemberExpression': handlePropLookup, 'VariableDeclarator': handleDestructuringAssignment, 'Program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KGxvb2t1cHMsIG9iamVjdE5hbWUpID0+IHtcbiAgICAgICAgY29uc3QgZmlsZUltcG9ydCA9IGZpbGVJbXBvcnRzLmdldChvYmplY3ROYW1lKVxuICAgICAgICBpZiAoZmlsZUltcG9ydCA9PSBudWxsKSByZXR1cm5cblxuICAgICAgICBmb3IgKGNvbnN0IHtwcm9wTmFtZSwgbm9kZX0gb2YgbG9va3Vwcykge1xuICAgICAgICAgIC8vIHRoZSBkZWZhdWx0IGltcG9ydCBjYW4gaGF2ZSBhIFwiZGVmYXVsdFwiIHByb3BlcnR5XG4gICAgICAgICAgaWYgKHByb3BOYW1lID09PSAnZGVmYXVsdCcpIGNvbnRpbnVlXG4gICAgICAgICAgaWYgKCFmaWxlSW1wb3J0LmV4cG9ydE1hcC5uYW1lc3BhY2UuaGFzKHByb3BOYW1lKSkgY29udGludWVcblxuICAgICAgICAgIGNvbnRleHQucmVwb3J0KHtcbiAgICAgICAgICAgIG5vZGUsXG4gICAgICAgICAgICBtZXNzYWdlOiAoXG4gICAgICAgICAgICAgIGBDYXV0aW9uOiBcXGAke29iamVjdE5hbWV9XFxgIGFsc28gaGFzIGEgbmFtZWQgZXhwb3J0IGAgK1xuICAgICAgICAgICAgICBgXFxgJHtwcm9wTmFtZX1cXGAuIENoZWNrIGlmIHlvdSBtZWFudCB0byB3cml0ZSBgICtcbiAgICAgICAgICAgICAgYFxcYGltcG9ydCB7JHtwcm9wTmFtZX19IGZyb20gJyR7ZmlsZUltcG9ydC5zb3VyY2VQYXRofSdcXGAgYCArXG4gICAgICAgICAgICAgICdpbnN0ZWFkLidcbiAgICAgICAgICAgICksXG4gICAgICAgICAgfSlcbiAgICAgICAgfVxuICAgICAgfSlcbiAgICB9XG5cbiAgICByZXR1cm4ge1xuICAgICAgJ0ltcG9ydERlZmF1bHRTcGVjaWZpZXInOiBoYW5kbGVJbXBvcnREZWZhdWx0LFxuICAgICAgJ01lbWJlckV4cHJlc3Npb24nOiBoYW5kbGVQcm9wTG9va3V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