github-pages-deploy-action/node_modules/eslint-plugin-import/lib/rules/no-mutable-exports.js
2020-03-06 22:45:40 -05:00

67 lines
5.7 KiB
JavaScript

'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')
},
schema: []
},
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1tdXRhYmxlLWV4cG9ydHMuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJjaGVja0RlY2xhcmF0aW9uIiwibm9kZSIsImtpbmQiLCJyZXBvcnQiLCJjaGVja0RlY2xhcmF0aW9uc0luU2NvcGUiLCJuYW1lIiwidmFyaWFibGVzIiwidmFyaWFibGUiLCJkZWYiLCJkZWZzIiwicGFyZW50I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