bigint-crypto-utils/node_modules/eslint-plugin-import/lib/rules/no-mutable-exports.js

66 lines
5.6 KiB
JavaScript
Raw Normal View History

'use strict';
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = {
meta: {
type: 'suggestion',
docs: {
url: (0, _docsUrl2.default)('no-mutable-exports')
}
},
create: function (context) {
function checkDeclaration(node) {
const kind = node.kind;
if (kind === 'var' || kind === 'let') {
context.report(node, `Exporting mutable '${kind}' binding, use 'const' instead.`);
}
}
function checkDeclarationsInScope(_ref, name) {
let variables = _ref.variables;
for (let variable of variables) {
if (variable.name === name) {
for (let def of variable.defs) {
if (def.type === 'Variable' && def.parent) {
checkDeclaration(def.parent);
}
}
}
}
}
function handleExportDefault(node) {
const scope = context.getScope();
if (node.declaration.name) {
checkDeclarationsInScope(scope, node.declaration.name);
}
}
function handleExportNamed(node) {
const scope = context.getScope();
if (node.declaration) {
checkDeclaration(node.declaration);
} else if (!node.source) {
for (let specifier of node.specifiers) {
checkDeclarationsInScope(scope, specifier.local.name);
}
}
}
return {
'ExportDefaultDeclaration': handleExportDefault,
'ExportNamedDeclaration': handleExportNamed
};
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1tdXRhYmxlLWV4cG9ydHMuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsImNyZWF0ZSIsImNvbnRleHQiLCJjaGVja0RlY2xhcmF0aW9uIiwibm9kZSIsImtpbmQiLCJyZXBvcnQiLCJjaGVja0RlY2xhcmF0aW9uc0luU2NvcGUiLCJuYW1lIiwidmFyaWFibGVzIiwidmFyaWFibGUiLCJkZWYiLCJkZWZzIiwicGFyZW50IiwiaGFuZGxlRXhwb3J0RGVmYX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