odin-javascript-exercises/node_modules/eslint-plugin-import/lib/rules/no-deprecated.js

149 lines
15 KiB
JavaScript
Raw Normal View History

2017-12-15 10:56:14 -08:00
'use strict';
var _ExportMap = require('../ExportMap');
var _ExportMap2 = _interopRequireDefault(_ExportMap);
var _declaredScope = require('eslint-module-utils/declaredScope');
var _declaredScope2 = _interopRequireDefault(_declaredScope);
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: {
docs: {}
},
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL25vLWRlcHJlY2F0ZWQuanMiXSwibmFtZXMiOlsibWVzc2FnZSIsImRlcHJlY2F0aW9uIiwiZGVzY3JpcHRpb24iLCJnZXREZXByZWNhdGlvbiIsIm1ldGFkYXRhIiwiZG9jIiwidGFncyIsInNvbWUiLCJ0IiwidGl0bGUiLCJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsImRvY3MiLCJjcmVhdGUiLCJjb250ZXh0IiwiZGVwcmVjYXRlZCIsIk1hcCIsIm5hbWVzcGFjZXMiLCJjaGVja1NwZWNpZmllcnMiLCJub2RlIiwidHlwZSIsInNvdXJjZSIsImltcG9ydHMiLCJnZXQiLCJ2YWx1ZSIsIm1vZHVsZURlcHJlY2F0aW9uIiwicmVwb3J0IiwiZXJyb3JzIiwibGVuZ3RoIiwicmVwb3J0RXJyb3JzIiwic3BlY2lmaWVycyIsImZvckVhY2giLCJpbSIsImltcG9ydGV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