123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- '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 (const variable of variables) {
- if (variable.name === name) {
- for (const 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 (const specifier of node.specifiers) {
- checkDeclarationsInScope(scope, specifier.local.name);
- }
- }
- }
- return {
- 'ExportDefaultDeclaration': handleExportDefault,
- 'ExportNamedDeclaration': handleExportNamed };
- } };
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1tdXRhYmxlLWV4cG9ydHMuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsImNvbnRleHQiLCJjaGVja0RlY2xhcmF0aW9uIiwibm9kZSIsImtpbmQiLCJyZXBvcnQiLCJjaGVja0RlY2xhcmF0aW9uc0luU2NvcGUiLCJuYW1lIiwidmFyaWFibGVzIiwidmFyaWFibGUiLCJkZWYiLCJkZWZzIiwicGFyZW50Ii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