PromoCursed/node_modules/eslint-plugin-import/lib/rules/no-deprecated.js
2024-08-20 23:25:37 +04:00

138 lines
16 KiB
JavaScript

'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 ? ': ' + String(deprecation.description) : '.');
}
function getDeprecation(metadata) {
if (!metadata || !metadata.doc) {return;}
return metadata.doc.tags.find(function (t) {return t.title === 'deprecated';});
}
module.exports = {
meta: {
type: 'suggestion',
docs: {
category: 'Helpful warnings',
description: 'Forbid imported names marked with `@deprecated` documentation tag.',
url: (0, _docsUrl2['default'])('no-deprecated') },
schema: [] },
create: function () {function create(context) {
var deprecated = new Map();
var namespaces = new Map();
function checkSpecifiers(node) {
if (node.type !== 'ImportDeclaration') {return;}
if (node.source == null) {return;} // local export, ignore
var imports = _ExportMap2['default'].get(node.source.value, context);
if (imports == null) {return;}
var moduleDeprecation = imports.doc && imports.doc.tags.find(function (t) {return t.title === 'deprecated';});
if (moduleDeprecation) {
context.report({ node: node, message: message(moduleDeprecation) });
}
if (imports.errors.length) {
imports.reportErrors(context, node);
return;
}
node.specifiers.forEach(function (im) {
var imported = void 0;var local = void 0;
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
var exported = imports.get(imported);
if (exported == null) {return;}
// capture import of deep namespace
if (exported.namespace) {namespaces.set(local, exported.namespace);}
var deprecation = getDeprecation(imports.get(imported));
if (!deprecation) {return;}
context.report({ node: im, message: message(deprecation) });
deprecated.set(local, deprecation);
});
}
return {
Program: function () {function Program(_ref) {var body = _ref.body;return body.forEach(checkSpecifiers);}return Program;}(),
Identifier: function () {function Identifier(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: node,
message: message(deprecated.get(node.name)) });
}return Identifier;}(),
MemberExpression: function () {function MemberExpression(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;}
var metadata = namespace.get(dereference.property.name);
if (!metadata) {break;}
var 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;
}
}return MemberExpression;}() };
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZXByZWNhdGVkLmpzIl0sIm5hbWVzIjpbIm1lc3NhZ2UiLCJkZXByZWNhdGlvbiIsImRlc2NyaXB0aW9uIiwiZ2V0RGVwcmVjYXRpb24iLCJtZXRhZGF0YSIsImRvYyIsInRhZ3MiLCJmaW5kIiwidCIsInRpdGxlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImNhdGVnb3J5IiwidXJsIiwic2NoZW1hIiwiY3JlYXRlIiwiY29udGV4dC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