bigint-crypto-utils/node_modules/eslint-plugin-import/lib/rules/no-deprecated.js

156 lines
15 KiB
JavaScript
Raw Normal View History

'use strict';
var _declaredScope = require('eslint-module-utils/declaredScope');
var _declaredScope2 = _interopRequireDefault(_declaredScope);
var _ExportMap = require('../ExportMap');
var _ExportMap2 = _interopRequireDefault(_ExportMap);
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function message(deprecation) {
return 'Deprecated' + (deprecation.description ? ': ' + deprecation.description : '.');
}
function getDeprecation(metadata) {
if (!metadata || !metadata.doc) return;
let deprecation;
if (metadata.doc.tags.some(t => t.title === 'deprecated' && (deprecation = t))) {
return deprecation;
}
}
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: (0, _docsUrl2.default)('no-deprecated')
}
},
create: function (context) {
const deprecated = new Map(),
namespaces = new Map();
function checkSpecifiers(node) {
if (node.type !== 'ImportDeclaration') return;
if (node.source == null) return; // local export, ignore
const imports = _ExportMap2.default.get(node.source.value, context);
if (imports == null) return;
let moduleDeprecation;
if (imports.doc && imports.doc.tags.some(t => t.title === 'deprecated' && (moduleDeprecation = t))) {
context.report({ node, message: message(moduleDeprecation) });
}
if (imports.errors.length) {
imports.reportErrors(context, node);
return;
}
node.specifiers.forEach(function (im) {
let imported, local;
switch (im.type) {
case 'ImportNamespaceSpecifier':
{
if (!imports.size) return;
namespaces.set(im.local.name, imports);
return;
}
case 'ImportDefaultSpecifier':
imported = 'default';
local = im.local.name;
break;
case 'ImportSpecifier':
imported = im.imported.name;
local = im.local.name;
break;
default:
return; // can't handle this one
}
// unknown thing can't be deprecated
const exported = imports.get(imported);
if (exported == null) return;
// capture import of deep namespace
if (exported.namespace) namespaces.set(local, exported.namespace);
const deprecation = getDeprecation(imports.get(imported));
if (!deprecation) return;
context.report({ node: im, message: message(deprecation) });
deprecated.set(local, deprecation);
});
}
return {
'Program': (_ref) => {
let body = _ref.body;
return body.forEach(checkSpecifiers);
},
'Identifier': function (node) {
if (node.parent.type === 'MemberExpression' && node.parent.property === node) {
return; // handled by MemberExpression
}
// ignore specifier identifiers
if (node.parent.type.slice(0, 6) === 'Import') return;
if (!deprecated.has(node.name)) return;
if ((0, _declaredScope2.default)(context, node.name) !== 'module') return;
context.report({
node,
message: message(deprecated.get(node.name))
});
},
'MemberExpression': function (dereference) {
if (dereference.object.type !== 'Identifier') return;
if (!namespaces.has(dereference.object.name)) return;
if ((0, _declaredScope2.default)(context, dereference.object.name) !== 'module') return;
// go deep
var namespace = namespaces.get(dereference.object.name);
var namepath = [dereference.object.name];
// while property is namespace and parent is member expression, keep validating
while (namespace instanceof _ExportMap2.default && dereference.type === 'MemberExpression') {
// ignore computed parts for now
if (dereference.computed) return;
const metadata = namespace.get(dereference.property.name);
if (!metadata) break;
const deprecation = getDeprecation(metadata);
if (deprecation) {
context.report({ node: dereference.property, message: message(deprecation) });
}
// stash and pop
namepath.push(dereference.property.name);
namespace = metadata.namespace;
dereference = dereference.parent;
}
}
};
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZXByZWNhdGVkLmpzIl0sIm5hbWVzIjpbIm1lc3NhZ2UiLCJkZXByZWNhdGlvbiIsImRlc2NyaXB0aW9uIiwiZ2V0RGVwcmVjYXRpb24iLCJtZXRhZGF0YSIsImRvYyIsInRhZ3MiLCJzb21lIiwidCIsInRpdGxlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsImNyZWF0ZSIsImNvbnRleHQiLCJkZXByZWNhdGVkIiwiTWFwIiwibmFtZXNwYWNlcyIsImNoZWNrU3BlY2lmaWVycyIsIm5vZGUiLCJzb3VyY2UiLCJpbXBvcnRzIiwiRXhwb3J0cyIsImdldCIsInZhbHVlIiwibW9kdWxlRGVwcmVjYXRpb24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