ast.mjs 2.4 KB

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