You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
216 lines
25 KiB
216 lines
25 KiB
'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; |
|
}} |
|
|
|
}); |
|
} |
|
|
|
module.exports = { |
|
meta: { |
|
type: 'problem', |
|
docs: { |
|
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) {return 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uYW1lc3BhY2UuanMiXSwibmFtZXMiOlsicHJvY2Vzc0JvZHlTdGF0ZW1lbnQiLCJjb250ZXh0IiwibmFtZXNwYWNlcyIsImRlY2xhcmF0aW9uIiwidHlwZSIsInNwZWNpZmllcnMiLCJsZW5ndGgiLCJpbXBvcnRzIiwiRXhwb3J0cyIsImdldCIsInNvdXJjZSIsInZhbHVlIiwiZXJyb3JzIiwicmVwb3J0RXJyb3JzIiwiZm9yRWFjaCIsInNwZWNpZmllciIsInNpemUiLCJyZXBvcnQiLCJzZXQiLCJsb2NhbCIsIm5hbWUiLCJtZXRhIiwiaW1wb3J0ZWQiLCJuYW1lc3BhY2UiLCJtb2R1bGUiLCJleHBvcnRzIiwiZG9jcyIsInVybCIsInNjaGVtYSIsInByb3BlcnRpZXMiLCJhbGxvd0NvbXB1dGVkIiwiZGVzY3JpcHRpb24iLCJhZGRpdGlvbmFsUHJvcGVydGllcyIsImNyZWF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gICAgICAgICAgICAgKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAoIW5hbWVzcGFjZS5oYXMoZGVyZWZlcmVuY2UucHJvcGVydHkubmFtZSkpIHtcbiAgICAgICAgICAgIGNvbnRleHQucmVwb3J0KFxuICAgICAgICAgICAgICBkZXJlZmVyZW5jZS5wcm9wZXJ0eSxcbiAgICAgICAgICAgICAgbWFrZU1lc3NhZ2UoZGVyZWZlcmVuY2UucHJvcGVydHksIG5hbWVwYXRoKSxcbiAgICAgICAgICAgICk7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBjb25zdCBleHBvcnRlZCA9IG5hbWVzcGFjZS5nZXQoZGVyZWZlcmVuY2UucHJvcGVydHkubmFtZSk7XG4gICAgICAgICAgaWYgKGV4cG9ydGVkID09IG51bGwpIHJldHVybjtcblxuICAgICAgICAgIC8vIHN0YXNoIGFuZCBwb3BcbiAgICAgICAgICBuYW1lcGF0aC5wdXNoKGRlcmVmZXJlbmNlLnByb3BlcnR5Lm5hbWUpO1xuICAgICAgICAgIG5hbWVzcGFjZSA9IGV4cG9ydGVkLm5hbWVzcGFjZTtcbiAgICAgICAgICBkZXJlZmVyZW5jZSA9IGRlcmVmZXJlbmNlLnBhcmVudDtcbiAgICAgICAgfVxuICAgICAgfSxcblxuICAgICAgVmFyaWFibGVEZWNsYXJhdG9yKHsgaWQsIGluaXQgfSkge1xuICAgICAgICBpZiAoaW5pdCA9PSBudWxsKSByZXR1cm47XG4gICAgICAgIGlmIChpbml0LnR5cGUgIT09ICdJZGVudGlmaWVyJykgcmV0dXJuO1xuICAgICAgICBpZiAoIW5hbWVzcGFjZXMuaGFzKGluaXQubmFtZSkpIHJldHVybjtcblxuICAgICAgICAvLyBjaGVjayBmb3IgcmVkZWZpbml0aW9uIGluIGludGVybWVkaWF0ZSBzY29wZXNcbiAgICAgICAgaWYgKGRlY2xhcmVkU2NvcGUoY29udGV4dCwgaW5pdC5uYW1lKSAhPT0gJ21vZHVsZScpIHJldHVybjtcblxuICAgICAgICAvLyBERlMgdHJhdmVyc2UgY2hpbGQgbmFtZXNwYWNlc1xuICAgICAgICBmdW5jdGlvbiB0ZXN0S2V5KHBhdHRlcm4sIG5hbWVzcGFjZSwgcGF0aCA9IFtpbml0Lm5hbWVdKSB7XG4gICAgICAgICAgaWYgKCEobmFtZXNwYWNlIGluc3RhbmNlb2YgRXhwb3J0cykpIHJldHVybjtcblxuICAgICAgICAgIGlmIChwYXR0ZXJuLnR5cGUgIT09ICdPYmplY3RQYXR0ZXJuJykgcmV0dXJuO1xuXG4gICAgICAgICAgZm9yIChjb25zdCBwcm9wZXJ0eSBvZiBwYXR0ZXJuLnByb3BlcnRpZXMpIHtcbiAgICAgICAgICAgIGlmIChcbiAgICAgICAgICAgICAgcHJvcGVydHkudHlwZSA9PT0gJ0V4cGVyaW1lbnRhbFJlc3RQcm9wZXJ0eSdcbiAgICAgICAgICAgICAgfHwgcHJvcGVydHkudHlwZSA9PT0gJ1Jlc3RFbGVtZW50J1xuICAgICAgICAgICAgICB8fCAhcHJvcGVydHkua2V5XG4gICAgICAgICAgICApIHtcbiAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChwcm9wZXJ0eS5rZXkudHlwZSAhPT0gJ0lkZW50aWZpZXInKSB7XG4gICAgICAgICAgICAgIGNvbnRleHQucmVwb3J0KHtcbiAgICAgICAgICAgICAgICBub2RlOiBwcm9wZXJ0eSxcbiAgICAgICAgICAgICAgICBtZXNzYWdlOiAnT25seSBkZXN0cnVjdHVyZSB0b3AtbGV2ZWwgbmFtZXMuJyxcbiAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgIGNvbnRpbnVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoIW5hbWVzcGFjZS5oYXMocHJvcGVydHkua2V5Lm5hbWUpKSB7XG4gICAgICAgICAgICAgIGNvbnRleHQucmVwb3J0KHtcbiAgICAgICAgICAgICAgICBub2RlOiBwcm9wZXJ0eSxcbiAgICAgICAgICAgICAgICBtZXNzYWdlOiBtYWtlTWVzc2FnZShwcm9wZXJ0eS5rZXksIHBhdGgpLFxuICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgY29udGludWU7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHBhdGgucHVzaChwcm9wZXJ0eS5rZXkubmFtZSk7XG4gICAgICAgICAgICBjb25zdCBkZXBlbmRlbmN5RXhwb3J0TWFwID0gbmFtZXNwYWNlLmdldChwcm9wZXJ0eS5rZXkubmFtZSk7XG4gICAgICAgICAgICAvLyBjb3VsZCBiZSBudWxsIHdoZW4gaWdub3JlZCBvciBhbWJpZ3VvdXNcbiAgICAgICAgICAgIGlmIChkZXBlbmRlbmN5RXhwb3J0TWFwICE9PSBudWxsKSB7XG4gICAgICAgICAgICAgIHRlc3RLZXkocHJvcGVydHkudmFsdWUsIGRlcGVuZGVuY3lFeHBvcnRNYXAubmFtZXNwYWNlLCBwYXRoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHBhdGgucG9wKCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgdGVzdEtleShpZCwgbmFtZXNwYWNlcy5nZXQoaW5pdC5uYW1lKSk7XG4gICAgICB9LFxuXG4gICAgICBKU1hNZW1iZXJFeHByZXNzaW9uKHsgb2JqZWN0LCBwcm9wZXJ0eSB9KSB7XG4gICAgICAgIGlmICghbmFtZXNwYWNlcy5oYXMob2JqZWN0Lm5hbWUpKSByZXR1cm47XG4gICAgICAgIGNvbnN0IG5hbWVzcGFjZSA9IG5hbWVzcGFjZXMuZ2V0KG9iamVjdC5uYW1lKTtcbiAgICAgICAgaWYgKCFuYW1lc3BhY2UuaGFzKHByb3BlcnR5Lm5hbWUpKSB7XG4gICAgICAgICAgY29udGV4dC5yZX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