state.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var N = _interopRequireWildcard(require("../types"));
  7. var _location = require("../util/location");
  8. var _context = require("./context");
  9. var _types2 = require("./types");
  10. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  11. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  12. class State {
  13. constructor() {
  14. this.errors = [];
  15. this.potentialArrowAt = -1;
  16. this.noArrowAt = [];
  17. this.noArrowParamsConversionAt = [];
  18. this.inParameters = false;
  19. this.maybeInArrowParameters = false;
  20. this.inPipeline = false;
  21. this.inType = false;
  22. this.noAnonFunctionType = false;
  23. this.inPropertyName = false;
  24. this.hasFlowComment = false;
  25. this.isIterator = false;
  26. this.topicContext = {
  27. maxNumOfResolvableTopics: 0,
  28. maxTopicIndex: null
  29. };
  30. this.soloAwait = false;
  31. this.inFSharpPipelineDirectBody = false;
  32. this.labels = [];
  33. this.decoratorStack = [[]];
  34. this.yieldPos = -1;
  35. this.awaitPos = -1;
  36. this.comments = [];
  37. this.trailingComments = [];
  38. this.leadingComments = [];
  39. this.commentStack = [];
  40. this.commentPreviousNode = null;
  41. this.pos = 0;
  42. this.lineStart = 0;
  43. this.type = _types2.types.eof;
  44. this.value = null;
  45. this.start = 0;
  46. this.end = 0;
  47. this.lastTokEndLoc = null;
  48. this.lastTokStartLoc = null;
  49. this.lastTokStart = 0;
  50. this.lastTokEnd = 0;
  51. this.context = [_context.types.braceStatement];
  52. this.exprAllowed = true;
  53. this.containsEsc = false;
  54. this.containsOctal = false;
  55. this.octalPosition = null;
  56. this.exportedIdentifiers = [];
  57. this.tokensLength = 0;
  58. }
  59. init(options) {
  60. this.strict = options.strictMode === false ? false : options.sourceType === "module";
  61. this.curLine = options.startLine;
  62. this.startLoc = this.endLoc = this.curPosition();
  63. }
  64. curPosition() {
  65. return new _location.Position(this.curLine, this.pos - this.lineStart);
  66. }
  67. clone(skipArrays) {
  68. const state = new State();
  69. const keys = Object.keys(this);
  70. for (let i = 0, length = keys.length; i < length; i++) {
  71. const key = keys[i];
  72. let val = this[key];
  73. if (!skipArrays && Array.isArray(val)) {
  74. val = val.slice();
  75. }
  76. state[key] = val;
  77. }
  78. return state;
  79. }
  80. }
  81. exports.default = State;