katoikia-app/web-ui/web-react/node_modules/eslint-plugin-import/lib/rules/no-namespace.js

147 lines
19 KiB
JavaScript

'use strict';
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } /**
* @fileoverview Rule to disallow namespace import
* @author Radek Benkel
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: (0, _docsUrl2.default)('no-namespace')
},
fixable: 'code',
schema: []
},
create: function (context) {
return {
'ImportNamespaceSpecifier': function (node) {
const scopeVariables = context.getScope().variables;
const namespaceVariable = scopeVariables.find(variable => variable.defs[0].node === node);
const namespaceReferences = namespaceVariable.references;
const namespaceIdentifiers = namespaceReferences.map(reference => reference.identifier);
const canFix = namespaceIdentifiers.length > 0 && !usesNamespaceAsObject(namespaceIdentifiers);
context.report({
node,
message: `Unexpected namespace import.`,
fix: canFix && (fixer => {
const scopeManager = context.getSourceCode().scopeManager;
const fixes = [];
// Pass 1: Collect variable names that are already in scope for each reference we want
// to transform, so that we can be sure that we choose non-conflicting import names
const importNameConflicts = {};
namespaceIdentifiers.forEach(identifier => {
const parent = identifier.parent;
if (parent && parent.type === 'MemberExpression') {
const importName = getMemberPropertyName(parent);
const localConflicts = getVariableNamesInScope(scopeManager, parent);
if (!importNameConflicts[importName]) {
importNameConflicts[importName] = localConflicts;
} else {
localConflicts.forEach(c => importNameConflicts[importName].add(c));
}
}
});
// Choose new names for each import
const importNames = Object.keys(importNameConflicts);
const importLocalNames = generateLocalNames(importNames, importNameConflicts, namespaceVariable.name);
// Replace the ImportNamespaceSpecifier with a list of ImportSpecifiers
const namedImportSpecifiers = importNames.map(importName => importName === importLocalNames[importName] ? importName : `${importName} as ${importLocalNames[importName]}`);
fixes.push(fixer.replaceText(node, `{ ${namedImportSpecifiers.join(', ')} }`));
// Pass 2: Replace references to the namespace with references to the named imports
namespaceIdentifiers.forEach(identifier => {
const parent = identifier.parent;
if (parent && parent.type === 'MemberExpression') {
const importName = getMemberPropertyName(parent);
fixes.push(fixer.replaceText(parent, importLocalNames[importName]));
}
});
return fixes;
})
});
}
};
}
/**
* @param {Identifier[]} namespaceIdentifiers
* @returns {boolean} `true` if the namespace variable is more than just a glorified constant
*/
};function usesNamespaceAsObject(namespaceIdentifiers) {
return !namespaceIdentifiers.every(identifier => {
const parent = identifier.parent;
// `namespace.x` or `namespace['x']`
return parent && parent.type === 'MemberExpression' && (parent.property.type === 'Identifier' || parent.property.type === 'Literal');
});
}
/**
* @param {MemberExpression} memberExpression
* @returns {string} the name of the member in the object expression, e.g. the `x` in `namespace.x`
*/
function getMemberPropertyName(memberExpression) {
return memberExpression.property.type === 'Identifier' ? memberExpression.property.name : memberExpression.property.value;
}
/**
* @param {ScopeManager} scopeManager
* @param {ASTNode} node
* @return {Set<string>}
*/
function getVariableNamesInScope(scopeManager, node) {
let currentNode = node;
let scope = scopeManager.acquire(currentNode);
while (scope == null) {
currentNode = currentNode.parent;
scope = scopeManager.acquire(currentNode, true);
}
return new Set([].concat(_toConsumableArray(scope.variables.map(variable => variable.name)), _toConsumableArray(scope.upper.variables.map(variable => variable.name))));
}
/**
*
* @param {*} names
* @param {*} nameConflicts
* @param {*} namespaceName
*/
function generateLocalNames(names, nameConflicts, namespaceName) {
const localNames = {};
names.forEach(name => {
let localName;
if (!nameConflicts[name].has(name)) {
localName = name;
} else if (!nameConflicts[name].has(`${namespaceName}_${name}`)) {
localName = `${namespaceName}_${name}`;
} else {
for (let i = 1; i < Infinity; i++) {
if (!nameConflicts[name].has(`${namespaceName}_${name}_${i}`)) {
localName = `${namespaceName}_${name}_${i}`;
break;
}
}
}
localNames[name] = localName;
});
return localNames;
}
//# sourceMappingURL=data:application/json;charset=utf-8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YWxDb25mbGljdHMuZm9yRWFjaCgoYykgPT4gaW1wb3J0TmFtZUNvbmZsaWN0c1tpbXBvcnROYW1lXS5hZGQoYykpXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KVxuXG4gICAgICAgICAgICAvLyBDaG9vc2UgbmV3IG5hbWVzIGZvciBlYWNoIGltcG9ydFxuICAgICAgICAgICAgY29uc3QgaW1wb3J0TmFtZXMgPSBPYmplY3Qua2V5cyhpbXBvcnROYW1lQ29uZmxpY3RzKVxuICAgICAgICAgICAgY29uc3QgaW1wb3J0TG9jYWxOYW1lcyA9IGdlbmVyYXRlTG9jYWxOYW1lcyhcbiAgICAgICAgICAgICAgaW1wb3J0TmFtZXMsXG4gICAgICAgICAgICAgIGltcG9ydE5hbWVDb25mbGljdHMsXG4gICAgICAgICAgICAgIG5hbWVzcGFjZVZhcmlhYmxlLm5hbWVcbiAgICAgICAgICAgIClcblxuICAgICAgICAgICAgLy8gUmVwbGFjZSB0aGUgSW1wb3J0TmFtZXNwYWNlU3BlY2lmaWVyIHdpdGggYSBsaXN0IG9mIEltcG9ydFNwZWNpZmllcnNcbiAgICAgICAgICAgIGNvbnN0IG5hbWVkSW1wb3J0U3BlY2lmaWVycyA9IGltcG9ydE5hbWVzLm1hcCgoaW1wb3J0TmFtZSkgPT5cbiAgICAgICAgICAgICAgaW1wb3J0TmFtZSA9PT0gaW1wb3J0TG9jYWxOYW1lc1tpbXBvcnROYW1lXVxuICAgICAgICAgICAgICAgID8gaW1wb3J0TmFtZVxuICAgICAgICAgICAgICAgIDogYCR7aW1wb3J0TmFtZX0gYXMgJHtpbXBvcnRMb2NhbE5hbWVzW2ltcG9ydE5hbWVdfWBcbiAgICAgICAgICAgIClcbiAgICAgICAgICAgIGZpeGVzLnB1c2goZml4ZXIucmVwbGFjZVRleHQobm9kZSwgYHsgJHtuYW1lZEltcG9ydFNwZWNpZmllcnMuam9pbignLCAnKX0gfWApKVxuXG4gICAg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