no-mutable-exports.js 7.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
  2. module.exports = {
  3. meta: {
  4. type: 'suggestion',
  5. docs: {
  6. category: 'Helpful warnings',
  7. description: 'Forbid the use of mutable exports with `var` or `let`.',
  8. url: (0, _docsUrl2['default'])('no-mutable-exports') },
  9. schema: [] },
  10. create: function () {function create(context) {
  11. function checkDeclaration(node) {var
  12. kind = node.kind;
  13. if (kind === 'var' || kind === 'let') {
  14. context.report(node, 'Exporting mutable \'' + String(kind) + '\' binding, use \'const\' instead.');
  15. }
  16. }
  17. function checkDeclarationsInScope(_ref, name) {var variables = _ref.variables;var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try {
  18. for (var _iterator = variables[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var variable = _step.value;
  19. if (variable.name === name) {var _iteratorNormalCompletion2 = true;var _didIteratorError2 = false;var _iteratorError2 = undefined;try {
  20. for (var _iterator2 = variable.defs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {var def = _step2.value;
  21. if (def.type === 'Variable' && def.parent) {
  22. checkDeclaration(def.parent);
  23. }
  24. }} catch (err) {_didIteratorError2 = true;_iteratorError2 = err;} finally {try {if (!_iteratorNormalCompletion2 && _iterator2['return']) {_iterator2['return']();}} finally {if (_didIteratorError2) {throw _iteratorError2;}}}
  25. }
  26. }} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}}
  27. }
  28. function handleExportDefault(node) {
  29. var scope = context.getScope();
  30. if (node.declaration.name) {
  31. checkDeclarationsInScope(scope, node.declaration.name);
  32. }
  33. }
  34. function handleExportNamed(node) {
  35. var scope = context.getScope();
  36. if (node.declaration) {
  37. checkDeclaration(node.declaration);
  38. } else if (!node.source) {var _iteratorNormalCompletion3 = true;var _didIteratorError3 = false;var _iteratorError3 = undefined;try {
  39. for (var _iterator3 = node.specifiers[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {var specifier = _step3.value;
  40. checkDeclarationsInScope(scope, specifier.local.name);
  41. }} catch (err) {_didIteratorError3 = true;_iteratorError3 = err;} finally {try {if (!_iteratorNormalCompletion3 && _iterator3['return']) {_iterator3['return']();}} finally {if (_didIteratorError3) {throw _iteratorError3;}}}
  42. }
  43. }
  44. return {
  45. ExportDefaultDeclaration: handleExportDefault,
  46. ExportNamedDeclaration: handleExportNamed };
  47. }return create;}() };
  48. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1tdXRhYmxlLWV4cG9ydHMuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImNhdGVnb3J5IiwiZGVzY3JpcHRpb24iLCJ1cmwiLCJzY2hlbWEiLCJjcmVhdGUiLCJjb250ZXh0IiwiY2hlY2tEZWNsYXJhdGlvbiIsIm5vZGUiLCJraW5kIiwicmVwb3J0IiwiY2hlY2tEZWNsYXJhdGlvbnNJblNjb3BlIiwibmFtZSIsInZhcmlhYmxlcyIsInZhcmlhYmxlIiwiZGVmcyIsImRlZiIsInBhcmVudCIsImhhbmRsZUV4cG9ydERlZmF1bHQiLCJzY29wZSIsImdldFNjb3BlIiwiZGVjbGFyYXRpb24iLCJoYW5kbGVFeHBvcnROYW1lZCIsInNvdXJjZSIsInNwZWNpZmllcnMiLCJzcGVjaWZpZXIiLCJsb2NhbCIsIkV4cG9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