'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,[encoded data, 8056 characters]