internet-programming/lab3/node_modules/eslint-plugin-import/lib/rules/namespace.js

218 lines
26 KiB
JavaScript

'use strict';var _declaredScope = require('eslint-module-utils/declaredScope');var _declaredScope2 = _interopRequireDefault(_declaredScope);
var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
var _importDeclaration = require('../importDeclaration');var _importDeclaration2 = _interopRequireDefault(_importDeclaration);
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
function processBodyStatement(context, namespaces, declaration) {
if (declaration.type !== 'ImportDeclaration') {return;}
if (declaration.specifiers.length === 0) {return;}
var imports = _ExportMap2['default'].get(declaration.source.value, context);
if (imports == null) {return null;}
if (imports.errors.length > 0) {
imports.reportErrors(context, declaration);
return;
}
declaration.specifiers.forEach(function (specifier) {
switch (specifier.type) {
case 'ImportNamespaceSpecifier':
if (!imports.size) {
context.report(
specifier, 'No exported names found in module \'' + String(
declaration.source.value) + '\'.');
}
namespaces.set(specifier.local.name, imports);
break;
case 'ImportDefaultSpecifier':
case 'ImportSpecifier':{
var meta = imports.get(
// default to 'default' for default https://i.imgur.com/nj6qAWy.jpg
specifier.imported ? specifier.imported.name || specifier.imported.value : 'default');
if (!meta || !meta.namespace) {break;}
namespaces.set(specifier.local.name, meta.namespace);
break;
}
default:}
});
}
module.exports = {
meta: {
type: 'problem',
docs: {
category: 'Static analysis',
description: 'Ensure imported namespaces contain dereferenced properties as they are dereferenced.',
url: (0, _docsUrl2['default'])('namespace') },
schema: [
{
type: 'object',
properties: {
allowComputed: {
description: 'If `false`, will report computed (and thus, un-lintable) references to namespace members.',
type: 'boolean',
'default': false } },
additionalProperties: false }] },
create: function () {function namespaceRule(context) {
// read options
var _ref =
context.options[0] || {},_ref$allowComputed = _ref.allowComputed,allowComputed = _ref$allowComputed === undefined ? false : _ref$allowComputed;
var namespaces = new Map();
function makeMessage(last, namepath) {
return '\'' + String(last.name) + '\' not found in ' + (namepath.length > 1 ? 'deeply ' : '') + 'imported namespace \'' + String(namepath.join('.')) + '\'.';
}
return {
// pick up all imports at body entry time, to properly respect hoisting
Program: function () {function Program(_ref2) {var body = _ref2.body;
body.forEach(function (x) {processBodyStatement(context, namespaces, x);});
}return Program;}(),
// same as above, but does not add names to local map
ExportNamespaceSpecifier: function () {function ExportNamespaceSpecifier(namespace) {
var declaration = (0, _importDeclaration2['default'])(context);
var imports = _ExportMap2['default'].get(declaration.source.value, context);
if (imports == null) {return null;}
if (imports.errors.length) {
imports.reportErrors(context, declaration);
return;
}
if (!imports.size) {
context.report(
namespace, 'No exported names found in module \'' + String(
declaration.source.value) + '\'.');
}
}return ExportNamespaceSpecifier;}(),
// todo: check for possible redefinition
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;}
if (dereference.parent.type === 'AssignmentExpression' && dereference.parent.left === dereference) {
context.report(
dereference.parent, 'Assignment to member of namespace \'' + String(
dereference.object.name) + '\'.');
}
// 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') {
if (dereference.computed) {
if (!allowComputed) {
context.report(
dereference.property, 'Unable to validate computed reference to imported namespace \'' + String(
dereference.object.name) + '\'.');
}
return;
}
if (!namespace.has(dereference.property.name)) {
context.report(
dereference.property,
makeMessage(dereference.property, namepath));
break;
}
var exported = namespace.get(dereference.property.name);
if (exported == null) {return;}
// stash and pop
namepath.push(dereference.property.name);
namespace = exported.namespace;
dereference = dereference.parent;
}
}return MemberExpression;}(),
VariableDeclarator: function () {function VariableDeclarator(_ref3) {var id = _ref3.id,init = _ref3.init;
if (init == null) {return;}
if (init.type !== 'Identifier') {return;}
if (!namespaces.has(init.name)) {return;}
// check for redefinition in intermediate scopes
if ((0, _declaredScope2['default'])(context, init.name) !== 'module') {return;}
// DFS traverse child namespaces
function testKey(pattern, namespace) {var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [init.name];
if (!(namespace instanceof _ExportMap2['default'])) {return;}
if (pattern.type !== 'ObjectPattern') {return;}var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try {
for (var _iterator = pattern.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var property = _step.value;
if (
property.type === 'ExperimentalRestProperty' ||
property.type === 'RestElement' ||
!property.key)
{
continue;
}
if (property.key.type !== 'Identifier') {
context.report({
node: property,
message: 'Only destructure top-level names.' });
continue;
}
if (!namespace.has(property.key.name)) {
context.report({
node: property,
message: makeMessage(property.key, path) });
continue;
}
path.push(property.key.name);
var dependencyExportMap = namespace.get(property.key.name);
// could be null when ignored or ambiguous
if (dependencyExportMap !== null) {
testKey(property.value, dependencyExportMap.namespace, path);
}
path.pop();
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}}
}
testKey(id, namespaces.get(init.name));
}return VariableDeclarator;}(),
JSXMemberExpression: function () {function JSXMemberExpression(_ref4) {var object = _ref4.object,property = _ref4.property;
if (!namespaces.has(object.name)) {return;}
var namespace = namespaces.get(object.name);
if (!namespace.has(property.name)) {
context.report({
node: property,
message: makeMessage(property, [object.name]) });
}
}return JSXMemberExpression;}() };
}return namespaceRule;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uYW1lc3BhY2UuanMiXSwibmFtZXMiOlsicHJvY2Vzc0JvZHlTdGF0ZW1lbnQiLCJjb250ZXh0IiwibmFtZXNwYWNlcyIsImRlY2xhcmF0aW9uIiwidHlwZSIsInNw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dCwgaW5pdC5uYW1lKSAhPT0gJ21vZHVsZScpIHsgcmV0dXJuOyB9XG5cbiAgICAgICAgLy8gREZTIHRyYXZlcnNlIGNoaWxkIG5hbWVzcGFjZXNcbiAgICAgICAgZnVuY3Rpb24gdGVzdEtleShwYXR0ZXJuLCBuYW1lc3BhY2UsIHBhdGggPSBbaW5pdC5uYW1lXSkge1xuICAgICAgICAgIGlmICghKG5hbWVzcGFjZSBpbnN0YW5jZW9mIEV4cG9ydHMpKSB7IHJldHVybjsgfVxuXG4gICAgICAgICAgaWYgKHBhdHRlcm4udHlwZSAhPT0gJ09iamVjdFBhdHRlcm4nKSB7IHJldHVybjsgfVxuXG4gICAgICAgICAgZm9yIChjb25zdCBwcm9wZXJ0eSBvZiBwYXR0ZXJuLnByb3BlcnRpZXMpIHtcbiAgICAgICAgICAgIGlmIChcbiAgICAgICAgICAgICAgcHJvcGVydHkudHlwZSA9PT0gJ0V4cGVyaW1lbnRhbFJlc3RQcm9wZXJ0eSdcbiAgICAgICAgICAgICAgfHwgcHJvcGVydHkudHlwZSA9PT0gJ1Jlc3RFbGVtZW50J1xuICAgICAgICAgICAgICB8fCAhcHJvcGVydHkua2V5XG4gICAgICAgICAgICApIHtcbiAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChwcm9wZXJ0eS5rZXkudHlwZSAhPT0gJ0lkZW50aWZpZXInKSB7XG4gICAgICAgICAgICAgIGNvbnRleHQucmVwb3J0KHtcbiAgICAgICAgICAgICAgICBub2RlOiBwcm9wZXJ0eSxcbiAgICAgICAgICAgICAgICBtZXNzYWdlOiAnT25seSBkZXN0cnVjdHVyZSB0b3AtbGV2ZWwgbmFtZXMuJyxcbiAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoIW5hbWVzcGFjZS5oYXMocHJvcGVydHkua2V5Lm5hbWUpKSB7XG4gICAgICAgICAgICAgIGNvbnRleHQucmVwb3J0KHtcbiAgICAgICAgICAgICAgICBub2RlOiBwcm9wZXJ0eSxcbiAgICAgICAgICAgICAgICBtZXNzYWdlOiBtYWtlTWVzc2FnZShwcm9wZXJ0eS5rZXksIHBhdGgpLFxuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHBhdGgucHVzaChwcm9wZXJ0eS5rZXkubmFtZSk7XG4gICAgICAgICAgICBjb25zdCBkZXBlbmRlbmN5RXhwb3J0TWFwID0gbmFtZXNwYWNlLmdldChwcm9wZXJ0eS5rZXkubmFtZSk7XG4gICAgICAgICAgICAvLyBjb3VsZCBiZSBudWxsIHdoZW4gaWdub3JlZCBvciBhbWJpZ3VvdXNcbiAgICAgICAgICAgIGlmIChkZXBlbmRlbmN5RXhwb3J0TWFwICE9PSBudWxsKSB7XG4gICAgICAgICAgICAgIHRlc3RLZXkocHJvcGVydHkudmFsdWUsIGRlcGVuZGVuY3lFeHBvcnRNYXAubmFtZXNwYWNlLCBwYXRoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHBhdGgucG9wKCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgdGVzdEtleShpZCwgbmFtZXNwYWNlcy5nZXQoaW5pdC5uYW1lKSk7XG4gICAgICB9LFxuXG4gICAgICBKU1hNZW1iZXJFeHByZXNzaW9uKHsgb2JqZWN0LCBwcm9wZXJ0eSB9KSB7XG4gICAgICAgIGlmICghbmFtZXNwYWNlcy5oYXMob2JqZWN0Lm5hbWUpKSB7IHJldHVybjsgfVxuICAgICAgICBjb25zdCBuYW1lc3BhY2UgPSBuYW1lc3BhY2VzLmdldChvYmplY3QubmFtZSk7XG4gICAgICAgIGlmICghbmFtZXNwYWNlLmhhcyhwcm9wZXJ0eS5uYW1lKSkge1xuICAgICAgICAgIGNvbnRleHQucmVwb3J0KHtcbiAgICAgICAgICAgIG5vZGU6IHByb3BlcnR5LFxuICAgICAgICAgICAgbWVzc2FnZTogbWFrZU1lc3NhZ2UocHJvcGVydHksIFtvYmplY3QubmFtZV0pLFxuICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICB9LFxuICAgIH07XG4gIH0sXG59O1xuIl19