index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. "use strict";
  2. var _getIterator = require("babel-runtime/core-js/get-iterator")["default"];
  3. exports.__esModule = true;
  4. exports["default"] = function (_ref3) {
  5. var messages = _ref3.messages;
  6. var t = _ref3.types;
  7. function check(node) {
  8. if (t.isVariableDeclaration(node, { kind: "const" })) {
  9. node.kind = "let";
  10. }
  11. }
  12. return {
  13. visitor: {
  14. Scope: function Scope(_ref4) {
  15. var scope = _ref4.scope;
  16. for (var _name in scope.bindings) {
  17. var binding = scope.bindings[_name];
  18. if (binding.kind !== "const" && binding.kind !== "module") continue;
  19. for (var _iterator = (binding.constantViolations /*: Array*/), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _getIterator(_iterator);;) {
  20. var _ref;
  21. if (_isArray) {
  22. if (_i >= _iterator.length) break;
  23. _ref = _iterator[_i++];
  24. } else {
  25. _i = _iterator.next();
  26. if (_i.done) break;
  27. _ref = _i.value;
  28. }
  29. var violation = _ref;
  30. throw violation.buildCodeFrameError(messages.get("readOnly", _name));
  31. }
  32. }
  33. },
  34. VariableDeclaration: function VariableDeclaration(_ref5) {
  35. var node = _ref5.node;
  36. check(node);
  37. },
  38. ForXStatement: function ForXStatement(_ref6) {
  39. var left = _ref6.node.left;
  40. check(left);
  41. },
  42. ForStatement: function ForStatement(_ref7) {
  43. var init = _ref7.node.init;
  44. check(init);
  45. },
  46. "BlockStatement|Program": function BlockStatementProgram(_ref8) {
  47. var body = _ref8.node.body;
  48. for (var _iterator2 = body, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _getIterator(_iterator2);;) {
  49. var _ref2;
  50. if (_isArray2) {
  51. if (_i2 >= _iterator2.length) break;
  52. _ref2 = _iterator2[_i2++];
  53. } else {
  54. _i2 = _iterator2.next();
  55. if (_i2.done) break;
  56. _ref2 = _i2.value;
  57. }
  58. var node = _ref2;
  59. check(node);
  60. }
  61. }
  62. }
  63. };
  64. };
  65. module.exports = exports["default"];