GoScrobble/web/node_modules/eslint-plugin-import/lib/rules/no-deprecated.js

139 lines
16 KiB
JavaScript
Raw Permalink Normal View History

2022-04-25 02:47:15 +00:00
'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;
return metadata.doc.tags.find(function (t) {return t.title === 'deprecated';});
}
module.exports = {
meta: {
type: 'suggestion',
docs: {
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZXByZWNhdGVkLmpzIl0sIm5hbWVzIjpbIm1lc3NhZ2UiLCJkZXByZWNhdGlvbiIsImRlc2NyaXB0aW9uIiwiZ2V0RGVwcmVjYXRpb24iLCJtZXRhZGF0YSIsImRvYyIsInRhZ3MiLCJmaW5kIiwidCIsInRpdGxlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJkZXByZWNhdGVkIiwiTWFwIiwibmFtZXNwYWNlcyIsImNoZWNrU3BlY2lmaWVycyIsIm5vZGU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