ast.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isNode = isNode;
  6. exports.Token = exports.Location = void 0;
  7. var _defineInspect = _interopRequireDefault(require("../jsutils/defineInspect.js"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * Contains a range of UTF-8 character offsets and token references that
  11. * identify the region of the source from which the AST derived.
  12. */
  13. var Location = /*#__PURE__*/function () {
  14. /**
  15. * The character offset at which this Node begins.
  16. */
  17. /**
  18. * The character offset at which this Node ends.
  19. */
  20. /**
  21. * The Token at which this Node begins.
  22. */
  23. /**
  24. * The Token at which this Node ends.
  25. */
  26. /**
  27. * The Source document the AST represents.
  28. */
  29. function Location(startToken, endToken, source) {
  30. this.start = startToken.start;
  31. this.end = endToken.end;
  32. this.startToken = startToken;
  33. this.endToken = endToken;
  34. this.source = source;
  35. }
  36. var _proto = Location.prototype;
  37. _proto.toJSON = function toJSON() {
  38. return {
  39. start: this.start,
  40. end: this.end
  41. };
  42. };
  43. return Location;
  44. }(); // Print a simplified form when appearing in `inspect` and `util.inspect`.
  45. exports.Location = Location;
  46. (0, _defineInspect.default)(Location);
  47. /**
  48. * Represents a range of characters represented by a lexical token
  49. * within a Source.
  50. */
  51. var Token = /*#__PURE__*/function () {
  52. /**
  53. * The kind of Token.
  54. */
  55. /**
  56. * The character offset at which this Node begins.
  57. */
  58. /**
  59. * The character offset at which this Node ends.
  60. */
  61. /**
  62. * The 1-indexed line number on which this Token appears.
  63. */
  64. /**
  65. * The 1-indexed column number at which this Token begins.
  66. */
  67. /**
  68. * For non-punctuation tokens, represents the interpreted value of the token.
  69. */
  70. /**
  71. * Tokens exist as nodes in a double-linked-list amongst all tokens
  72. * including ignored tokens. <SOF> is always the first node and <EOF>
  73. * the last.
  74. */
  75. function Token(kind, start, end, line, column, prev, value) {
  76. this.kind = kind;
  77. this.start = start;
  78. this.end = end;
  79. this.line = line;
  80. this.column = column;
  81. this.value = value;
  82. this.prev = prev;
  83. this.next = null;
  84. }
  85. var _proto2 = Token.prototype;
  86. _proto2.toJSON = function toJSON() {
  87. return {
  88. kind: this.kind,
  89. value: this.value,
  90. line: this.line,
  91. column: this.column
  92. };
  93. };
  94. return Token;
  95. }(); // Print a simplified form when appearing in `inspect` and `util.inspect`.
  96. exports.Token = Token;
  97. (0, _defineInspect.default)(Token);
  98. /**
  99. * @internal
  100. */
  101. function isNode(maybeNode) {
  102. return maybeNode != null && typeof maybeNode.kind === 'string';
  103. }
  104. /**
  105. * The list of all possible AST node types.
  106. */