state.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.strict = void 0;
  15. this.curLine = void 0;
  16. this.startLoc = void 0;
  17. this.endLoc = void 0;
  18. this.errors = [];
  19. this.potentialArrowAt = -1;
  20. this.noArrowAt = [];
  21. this.noArrowParamsConversionAt = [];
  22. this.maybeInArrowParameters = false;
  23. this.inPipeline = false;
  24. this.inType = false;
  25. this.noAnonFunctionType = false;
  26. this.inPropertyName = false;
  27. this.hasFlowComment = false;
  28. this.isIterator = false;
  29. this.isDeclareContext = false;
  30. this.topicContext = {
  31. maxNumOfResolvableTopics: 0,
  32. maxTopicIndex: null
  33. };
  34. this.soloAwait = false;
  35. this.inFSharpPipelineDirectBody = false;
  36. this.labels = [];
  37. this.decoratorStack = [[]];
  38. this.comments = [];
  39. this.trailingComments = [];
  40. this.leadingComments = [];
  41. this.commentStack = [];
  42. this.commentPreviousNode = null;
  43. this.pos = 0;
  44. this.lineStart = 0;
  45. this.type = _types2.types.eof;
  46. this.value = null;
  47. this.start = 0;
  48. this.end = 0;
  49. this.lastTokEndLoc = null;
  50. this.lastTokStartLoc = null;
  51. this.lastTokStart = 0;
  52. this.lastTokEnd = 0;
  53. this.context = [_context.types.braceStatement];
  54. this.exprAllowed = true;
  55. this.containsEsc = false;
  56. this.octalPositions = [];
  57. this.exportedIdentifiers = [];
  58. this.tokensLength = 0;
  59. }
  60. init(options) {
  61. this.strict = options.strictMode === false ? false : options.sourceType === "module";
  62. this.curLine = options.startLine;
  63. this.startLoc = this.endLoc = this.curPosition();
  64. }
  65. curPosition() {
  66. return new _location.Position(this.curLine, this.pos - this.lineStart);
  67. }
  68. clone(skipArrays) {
  69. const state = new State();
  70. const keys = Object.keys(this);
  71. for (let i = 0, length = keys.length; i < length; i++) {
  72. const key = keys[i];
  73. let val = this[key];
  74. if (!skipArrays && Array.isArray(val)) {
  75. val = val.slice();
  76. }
  77. state[key] = val;
  78. }
  79. return state;
  80. }
  81. }
  82. exports.default = State;