UNPKG

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