msw 0.36.8 → 0.38.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node/lib/index.js CHANGED
@@ -2069,7 +2069,6 @@ var serialize_1 = serialize;
2069
2069
 
2070
2070
  var decode = decodeURIComponent;
2071
2071
  var encode = encodeURIComponent;
2072
- var pairSplitRegExp = /; */;
2073
2072
 
2074
2073
  /**
2075
2074
  * RegExp to match field-content in RFC 7230 sec 3.2
@@ -2100,28 +2099,29 @@ function parse$2(str, options) {
2100
2099
 
2101
2100
  var obj = {};
2102
2101
  var opt = options || {};
2103
- var pairs = str.split(pairSplitRegExp);
2102
+ var pairs = str.split(';');
2104
2103
  var dec = opt.decode || decode;
2105
2104
 
2106
2105
  for (var i = 0; i < pairs.length; i++) {
2107
2106
  var pair = pairs[i];
2108
- var eq_idx = pair.indexOf('=');
2107
+ var index = pair.indexOf('=');
2109
2108
 
2110
2109
  // skip things that don't look like key=value
2111
- if (eq_idx < 0) {
2110
+ if (index < 0) {
2112
2111
  continue;
2113
2112
  }
2114
2113
 
2115
- var key = pair.substr(0, eq_idx).trim();
2116
- var val = pair.substr(++eq_idx, pair.length).trim();
2117
-
2118
- // quoted values
2119
- if ('"' == val[0]) {
2120
- val = val.slice(1, -1);
2121
- }
2114
+ var key = pair.substring(0, index).trim();
2122
2115
 
2123
2116
  // only assign once
2124
2117
  if (undefined == obj[key]) {
2118
+ var val = pair.substring(index + 1, pair.length).trim();
2119
+
2120
+ // quoted values
2121
+ if (val[0] === '"') {
2122
+ val = val.slice(1, -1);
2123
+ }
2124
+
2125
2125
  obj[key] = tryDecode(val, dec);
2126
2126
  }
2127
2127
  }
@@ -2644,6 +2644,9 @@ var Headers_1$2 = Headers;
2644
2644
  function stringToHeaders(str) {
2645
2645
  var lines = str.trim().split(/[\r\n]+/);
2646
2646
  return lines.reduce(function (headers, line) {
2647
+ if (line.trim() === '') {
2648
+ return headers;
2649
+ }
2647
2650
  var parts = line.split(': ');
2648
2651
  var name = parts.shift();
2649
2652
  var value = parts.join(': ');
@@ -3277,20 +3280,33 @@ var jsLevenshtein = (function()
3277
3280
  };
3278
3281
  })();
3279
3282
 
3280
- function _typeof$3(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$3 = function _typeof(obj) { return typeof obj; }; } else { _typeof$3 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$3(obj); }
3283
+ function devAssert(condition, message) {
3284
+ const booleanCondition = Boolean(condition);
3285
+
3286
+ if (!booleanCondition) {
3287
+ throw new Error(message);
3288
+ }
3289
+ }
3281
3290
 
3282
3291
  /**
3283
3292
  * Return true if `value` is object-like. A value is object-like if it's not
3284
3293
  * `null` and has a `typeof` result of "object".
3285
3294
  */
3286
3295
  function isObjectLike(value) {
3287
- return _typeof$3(value) == 'object' && value !== null;
3296
+ return typeof value == 'object' && value !== null;
3288
3297
  }
3289
3298
 
3290
- // In ES2015 (or a polyfilled) environment, this will be Symbol.iterator
3299
+ function invariant(condition, message) {
3300
+ const booleanCondition = Boolean(condition);
3291
3301
 
3292
- var SYMBOL_TO_STRING_TAG = typeof Symbol === 'function' && Symbol.toStringTag != null ? Symbol.toStringTag : '@@toStringTag';
3302
+ if (!booleanCondition) {
3303
+ throw new Error(
3304
+ message != null ? message : 'Unexpected invariant triggered.',
3305
+ );
3306
+ }
3307
+ }
3293
3308
 
3309
+ const LineRegExp = /\r\n|[\n\r]/g;
3294
3310
  /**
3295
3311
  * Represents a location in a Source.
3296
3312
  */
@@ -3300,115 +3316,107 @@ var SYMBOL_TO_STRING_TAG = typeof Symbol === 'function' && Symbol.toStringTag !=
3300
3316
  * line and column as a SourceLocation.
3301
3317
  */
3302
3318
  function getLocation(source, position) {
3303
- var lineRegexp = /\r\n|[\n\r]/g;
3304
- var line = 1;
3305
- var column = position + 1;
3306
- var match;
3319
+ let lastLineStart = 0;
3320
+ let line = 1;
3321
+
3322
+ for (const match of source.body.matchAll(LineRegExp)) {
3323
+ typeof match.index === 'number' || invariant(false);
3324
+
3325
+ if (match.index >= position) {
3326
+ break;
3327
+ }
3307
3328
 
3308
- while ((match = lineRegexp.exec(source.body)) && match.index < position) {
3329
+ lastLineStart = match.index + match[0].length;
3309
3330
  line += 1;
3310
- column = position + 1 - (match.index + match[0].length);
3311
3331
  }
3312
3332
 
3313
3333
  return {
3314
- line: line,
3315
- column: column
3334
+ line,
3335
+ column: position + 1 - lastLineStart,
3316
3336
  };
3317
3337
  }
3318
3338
 
3319
3339
  /**
3320
3340
  * Render a helpful description of the location in the GraphQL Source document.
3321
3341
  */
3322
-
3323
3342
  function printLocation(location) {
3324
- return printSourceLocation(location.source, getLocation(location.source, location.start));
3343
+ return printSourceLocation(
3344
+ location.source,
3345
+ getLocation(location.source, location.start),
3346
+ );
3325
3347
  }
3326
3348
  /**
3327
3349
  * Render a helpful description of the location in the GraphQL Source document.
3328
3350
  */
3329
3351
 
3330
3352
  function printSourceLocation(source, sourceLocation) {
3331
- var firstLineColumnOffset = source.locationOffset.column - 1;
3332
- var body = whitespace(firstLineColumnOffset) + source.body;
3333
- var lineIndex = sourceLocation.line - 1;
3334
- var lineOffset = source.locationOffset.line - 1;
3335
- var lineNum = sourceLocation.line + lineOffset;
3336
- var columnOffset = sourceLocation.line === 1 ? firstLineColumnOffset : 0;
3337
- var columnNum = sourceLocation.column + columnOffset;
3338
- var locationStr = "".concat(source.name, ":").concat(lineNum, ":").concat(columnNum, "\n");
3339
- var lines = body.split(/\r\n|[\n\r]/g);
3340
- var locationLine = lines[lineIndex]; // Special case for minified documents
3353
+ const firstLineColumnOffset = source.locationOffset.column - 1;
3354
+ const body = ''.padStart(firstLineColumnOffset) + source.body;
3355
+ const lineIndex = sourceLocation.line - 1;
3356
+ const lineOffset = source.locationOffset.line - 1;
3357
+ const lineNum = sourceLocation.line + lineOffset;
3358
+ const columnOffset = sourceLocation.line === 1 ? firstLineColumnOffset : 0;
3359
+ const columnNum = sourceLocation.column + columnOffset;
3360
+ const locationStr = `${source.name}:${lineNum}:${columnNum}\n`;
3361
+ const lines = body.split(/\r\n|[\n\r]/g);
3362
+ const locationLine = lines[lineIndex]; // Special case for minified documents
3341
3363
 
3342
3364
  if (locationLine.length > 120) {
3343
- var subLineIndex = Math.floor(columnNum / 80);
3344
- var subLineColumnNum = columnNum % 80;
3345
- var subLines = [];
3365
+ const subLineIndex = Math.floor(columnNum / 80);
3366
+ const subLineColumnNum = columnNum % 80;
3367
+ const subLines = [];
3346
3368
 
3347
- for (var i = 0; i < locationLine.length; i += 80) {
3369
+ for (let i = 0; i < locationLine.length; i += 80) {
3348
3370
  subLines.push(locationLine.slice(i, i + 80));
3349
3371
  }
3350
3372
 
3351
- return locationStr + printPrefixedLines([["".concat(lineNum), subLines[0]]].concat(subLines.slice(1, subLineIndex + 1).map(function (subLine) {
3352
- return ['', subLine];
3353
- }), [[' ', whitespace(subLineColumnNum - 1) + '^'], ['', subLines[subLineIndex + 1]]]));
3373
+ return (
3374
+ locationStr +
3375
+ printPrefixedLines([
3376
+ [`${lineNum} |`, subLines[0]],
3377
+ ...subLines.slice(1, subLineIndex + 1).map((subLine) => ['|', subLine]),
3378
+ ['|', '^'.padStart(subLineColumnNum)],
3379
+ ['|', subLines[subLineIndex + 1]],
3380
+ ])
3381
+ );
3354
3382
  }
3355
3383
 
3356
- return locationStr + printPrefixedLines([// Lines specified like this: ["prefix", "string"],
3357
- ["".concat(lineNum - 1), lines[lineIndex - 1]], ["".concat(lineNum), locationLine], ['', whitespace(columnNum - 1) + '^'], ["".concat(lineNum + 1), lines[lineIndex + 1]]]);
3384
+ return (
3385
+ locationStr +
3386
+ printPrefixedLines([
3387
+ // Lines specified like this: ["prefix", "string"],
3388
+ [`${lineNum - 1} |`, lines[lineIndex - 1]],
3389
+ [`${lineNum} |`, locationLine],
3390
+ ['|', '^'.padStart(columnNum)],
3391
+ [`${lineNum + 1} |`, lines[lineIndex + 1]],
3392
+ ])
3393
+ );
3358
3394
  }
3359
3395
 
3360
3396
  function printPrefixedLines(lines) {
3361
- var existingLines = lines.filter(function (_ref) {
3362
- _ref[0];
3363
- var line = _ref[1];
3364
- return line !== undefined;
3365
- });
3366
- var padLen = Math.max.apply(Math, existingLines.map(function (_ref2) {
3367
- var prefix = _ref2[0];
3368
- return prefix.length;
3369
- }));
3370
- return existingLines.map(function (_ref3) {
3371
- var prefix = _ref3[0],
3372
- line = _ref3[1];
3373
- return leftPad(padLen, prefix) + (line ? ' | ' + line : ' |');
3374
- }).join('\n');
3375
- }
3376
-
3377
- function whitespace(len) {
3378
- return Array(len + 1).join(' ');
3379
- }
3380
-
3381
- function leftPad(len, str) {
3382
- return whitespace(len - str.length) + str;
3397
+ const existingLines = lines.filter(([_, line]) => line !== undefined);
3398
+ const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
3399
+ return existingLines
3400
+ .map(([prefix, line]) => prefix.padStart(padLen) + (line ? ' ' + line : ''))
3401
+ .join('\n');
3383
3402
  }
3384
3403
 
3385
- function _typeof$2(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); }
3386
-
3387
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3388
-
3389
- function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3390
-
3391
- function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
3392
-
3393
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
3394
-
3395
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
3404
+ function toNormalizedArgs(args) {
3405
+ const firstArg = args[0];
3396
3406
 
3397
- function _possibleConstructorReturn(self, call) { if (call && (_typeof$2(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
3398
-
3399
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
3400
-
3401
- function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
3402
-
3403
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
3404
-
3405
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
3406
-
3407
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
3408
-
3409
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
3407
+ if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
3408
+ return {
3409
+ nodes: firstArg,
3410
+ source: args[1],
3411
+ positions: args[2],
3412
+ path: args[3],
3413
+ originalError: args[4],
3414
+ extensions: args[5],
3415
+ };
3416
+ }
3410
3417
 
3411
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
3418
+ return firstArg;
3419
+ }
3412
3420
  /**
3413
3421
  * A GraphQLError describes an Error found during the parse, validate, or
3414
3422
  * execute phases of performing a GraphQL operation. In addition to a message
@@ -3416,21 +3424,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
3416
3424
  * GraphQL document and/or execution result that correspond to the Error.
3417
3425
  */
3418
3426
 
3419
- var GraphQLError = /*#__PURE__*/function (_Error) {
3420
- _inherits(GraphQLError, _Error);
3421
-
3422
- var _super = _createSuper(GraphQLError);
3423
-
3424
- /**
3425
- * A message describing the Error for debugging purposes.
3426
- *
3427
- * Enumerable, and appears in the result of JSON.stringify().
3428
- *
3429
- * Note: should be treated as readonly, despite invariant usage.
3430
- */
3431
-
3427
+ class GraphQLError extends Error {
3432
3428
  /**
3433
- * An array of { line, column } locations within the source GraphQL document
3429
+ * An array of `{ line, column }` locations within the source GraphQL document
3434
3430
  * which correspond to this error.
3435
3431
  *
3436
3432
  * Errors during validation often contain multiple locations, for example to
@@ -3470,184 +3466,163 @@ var GraphQLError = /*#__PURE__*/function (_Error) {
3470
3466
  /**
3471
3467
  * Extension fields to add to the formatted error.
3472
3468
  */
3473
- function GraphQLError(message, nodes, source, positions, path, originalError, extensions) {
3474
- var _locations2, _source2, _positions2, _extensions2;
3475
-
3476
- var _this;
3477
-
3478
- _classCallCheck(this, GraphQLError);
3479
-
3480
- _this = _super.call(this, message); // Compute list of blame nodes.
3481
-
3482
- var _nodes = Array.isArray(nodes) ? nodes.length !== 0 ? nodes : undefined : nodes ? [nodes] : undefined; // Compute locations in the source for the given nodes/positions.
3483
-
3484
-
3485
- var _source = source;
3486
-
3487
- if (!_source && _nodes) {
3488
- var _nodes$0$loc;
3489
-
3490
- _source = (_nodes$0$loc = _nodes[0].loc) === null || _nodes$0$loc === void 0 ? void 0 : _nodes$0$loc.source;
3491
- }
3492
-
3493
- var _positions = positions;
3494
-
3495
- if (!_positions && _nodes) {
3496
- _positions = _nodes.reduce(function (list, node) {
3497
- if (node.loc) {
3498
- list.push(node.loc.start);
3499
- }
3500
-
3501
- return list;
3502
- }, []);
3503
- }
3504
-
3505
- if (_positions && _positions.length === 0) {
3506
- _positions = undefined;
3507
- }
3508
-
3509
- var _locations;
3510
-
3511
- if (positions && source) {
3512
- _locations = positions.map(function (pos) {
3513
- return getLocation(source, pos);
3514
- });
3515
- } else if (_nodes) {
3516
- _locations = _nodes.reduce(function (list, node) {
3517
- if (node.loc) {
3518
- list.push(getLocation(node.loc.source, node.loc.start));
3519
- }
3520
3469
 
3521
- return list;
3522
- }, []);
3523
- }
3524
-
3525
- var _extensions = extensions;
3526
-
3527
- if (_extensions == null && originalError != null) {
3528
- var originalExtensions = originalError.extensions;
3529
-
3530
- if (isObjectLike(originalExtensions)) {
3531
- _extensions = originalExtensions;
3532
- }
3533
- }
3534
-
3535
- Object.defineProperties(_assertThisInitialized(_this), {
3536
- name: {
3537
- value: 'GraphQLError'
3538
- },
3470
+ /**
3471
+ * @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
3472
+ */
3473
+ constructor(message, ...rawArgs) {
3474
+ var _this$nodes, _nodeLocations$, _ref;
3475
+
3476
+ const { nodes, source, positions, path, originalError, extensions } =
3477
+ toNormalizedArgs(rawArgs);
3478
+ super(message);
3479
+ this.name = 'GraphQLError';
3480
+ this.path = path !== null && path !== void 0 ? path : undefined;
3481
+ this.originalError =
3482
+ originalError !== null && originalError !== void 0
3483
+ ? originalError
3484
+ : undefined; // Compute list of blame nodes.
3485
+
3486
+ this.nodes = undefinedIfEmpty(
3487
+ Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined,
3488
+ );
3489
+ const nodeLocations = undefinedIfEmpty(
3490
+ (_this$nodes = this.nodes) === null || _this$nodes === void 0
3491
+ ? void 0
3492
+ : _this$nodes.map((node) => node.loc).filter((loc) => loc != null),
3493
+ ); // Compute locations in the source for the given nodes/positions.
3494
+
3495
+ this.source =
3496
+ source !== null && source !== void 0
3497
+ ? source
3498
+ : nodeLocations === null || nodeLocations === void 0
3499
+ ? void 0
3500
+ : (_nodeLocations$ = nodeLocations[0]) === null ||
3501
+ _nodeLocations$ === void 0
3502
+ ? void 0
3503
+ : _nodeLocations$.source;
3504
+ this.positions =
3505
+ positions !== null && positions !== void 0
3506
+ ? positions
3507
+ : nodeLocations === null || nodeLocations === void 0
3508
+ ? void 0
3509
+ : nodeLocations.map((loc) => loc.start);
3510
+ this.locations =
3511
+ positions && source
3512
+ ? positions.map((pos) => getLocation(source, pos))
3513
+ : nodeLocations === null || nodeLocations === void 0
3514
+ ? void 0
3515
+ : nodeLocations.map((loc) => getLocation(loc.source, loc.start));
3516
+ const originalExtensions = isObjectLike(
3517
+ originalError === null || originalError === void 0
3518
+ ? void 0
3519
+ : originalError.extensions,
3520
+ )
3521
+ ? originalError === null || originalError === void 0
3522
+ ? void 0
3523
+ : originalError.extensions
3524
+ : undefined;
3525
+ this.extensions =
3526
+ (_ref =
3527
+ extensions !== null && extensions !== void 0
3528
+ ? extensions
3529
+ : originalExtensions) !== null && _ref !== void 0
3530
+ ? _ref
3531
+ : Object.create(null); // Only properties prescribed by the spec should be enumerable.
3532
+ // Keep the rest as non-enumerable.
3533
+
3534
+ Object.defineProperties(this, {
3539
3535
  message: {
3540
- value: message,
3541
- // By being enumerable, JSON.stringify will include `message` in the
3542
- // resulting output. This ensures that the simplest possible GraphQL
3543
- // service adheres to the spec.
3536
+ writable: true,
3544
3537
  enumerable: true,
3545
- writable: true
3546
3538
  },
3547
- locations: {
3548
- // Coercing falsy values to undefined ensures they will not be included
3549
- // in JSON.stringify() when not provided.
3550
- value: (_locations2 = _locations) !== null && _locations2 !== void 0 ? _locations2 : undefined,
3551
- // By being enumerable, JSON.stringify will include `locations` in the
3552
- // resulting output. This ensures that the simplest possible GraphQL
3553
- // service adheres to the spec.
3554
- enumerable: _locations != null
3555
- },
3556
- path: {
3557
- // Coercing falsy values to undefined ensures they will not be included
3558
- // in JSON.stringify() when not provided.
3559
- value: path !== null && path !== void 0 ? path : undefined,
3560
- // By being enumerable, JSON.stringify will include `path` in the
3561
- // resulting output. This ensures that the simplest possible GraphQL
3562
- // service adheres to the spec.
3563
- enumerable: path != null
3539
+ name: {
3540
+ enumerable: false,
3564
3541
  },
3565
3542
  nodes: {
3566
- value: _nodes !== null && _nodes !== void 0 ? _nodes : undefined
3543
+ enumerable: false,
3567
3544
  },
3568
3545
  source: {
3569
- value: (_source2 = _source) !== null && _source2 !== void 0 ? _source2 : undefined
3546
+ enumerable: false,
3570
3547
  },
3571
3548
  positions: {
3572
- value: (_positions2 = _positions) !== null && _positions2 !== void 0 ? _positions2 : undefined
3549
+ enumerable: false,
3573
3550
  },
3574
3551
  originalError: {
3575
- value: originalError
3552
+ enumerable: false,
3576
3553
  },
3577
- extensions: {
3578
- // Coercing falsy values to undefined ensures they will not be included
3579
- // in JSON.stringify() when not provided.
3580
- value: (_extensions2 = _extensions) !== null && _extensions2 !== void 0 ? _extensions2 : undefined,
3581
- // By being enumerable, JSON.stringify will include `path` in the
3582
- // resulting output. This ensures that the simplest possible GraphQL
3583
- // service adheres to the spec.
3584
- enumerable: _extensions != null
3585
- }
3586
3554
  }); // Include (non-enumerable) stack trace.
3587
3555
 
3588
- if (originalError !== null && originalError !== void 0 && originalError.stack) {
3589
- Object.defineProperty(_assertThisInitialized(_this), 'stack', {
3556
+ /* c8 ignore start */
3557
+ // FIXME: https://github.com/graphql/graphql-js/issues/2317
3558
+
3559
+ if (
3560
+ originalError !== null &&
3561
+ originalError !== void 0 &&
3562
+ originalError.stack
3563
+ ) {
3564
+ Object.defineProperty(this, 'stack', {
3590
3565
  value: originalError.stack,
3591
3566
  writable: true,
3592
- configurable: true
3567
+ configurable: true,
3593
3568
  });
3594
- return _possibleConstructorReturn(_this);
3595
- } // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
3596
-
3597
-
3598
- if (Error.captureStackTrace) {
3599
- Error.captureStackTrace(_assertThisInitialized(_this), GraphQLError);
3569
+ } else if (Error.captureStackTrace) {
3570
+ Error.captureStackTrace(this, GraphQLError);
3600
3571
  } else {
3601
- Object.defineProperty(_assertThisInitialized(_this), 'stack', {
3572
+ Object.defineProperty(this, 'stack', {
3602
3573
  value: Error().stack,
3603
3574
  writable: true,
3604
- configurable: true
3575
+ configurable: true,
3605
3576
  });
3606
3577
  }
3578
+ /* c8 ignore stop */
3579
+ }
3607
3580
 
3608
- return _this;
3581
+ get [Symbol.toStringTag]() {
3582
+ return 'GraphQLError';
3609
3583
  }
3610
3584
 
3611
- _createClass$1(GraphQLError, [{
3612
- key: "toString",
3613
- value: function toString() {
3614
- return printError(this);
3615
- } // FIXME: workaround to not break chai comparisons, should be remove in v16
3616
- // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
3617
-
3618
- }, {
3619
- key: SYMBOL_TO_STRING_TAG,
3620
- get: function get() {
3621
- return 'Object';
3585
+ toString() {
3586
+ let output = this.message;
3587
+
3588
+ if (this.nodes) {
3589
+ for (const node of this.nodes) {
3590
+ if (node.loc) {
3591
+ output += '\n\n' + printLocation(node.loc);
3592
+ }
3593
+ }
3594
+ } else if (this.source && this.locations) {
3595
+ for (const location of this.locations) {
3596
+ output += '\n\n' + printSourceLocation(this.source, location);
3597
+ }
3622
3598
  }
3623
- }]);
3624
3599
 
3625
- return GraphQLError;
3626
- }( /*#__PURE__*/_wrapNativeSuper(Error));
3627
- /**
3628
- * Prints a GraphQLError to a string, representing useful location information
3629
- * about the error's position in the source.
3630
- */
3600
+ return output;
3601
+ }
3631
3602
 
3632
- function printError(error) {
3633
- var output = error.message;
3603
+ toJSON() {
3604
+ const formattedError = {
3605
+ message: this.message,
3606
+ };
3634
3607
 
3635
- if (error.nodes) {
3636
- for (var _i2 = 0, _error$nodes2 = error.nodes; _i2 < _error$nodes2.length; _i2++) {
3637
- var node = _error$nodes2[_i2];
3608
+ if (this.locations != null) {
3609
+ formattedError.locations = this.locations;
3610
+ }
3638
3611
 
3639
- if (node.loc) {
3640
- output += '\n\n' + printLocation(node.loc);
3641
- }
3612
+ if (this.path != null) {
3613
+ formattedError.path = this.path;
3642
3614
  }
3643
- } else if (error.source && error.locations) {
3644
- for (var _i4 = 0, _error$locations2 = error.locations; _i4 < _error$locations2.length; _i4++) {
3645
- var location = _error$locations2[_i4];
3646
- output += '\n\n' + printSourceLocation(error.source, location);
3615
+
3616
+ if (this.extensions != null && Object.keys(this.extensions).length > 0) {
3617
+ formattedError.extensions = this.extensions;
3647
3618
  }
3619
+
3620
+ return formattedError;
3648
3621
  }
3622
+ }
3649
3623
 
3650
- return output;
3624
+ function undefinedIfEmpty(array) {
3625
+ return array === undefined || array.length === 0 ? undefined : array;
3651
3626
  }
3652
3627
 
3653
3628
  /**
@@ -3656,103 +3631,16 @@ function printError(error) {
3656
3631
  */
3657
3632
 
3658
3633
  function syntaxError(source, position, description) {
3659
- return new GraphQLError("Syntax Error: ".concat(description), undefined, source, [position]);
3660
- }
3661
-
3662
- /**
3663
- * The set of allowed kind values for AST nodes.
3664
- */
3665
- var Kind = Object.freeze({
3666
- // Name
3667
- NAME: 'Name',
3668
- // Document
3669
- DOCUMENT: 'Document',
3670
- OPERATION_DEFINITION: 'OperationDefinition',
3671
- VARIABLE_DEFINITION: 'VariableDefinition',
3672
- SELECTION_SET: 'SelectionSet',
3673
- FIELD: 'Field',
3674
- ARGUMENT: 'Argument',
3675
- // Fragments
3676
- FRAGMENT_SPREAD: 'FragmentSpread',
3677
- INLINE_FRAGMENT: 'InlineFragment',
3678
- FRAGMENT_DEFINITION: 'FragmentDefinition',
3679
- // Values
3680
- VARIABLE: 'Variable',
3681
- INT: 'IntValue',
3682
- FLOAT: 'FloatValue',
3683
- STRING: 'StringValue',
3684
- BOOLEAN: 'BooleanValue',
3685
- NULL: 'NullValue',
3686
- ENUM: 'EnumValue',
3687
- LIST: 'ListValue',
3688
- OBJECT: 'ObjectValue',
3689
- OBJECT_FIELD: 'ObjectField',
3690
- // Directives
3691
- DIRECTIVE: 'Directive',
3692
- // Types
3693
- NAMED_TYPE: 'NamedType',
3694
- LIST_TYPE: 'ListType',
3695
- NON_NULL_TYPE: 'NonNullType',
3696
- // Type System Definitions
3697
- SCHEMA_DEFINITION: 'SchemaDefinition',
3698
- OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition',
3699
- // Type Definitions
3700
- SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition',
3701
- OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition',
3702
- FIELD_DEFINITION: 'FieldDefinition',
3703
- INPUT_VALUE_DEFINITION: 'InputValueDefinition',
3704
- INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition',
3705
- UNION_TYPE_DEFINITION: 'UnionTypeDefinition',
3706
- ENUM_TYPE_DEFINITION: 'EnumTypeDefinition',
3707
- ENUM_VALUE_DEFINITION: 'EnumValueDefinition',
3708
- INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition',
3709
- // Directive Definitions
3710
- DIRECTIVE_DEFINITION: 'DirectiveDefinition',
3711
- // Type System Extensions
3712
- SCHEMA_EXTENSION: 'SchemaExtension',
3713
- // Type Extensions
3714
- SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension',
3715
- OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension',
3716
- INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension',
3717
- UNION_TYPE_EXTENSION: 'UnionTypeExtension',
3718
- ENUM_TYPE_EXTENSION: 'EnumTypeExtension',
3719
- INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension'
3720
- });
3721
- /**
3722
- * The enum type representing the possible kind values of AST nodes.
3723
- */
3724
-
3725
- function invariant(condition, message) {
3726
- var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')
3727
-
3728
- if (!booleanCondition) {
3729
- throw new Error(message != null ? message : 'Unexpected invariant triggered.');
3730
- }
3731
- }
3732
-
3733
- // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
3734
- var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
3735
- var nodejsCustomInspectSymbol$1 = nodejsCustomInspectSymbol;
3736
-
3737
- /**
3738
- * The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
3739
- */
3740
-
3741
- function defineInspect(classObject) {
3742
- var fn = classObject.prototype.toJSON;
3743
- typeof fn === 'function' || invariant(0);
3744
- classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
3745
-
3746
- if (nodejsCustomInspectSymbol$1) {
3747
- classObject.prototype[nodejsCustomInspectSymbol$1] = fn;
3748
- }
3634
+ return new GraphQLError(`Syntax Error: ${description}`, undefined, source, [
3635
+ position,
3636
+ ]);
3749
3637
  }
3750
3638
 
3751
3639
  /**
3752
3640
  * Contains a range of UTF-8 character offsets and token references that
3753
3641
  * identify the region of the source from which the AST derived.
3754
3642
  */
3755
- var Location = /*#__PURE__*/function () {
3643
+ class Location {
3756
3644
  /**
3757
3645
  * The character offset at which this Node begins.
3758
3646
  */
@@ -3772,7 +3660,7 @@ var Location = /*#__PURE__*/function () {
3772
3660
  /**
3773
3661
  * The Source document the AST represents.
3774
3662
  */
3775
- function Location(startToken, endToken, source) {
3663
+ constructor(startToken, endToken, source) {
3776
3664
  this.start = startToken.start;
3777
3665
  this.end = endToken.end;
3778
3666
  this.startToken = startToken;
@@ -3780,25 +3668,23 @@ var Location = /*#__PURE__*/function () {
3780
3668
  this.source = source;
3781
3669
  }
3782
3670
 
3783
- var _proto = Location.prototype;
3671
+ get [Symbol.toStringTag]() {
3672
+ return 'Location';
3673
+ }
3784
3674
 
3785
- _proto.toJSON = function toJSON() {
3675
+ toJSON() {
3786
3676
  return {
3787
3677
  start: this.start,
3788
- end: this.end
3678
+ end: this.end,
3789
3679
  };
3790
- };
3791
-
3792
- return Location;
3793
- }(); // Print a simplified form when appearing in `inspect` and `util.inspect`.
3794
-
3795
- defineInspect(Location);
3680
+ }
3681
+ }
3796
3682
  /**
3797
3683
  * Represents a range of characters represented by a lexical token
3798
3684
  * within a Source.
3799
3685
  */
3800
3686
 
3801
- var Token = /*#__PURE__*/function () {
3687
+ class Token {
3802
3688
  /**
3803
3689
  * The kind of Token.
3804
3690
  */
@@ -3821,6 +3707,9 @@ var Token = /*#__PURE__*/function () {
3821
3707
 
3822
3708
  /**
3823
3709
  * For non-punctuation tokens, represents the interpreted value of the token.
3710
+ *
3711
+ * Note: is undefined for punctuation tokens, but typed as string for
3712
+ * convenience in the parser.
3824
3713
  */
3825
3714
 
3826
3715
  /**
@@ -3828,403 +3717,288 @@ var Token = /*#__PURE__*/function () {
3828
3717
  * including ignored tokens. <SOF> is always the first node and <EOF>
3829
3718
  * the last.
3830
3719
  */
3831
- function Token(kind, start, end, line, column, prev, value) {
3720
+ constructor(kind, start, end, line, column, value) {
3832
3721
  this.kind = kind;
3833
3722
  this.start = start;
3834
3723
  this.end = end;
3835
3724
  this.line = line;
3836
- this.column = column;
3725
+ this.column = column; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3726
+
3837
3727
  this.value = value;
3838
- this.prev = prev;
3728
+ this.prev = null;
3839
3729
  this.next = null;
3840
3730
  }
3841
3731
 
3842
- var _proto2 = Token.prototype;
3732
+ get [Symbol.toStringTag]() {
3733
+ return 'Token';
3734
+ }
3843
3735
 
3844
- _proto2.toJSON = function toJSON() {
3736
+ toJSON() {
3845
3737
  return {
3846
3738
  kind: this.kind,
3847
3739
  value: this.value,
3848
3740
  line: this.line,
3849
- column: this.column
3741
+ column: this.column,
3850
3742
  };
3851
- };
3743
+ }
3744
+ }
3745
+ /** Name */
3746
+
3747
+ let OperationTypeNode;
3852
3748
 
3853
- return Token;
3854
- }(); // Print a simplified form when appearing in `inspect` and `util.inspect`.
3749
+ (function (OperationTypeNode) {
3750
+ OperationTypeNode['QUERY'] = 'query';
3751
+ OperationTypeNode['MUTATION'] = 'mutation';
3752
+ OperationTypeNode['SUBSCRIPTION'] = 'subscription';
3753
+ })(OperationTypeNode || (OperationTypeNode = {}));
3855
3754
 
3856
- defineInspect(Token);
3857
3755
  /**
3858
- * The list of all possible AST node types.
3756
+ * The set of allowed directive location values.
3757
+ */
3758
+ let DirectiveLocation;
3759
+ /**
3760
+ * The enum type representing the directive location values.
3761
+ *
3762
+ * @deprecated Please use `DirectiveLocation`. Will be remove in v17.
3859
3763
  */
3860
3764
 
3765
+ (function (DirectiveLocation) {
3766
+ DirectiveLocation['QUERY'] = 'QUERY';
3767
+ DirectiveLocation['MUTATION'] = 'MUTATION';
3768
+ DirectiveLocation['SUBSCRIPTION'] = 'SUBSCRIPTION';
3769
+ DirectiveLocation['FIELD'] = 'FIELD';
3770
+ DirectiveLocation['FRAGMENT_DEFINITION'] = 'FRAGMENT_DEFINITION';
3771
+ DirectiveLocation['FRAGMENT_SPREAD'] = 'FRAGMENT_SPREAD';
3772
+ DirectiveLocation['INLINE_FRAGMENT'] = 'INLINE_FRAGMENT';
3773
+ DirectiveLocation['VARIABLE_DEFINITION'] = 'VARIABLE_DEFINITION';
3774
+ DirectiveLocation['SCHEMA'] = 'SCHEMA';
3775
+ DirectiveLocation['SCALAR'] = 'SCALAR';
3776
+ DirectiveLocation['OBJECT'] = 'OBJECT';
3777
+ DirectiveLocation['FIELD_DEFINITION'] = 'FIELD_DEFINITION';
3778
+ DirectiveLocation['ARGUMENT_DEFINITION'] = 'ARGUMENT_DEFINITION';
3779
+ DirectiveLocation['INTERFACE'] = 'INTERFACE';
3780
+ DirectiveLocation['UNION'] = 'UNION';
3781
+ DirectiveLocation['ENUM'] = 'ENUM';
3782
+ DirectiveLocation['ENUM_VALUE'] = 'ENUM_VALUE';
3783
+ DirectiveLocation['INPUT_OBJECT'] = 'INPUT_OBJECT';
3784
+ DirectiveLocation['INPUT_FIELD_DEFINITION'] = 'INPUT_FIELD_DEFINITION';
3785
+ })(DirectiveLocation || (DirectiveLocation = {}));
3786
+
3861
3787
  /**
3862
- * An exported enum describing the different kinds of tokens that the
3863
- * lexer emits.
3788
+ * The set of allowed kind values for AST nodes.
3864
3789
  */
3865
- var TokenKind = Object.freeze({
3866
- SOF: '<SOF>',
3867
- EOF: '<EOF>',
3868
- BANG: '!',
3869
- DOLLAR: '$',
3870
- AMP: '&',
3871
- PAREN_L: '(',
3872
- PAREN_R: ')',
3873
- SPREAD: '...',
3874
- COLON: ':',
3875
- EQUALS: '=',
3876
- AT: '@',
3877
- BRACKET_L: '[',
3878
- BRACKET_R: ']',
3879
- BRACE_L: '{',
3880
- PIPE: '|',
3881
- BRACE_R: '}',
3882
- NAME: 'Name',
3883
- INT: 'Int',
3884
- FLOAT: 'Float',
3885
- STRING: 'String',
3886
- BLOCK_STRING: 'BlockString',
3887
- COMMENT: 'Comment'
3888
- });
3790
+ let Kind;
3889
3791
  /**
3890
- * The enum type representing the token kinds values.
3792
+ * The enum type representing the possible kind values of AST nodes.
3793
+ *
3794
+ * @deprecated Please use `Kind`. Will be remove in v17.
3891
3795
  */
3892
3796
 
3893
- function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
3894
- var MAX_ARRAY_LENGTH = 10;
3895
- var MAX_RECURSIVE_DEPTH = 2;
3797
+ (function (Kind) {
3798
+ Kind['NAME'] = 'Name';
3799
+ Kind['DOCUMENT'] = 'Document';
3800
+ Kind['OPERATION_DEFINITION'] = 'OperationDefinition';
3801
+ Kind['VARIABLE_DEFINITION'] = 'VariableDefinition';
3802
+ Kind['SELECTION_SET'] = 'SelectionSet';
3803
+ Kind['FIELD'] = 'Field';
3804
+ Kind['ARGUMENT'] = 'Argument';
3805
+ Kind['FRAGMENT_SPREAD'] = 'FragmentSpread';
3806
+ Kind['INLINE_FRAGMENT'] = 'InlineFragment';
3807
+ Kind['FRAGMENT_DEFINITION'] = 'FragmentDefinition';
3808
+ Kind['VARIABLE'] = 'Variable';
3809
+ Kind['INT'] = 'IntValue';
3810
+ Kind['FLOAT'] = 'FloatValue';
3811
+ Kind['STRING'] = 'StringValue';
3812
+ Kind['BOOLEAN'] = 'BooleanValue';
3813
+ Kind['NULL'] = 'NullValue';
3814
+ Kind['ENUM'] = 'EnumValue';
3815
+ Kind['LIST'] = 'ListValue';
3816
+ Kind['OBJECT'] = 'ObjectValue';
3817
+ Kind['OBJECT_FIELD'] = 'ObjectField';
3818
+ Kind['DIRECTIVE'] = 'Directive';
3819
+ Kind['NAMED_TYPE'] = 'NamedType';
3820
+ Kind['LIST_TYPE'] = 'ListType';
3821
+ Kind['NON_NULL_TYPE'] = 'NonNullType';
3822
+ Kind['SCHEMA_DEFINITION'] = 'SchemaDefinition';
3823
+ Kind['OPERATION_TYPE_DEFINITION'] = 'OperationTypeDefinition';
3824
+ Kind['SCALAR_TYPE_DEFINITION'] = 'ScalarTypeDefinition';
3825
+ Kind['OBJECT_TYPE_DEFINITION'] = 'ObjectTypeDefinition';
3826
+ Kind['FIELD_DEFINITION'] = 'FieldDefinition';
3827
+ Kind['INPUT_VALUE_DEFINITION'] = 'InputValueDefinition';
3828
+ Kind['INTERFACE_TYPE_DEFINITION'] = 'InterfaceTypeDefinition';
3829
+ Kind['UNION_TYPE_DEFINITION'] = 'UnionTypeDefinition';
3830
+ Kind['ENUM_TYPE_DEFINITION'] = 'EnumTypeDefinition';
3831
+ Kind['ENUM_VALUE_DEFINITION'] = 'EnumValueDefinition';
3832
+ Kind['INPUT_OBJECT_TYPE_DEFINITION'] = 'InputObjectTypeDefinition';
3833
+ Kind['DIRECTIVE_DEFINITION'] = 'DirectiveDefinition';
3834
+ Kind['SCHEMA_EXTENSION'] = 'SchemaExtension';
3835
+ Kind['SCALAR_TYPE_EXTENSION'] = 'ScalarTypeExtension';
3836
+ Kind['OBJECT_TYPE_EXTENSION'] = 'ObjectTypeExtension';
3837
+ Kind['INTERFACE_TYPE_EXTENSION'] = 'InterfaceTypeExtension';
3838
+ Kind['UNION_TYPE_EXTENSION'] = 'UnionTypeExtension';
3839
+ Kind['ENUM_TYPE_EXTENSION'] = 'EnumTypeExtension';
3840
+ Kind['INPUT_OBJECT_TYPE_EXTENSION'] = 'InputObjectTypeExtension';
3841
+ })(Kind || (Kind = {}));
3842
+
3896
3843
  /**
3897
- * Used to print values in error messages.
3844
+ * ```
3845
+ * WhiteSpace ::
3846
+ * - "Horizontal Tab (U+0009)"
3847
+ * - "Space (U+0020)"
3848
+ * ```
3849
+ * @internal
3898
3850
  */
3899
-
3900
- function inspect(value) {
3901
- return formatValue(value, []);
3851
+ function isWhiteSpace(code) {
3852
+ return code === 0x0009 || code === 0x0020;
3902
3853
  }
3854
+ /**
3855
+ * ```
3856
+ * Digit :: one of
3857
+ * - `0` `1` `2` `3` `4` `5` `6` `7` `8` `9`
3858
+ * ```
3859
+ * @internal
3860
+ */
3903
3861
 
3904
- function formatValue(value, seenValues) {
3905
- switch (_typeof$1(value)) {
3906
- case 'string':
3907
- return JSON.stringify(value);
3908
-
3909
- case 'function':
3910
- return value.name ? "[function ".concat(value.name, "]") : '[function]';
3911
-
3912
- case 'object':
3913
- if (value === null) {
3914
- return 'null';
3915
- }
3916
-
3917
- return formatObjectValue(value, seenValues);
3918
-
3919
- default:
3920
- return String(value);
3921
- }
3862
+ function isDigit(code) {
3863
+ return code >= 0x0030 && code <= 0x0039;
3922
3864
  }
3865
+ /**
3866
+ * ```
3867
+ * Letter :: one of
3868
+ * - `A` `B` `C` `D` `E` `F` `G` `H` `I` `J` `K` `L` `M`
3869
+ * - `N` `O` `P` `Q` `R` `S` `T` `U` `V` `W` `X` `Y` `Z`
3870
+ * - `a` `b` `c` `d` `e` `f` `g` `h` `i` `j` `k` `l` `m`
3871
+ * - `n` `o` `p` `q` `r` `s` `t` `u` `v` `w` `x` `y` `z`
3872
+ * ```
3873
+ * @internal
3874
+ */
3923
3875
 
3924
- function formatObjectValue(value, previouslySeenValues) {
3925
- if (previouslySeenValues.indexOf(value) !== -1) {
3926
- return '[Circular]';
3927
- }
3928
-
3929
- var seenValues = [].concat(previouslySeenValues, [value]);
3930
- var customInspectFn = getCustomFn(value);
3931
-
3932
- if (customInspectFn !== undefined) {
3933
- var customValue = customInspectFn.call(value); // check for infinite recursion
3934
-
3935
- if (customValue !== value) {
3936
- return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues);
3937
- }
3938
- } else if (Array.isArray(value)) {
3939
- return formatArray(value, seenValues);
3940
- }
3941
-
3942
- return formatObject(value, seenValues);
3876
+ function isLetter(code) {
3877
+ return (
3878
+ (code >= 0x0061 && code <= 0x007a) || // A-Z
3879
+ (code >= 0x0041 && code <= 0x005a) // a-z
3880
+ );
3943
3881
  }
3882
+ /**
3883
+ * ```
3884
+ * NameStart ::
3885
+ * - Letter
3886
+ * - `_`
3887
+ * ```
3888
+ * @internal
3889
+ */
3944
3890
 
3945
- function formatObject(object, seenValues) {
3946
- var keys = Object.keys(object);
3947
-
3948
- if (keys.length === 0) {
3949
- return '{}';
3950
- }
3951
-
3952
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
3953
- return '[' + getObjectTag(object) + ']';
3954
- }
3891
+ function isNameStart(code) {
3892
+ return isLetter(code) || code === 0x005f;
3893
+ }
3894
+ /**
3895
+ * ```
3896
+ * NameContinue ::
3897
+ * - Letter
3898
+ * - Digit
3899
+ * - `_`
3900
+ * ```
3901
+ * @internal
3902
+ */
3955
3903
 
3956
- var properties = keys.map(function (key) {
3957
- var value = formatValue(object[key], seenValues);
3958
- return key + ': ' + value;
3959
- });
3960
- return '{ ' + properties.join(', ') + ' }';
3904
+ function isNameContinue(code) {
3905
+ return isLetter(code) || isDigit(code) || code === 0x005f;
3961
3906
  }
3962
3907
 
3963
- function formatArray(array, seenValues) {
3964
- if (array.length === 0) {
3965
- return '[]';
3966
- }
3908
+ /**
3909
+ * Produces the value of a block string from its parsed raw value, similar to
3910
+ * CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
3911
+ *
3912
+ * This implements the GraphQL spec's BlockStringValue() static algorithm.
3913
+ *
3914
+ * @internal
3915
+ */
3967
3916
 
3968
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
3969
- return '[Array]';
3970
- }
3917
+ function dedentBlockStringLines(lines) {
3918
+ var _firstNonEmptyLine2;
3971
3919
 
3972
- var len = Math.min(MAX_ARRAY_LENGTH, array.length);
3973
- var remaining = array.length - len;
3974
- var items = [];
3920
+ let commonIndent = Number.MAX_SAFE_INTEGER;
3921
+ let firstNonEmptyLine = null;
3922
+ let lastNonEmptyLine = -1;
3975
3923
 
3976
- for (var i = 0; i < len; ++i) {
3977
- items.push(formatValue(array[i], seenValues));
3978
- }
3924
+ for (let i = 0; i < lines.length; ++i) {
3925
+ var _firstNonEmptyLine;
3979
3926
 
3980
- if (remaining === 1) {
3981
- items.push('... 1 more item');
3982
- } else if (remaining > 1) {
3983
- items.push("... ".concat(remaining, " more items"));
3984
- }
3927
+ const line = lines[i];
3928
+ const indent = leadingWhitespace(line);
3985
3929
 
3986
- return '[' + items.join(', ') + ']';
3987
- }
3930
+ if (indent === line.length) {
3931
+ continue; // skip empty lines
3932
+ }
3988
3933
 
3989
- function getCustomFn(object) {
3990
- var customInspectFn = object[String(nodejsCustomInspectSymbol$1)];
3934
+ firstNonEmptyLine =
3935
+ (_firstNonEmptyLine = firstNonEmptyLine) !== null &&
3936
+ _firstNonEmptyLine !== void 0
3937
+ ? _firstNonEmptyLine
3938
+ : i;
3939
+ lastNonEmptyLine = i;
3991
3940
 
3992
- if (typeof customInspectFn === 'function') {
3993
- return customInspectFn;
3941
+ if (i !== 0 && indent < commonIndent) {
3942
+ commonIndent = indent;
3943
+ }
3994
3944
  }
3995
3945
 
3996
- if (typeof object.inspect === 'function') {
3997
- return object.inspect;
3998
- }
3946
+ return lines // Remove common indentation from all lines but first.
3947
+ .map((line, i) => (i === 0 ? line : line.slice(commonIndent))) // Remove leading and trailing blank lines.
3948
+ .slice(
3949
+ (_firstNonEmptyLine2 = firstNonEmptyLine) !== null &&
3950
+ _firstNonEmptyLine2 !== void 0
3951
+ ? _firstNonEmptyLine2
3952
+ : 0,
3953
+ lastNonEmptyLine + 1,
3954
+ );
3999
3955
  }
4000
3956
 
4001
- function getObjectTag(object) {
4002
- var tag = Object.prototype.toString.call(object).replace(/^\[object /, '').replace(/]$/, '');
4003
-
4004
- if (tag === 'Object' && typeof object.constructor === 'function') {
4005
- var name = object.constructor.name;
3957
+ function leadingWhitespace(str) {
3958
+ let i = 0;
4006
3959
 
4007
- if (typeof name === 'string' && name !== '') {
4008
- return name;
4009
- }
3960
+ while (i < str.length && isWhiteSpace(str.charCodeAt(i))) {
3961
+ ++i;
4010
3962
  }
4011
3963
 
4012
- return tag;
3964
+ return i;
4013
3965
  }
4014
3966
 
4015
- function devAssert(condition, message) {
4016
- var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')
3967
+ /**
3968
+ * An exported enum describing the different kinds of tokens that the
3969
+ * lexer emits.
3970
+ */
3971
+ let TokenKind;
3972
+ /**
3973
+ * The enum type representing the token kinds values.
3974
+ *
3975
+ * @deprecated Please use `TokenKind`. Will be remove in v17.
3976
+ */
4017
3977
 
4018
- if (!booleanCondition) {
4019
- throw new Error(message);
4020
- }
4021
- }
4022
-
4023
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4024
- /**
4025
- * A replacement for instanceof which includes an error warning when multi-realm
4026
- * constructors are detected.
4027
- */
4028
-
4029
- // See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
4030
- // See: https://webpack.js.org/guides/production/
4031
- var instanceOf = process.env.NODE_ENV === 'production' ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
4032
- // eslint-disable-next-line no-shadow
4033
- function instanceOf(value, constructor) {
4034
- return value instanceof constructor;
4035
- } : // eslint-disable-next-line no-shadow
4036
- function instanceOf(value, constructor) {
4037
- if (value instanceof constructor) {
4038
- return true;
4039
- }
4040
-
4041
- if (_typeof(value) === 'object' && value !== null) {
4042
- var _value$constructor;
4043
-
4044
- var className = constructor.prototype[Symbol.toStringTag];
4045
- var valueClassName = // We still need to support constructor's name to detect conflicts with older versions of this library.
4046
- Symbol.toStringTag in value ? value[Symbol.toStringTag] : (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name;
4047
-
4048
- if (className === valueClassName) {
4049
- var stringifiedValue = inspect(value);
4050
- throw new Error("Cannot use ".concat(className, " \"").concat(stringifiedValue, "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));
4051
- }
4052
- }
4053
-
4054
- return false;
4055
- };
4056
-
4057
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4058
-
4059
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
4060
-
4061
- /**
4062
- * A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
4063
- * optional, but they are useful for clients who store GraphQL documents in source files.
4064
- * For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
4065
- * be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
4066
- * The `line` and `column` properties in `locationOffset` are 1-indexed.
4067
- */
4068
- var Source = /*#__PURE__*/function () {
4069
- function Source(body) {
4070
- var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GraphQL request';
4071
- var locationOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
4072
- line: 1,
4073
- column: 1
4074
- };
4075
- typeof body === 'string' || devAssert(0, "Body must be a string. Received: ".concat(inspect(body), "."));
4076
- this.body = body;
4077
- this.name = name;
4078
- this.locationOffset = locationOffset;
4079
- this.locationOffset.line > 0 || devAssert(0, 'line in locationOffset is 1-indexed and must be positive.');
4080
- this.locationOffset.column > 0 || devAssert(0, 'column in locationOffset is 1-indexed and must be positive.');
4081
- } // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
4082
-
4083
-
4084
- _createClass(Source, [{
4085
- key: SYMBOL_TO_STRING_TAG,
4086
- get: function get() {
4087
- return 'Source';
4088
- }
4089
- }]);
4090
-
4091
- return Source;
4092
- }();
4093
- /**
4094
- * Test if the given value is a Source object.
4095
- *
4096
- * @internal
4097
- */
4098
-
4099
- // eslint-disable-next-line no-redeclare
4100
- function isSource(source) {
4101
- return instanceOf(source, Source);
4102
- }
4103
-
4104
- /**
4105
- * The set of allowed directive location values.
4106
- */
4107
- var DirectiveLocation = Object.freeze({
4108
- // Request Definitions
4109
- QUERY: 'QUERY',
4110
- MUTATION: 'MUTATION',
4111
- SUBSCRIPTION: 'SUBSCRIPTION',
4112
- FIELD: 'FIELD',
4113
- FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION',
4114
- FRAGMENT_SPREAD: 'FRAGMENT_SPREAD',
4115
- INLINE_FRAGMENT: 'INLINE_FRAGMENT',
4116
- VARIABLE_DEFINITION: 'VARIABLE_DEFINITION',
4117
- // Type System Definitions
4118
- SCHEMA: 'SCHEMA',
4119
- SCALAR: 'SCALAR',
4120
- OBJECT: 'OBJECT',
4121
- FIELD_DEFINITION: 'FIELD_DEFINITION',
4122
- ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION',
4123
- INTERFACE: 'INTERFACE',
4124
- UNION: 'UNION',
4125
- ENUM: 'ENUM',
4126
- ENUM_VALUE: 'ENUM_VALUE',
4127
- INPUT_OBJECT: 'INPUT_OBJECT',
4128
- INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION'
4129
- });
4130
- /**
4131
- * The enum type representing the directive location values.
4132
- */
4133
-
4134
- /**
4135
- * Produces the value of a block string from its parsed raw value, similar to
4136
- * CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
4137
- *
4138
- * This implements the GraphQL spec's BlockStringValue() static algorithm.
4139
- *
4140
- * @internal
4141
- */
4142
- function dedentBlockStringValue(rawString) {
4143
- // Expand a block string's raw value into independent lines.
4144
- var lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first.
4145
-
4146
- var commonIndent = getBlockStringIndentation(rawString);
4147
-
4148
- if (commonIndent !== 0) {
4149
- for (var i = 1; i < lines.length; i++) {
4150
- lines[i] = lines[i].slice(commonIndent);
4151
- }
4152
- } // Remove leading and trailing blank lines.
4153
-
4154
-
4155
- var startLine = 0;
4156
-
4157
- while (startLine < lines.length && isBlank(lines[startLine])) {
4158
- ++startLine;
4159
- }
4160
-
4161
- var endLine = lines.length;
4162
-
4163
- while (endLine > startLine && isBlank(lines[endLine - 1])) {
4164
- --endLine;
4165
- } // Return a string of the lines joined with U+000A.
4166
-
4167
-
4168
- return lines.slice(startLine, endLine).join('\n');
4169
- }
4170
-
4171
- function isBlank(str) {
4172
- for (var i = 0; i < str.length; ++i) {
4173
- if (str[i] !== ' ' && str[i] !== '\t') {
4174
- return false;
4175
- }
4176
- }
4177
-
4178
- return true;
4179
- }
4180
- /**
4181
- * @internal
4182
- */
4183
-
4184
-
4185
- function getBlockStringIndentation(value) {
4186
- var _commonIndent;
4187
-
4188
- var isFirstLine = true;
4189
- var isEmptyLine = true;
4190
- var indent = 0;
4191
- var commonIndent = null;
4192
-
4193
- for (var i = 0; i < value.length; ++i) {
4194
- switch (value.charCodeAt(i)) {
4195
- case 13:
4196
- // \r
4197
- if (value.charCodeAt(i + 1) === 10) {
4198
- ++i; // skip \r\n as one symbol
4199
- }
4200
-
4201
- // falls through
4202
-
4203
- case 10:
4204
- // \n
4205
- isFirstLine = false;
4206
- isEmptyLine = true;
4207
- indent = 0;
4208
- break;
4209
-
4210
- case 9: // \t
4211
-
4212
- case 32:
4213
- // <space>
4214
- ++indent;
4215
- break;
4216
-
4217
- default:
4218
- if (isEmptyLine && !isFirstLine && (commonIndent === null || indent < commonIndent)) {
4219
- commonIndent = indent;
4220
- }
4221
-
4222
- isEmptyLine = false;
4223
- }
4224
- }
4225
-
4226
- return (_commonIndent = commonIndent) !== null && _commonIndent !== void 0 ? _commonIndent : 0;
4227
- }
3978
+ (function (TokenKind) {
3979
+ TokenKind['SOF'] = '<SOF>';
3980
+ TokenKind['EOF'] = '<EOF>';
3981
+ TokenKind['BANG'] = '!';
3982
+ TokenKind['DOLLAR'] = '$';
3983
+ TokenKind['AMP'] = '&';
3984
+ TokenKind['PAREN_L'] = '(';
3985
+ TokenKind['PAREN_R'] = ')';
3986
+ TokenKind['SPREAD'] = '...';
3987
+ TokenKind['COLON'] = ':';
3988
+ TokenKind['EQUALS'] = '=';
3989
+ TokenKind['AT'] = '@';
3990
+ TokenKind['BRACKET_L'] = '[';
3991
+ TokenKind['BRACKET_R'] = ']';
3992
+ TokenKind['BRACE_L'] = '{';
3993
+ TokenKind['PIPE'] = '|';
3994
+ TokenKind['BRACE_R'] = '}';
3995
+ TokenKind['NAME'] = 'Name';
3996
+ TokenKind['INT'] = 'Int';
3997
+ TokenKind['FLOAT'] = 'Float';
3998
+ TokenKind['STRING'] = 'String';
3999
+ TokenKind['BLOCK_STRING'] = 'BlockString';
4000
+ TokenKind['COMMENT'] = 'Comment';
4001
+ })(TokenKind || (TokenKind = {}));
4228
4002
 
4229
4003
  /**
4230
4004
  * Given a Source object, creates a Lexer for that source.
@@ -4235,7 +4009,7 @@ function getBlockStringIndentation(value) {
4235
4009
  * whenever called.
4236
4010
  */
4237
4011
 
4238
- var Lexer = /*#__PURE__*/function () {
4012
+ class Lexer {
4239
4013
  /**
4240
4014
  * The previously focused non-ignored token.
4241
4015
  */
@@ -4251,64 +4025,143 @@ var Lexer = /*#__PURE__*/function () {
4251
4025
  /**
4252
4026
  * The character offset at which the current line begins.
4253
4027
  */
4254
- function Lexer(source) {
4255
- var startOfFileToken = new Token(TokenKind.SOF, 0, 0, 0, 0, null);
4028
+ constructor(source) {
4029
+ const startOfFileToken = new Token(TokenKind.SOF, 0, 0, 0, 0);
4256
4030
  this.source = source;
4257
4031
  this.lastToken = startOfFileToken;
4258
4032
  this.token = startOfFileToken;
4259
4033
  this.line = 1;
4260
4034
  this.lineStart = 0;
4261
4035
  }
4036
+
4037
+ get [Symbol.toStringTag]() {
4038
+ return 'Lexer';
4039
+ }
4262
4040
  /**
4263
4041
  * Advances the token stream to the next non-ignored token.
4264
4042
  */
4265
4043
 
4266
-
4267
- var _proto = Lexer.prototype;
4268
-
4269
- _proto.advance = function advance() {
4044
+ advance() {
4270
4045
  this.lastToken = this.token;
4271
- var token = this.token = this.lookahead();
4046
+ const token = (this.token = this.lookahead());
4272
4047
  return token;
4273
4048
  }
4274
4049
  /**
4275
4050
  * Looks ahead and returns the next non-ignored token, but does not change
4276
4051
  * the state of Lexer.
4277
4052
  */
4278
- ;
4279
4053
 
4280
- _proto.lookahead = function lookahead() {
4281
- var token = this.token;
4054
+ lookahead() {
4055
+ let token = this.token;
4282
4056
 
4283
4057
  if (token.kind !== TokenKind.EOF) {
4284
4058
  do {
4285
- var _token$next;
4059
+ if (token.next) {
4060
+ token = token.next;
4061
+ } else {
4062
+ // Read the next token and form a link in the token linked-list.
4063
+ const nextToken = readNextToken(this, token.end); // @ts-expect-error next is only mutable during parsing.
4064
+
4065
+ token.next = nextToken; // @ts-expect-error prev is only mutable during parsing.
4286
4066
 
4287
- // Note: next is only mutable during parsing, so we cast to allow this.
4288
- token = (_token$next = token.next) !== null && _token$next !== void 0 ? _token$next : token.next = readToken(this, token);
4067
+ nextToken.prev = token;
4068
+ token = nextToken;
4069
+ }
4289
4070
  } while (token.kind === TokenKind.COMMENT);
4290
4071
  }
4291
4072
 
4292
4073
  return token;
4293
- };
4294
-
4295
- return Lexer;
4296
- }();
4074
+ }
4075
+ }
4297
4076
  /**
4298
4077
  * @internal
4299
4078
  */
4300
4079
 
4301
4080
  function isPunctuatorTokenKind(kind) {
4302
- return kind === TokenKind.BANG || kind === TokenKind.DOLLAR || kind === TokenKind.AMP || kind === TokenKind.PAREN_L || kind === TokenKind.PAREN_R || kind === TokenKind.SPREAD || kind === TokenKind.COLON || kind === TokenKind.EQUALS || kind === TokenKind.AT || kind === TokenKind.BRACKET_L || kind === TokenKind.BRACKET_R || kind === TokenKind.BRACE_L || kind === TokenKind.PIPE || kind === TokenKind.BRACE_R;
4081
+ return (
4082
+ kind === TokenKind.BANG ||
4083
+ kind === TokenKind.DOLLAR ||
4084
+ kind === TokenKind.AMP ||
4085
+ kind === TokenKind.PAREN_L ||
4086
+ kind === TokenKind.PAREN_R ||
4087
+ kind === TokenKind.SPREAD ||
4088
+ kind === TokenKind.COLON ||
4089
+ kind === TokenKind.EQUALS ||
4090
+ kind === TokenKind.AT ||
4091
+ kind === TokenKind.BRACKET_L ||
4092
+ kind === TokenKind.BRACKET_R ||
4093
+ kind === TokenKind.BRACE_L ||
4094
+ kind === TokenKind.PIPE ||
4095
+ kind === TokenKind.BRACE_R
4096
+ );
4303
4097
  }
4098
+ /**
4099
+ * A Unicode scalar value is any Unicode code point except surrogate code
4100
+ * points. In other words, the inclusive ranges of values 0x0000 to 0xD7FF and
4101
+ * 0xE000 to 0x10FFFF.
4102
+ *
4103
+ * SourceCharacter ::
4104
+ * - "Any Unicode scalar value"
4105
+ */
4106
+
4107
+ function isUnicodeScalarValue(code) {
4108
+ return (
4109
+ (code >= 0x0000 && code <= 0xd7ff) || (code >= 0xe000 && code <= 0x10ffff)
4110
+ );
4111
+ }
4112
+ /**
4113
+ * The GraphQL specification defines source text as a sequence of unicode scalar
4114
+ * values (which Unicode defines to exclude surrogate code points). However
4115
+ * JavaScript defines strings as a sequence of UTF-16 code units which may
4116
+ * include surrogates. A surrogate pair is a valid source character as it
4117
+ * encodes a supplementary code point (above U+FFFF), but unpaired surrogate
4118
+ * code points are not valid source characters.
4119
+ */
4304
4120
 
4305
- function printCharCode(code) {
4306
- return (// NaN/undefined represents access beyond the end of the file.
4307
- isNaN(code) ? TokenKind.EOF : // Trust JSON for ASCII.
4308
- code < 0x007f ? JSON.stringify(String.fromCharCode(code)) : // Otherwise print the escaped form.
4309
- "\"\\u".concat(('00' + code.toString(16).toUpperCase()).slice(-4), "\"")
4121
+ function isSupplementaryCodePoint(body, location) {
4122
+ return (
4123
+ isLeadingSurrogate(body.charCodeAt(location)) &&
4124
+ isTrailingSurrogate(body.charCodeAt(location + 1))
4310
4125
  );
4311
4126
  }
4127
+
4128
+ function isLeadingSurrogate(code) {
4129
+ return code >= 0xd800 && code <= 0xdbff;
4130
+ }
4131
+
4132
+ function isTrailingSurrogate(code) {
4133
+ return code >= 0xdc00 && code <= 0xdfff;
4134
+ }
4135
+ /**
4136
+ * Prints the code point (or end of file reference) at a given location in a
4137
+ * source for use in error messages.
4138
+ *
4139
+ * Printable ASCII is printed quoted, while other points are printed in Unicode
4140
+ * code point form (ie. U+1234).
4141
+ */
4142
+
4143
+ function printCodePointAt(lexer, location) {
4144
+ const code = lexer.source.body.codePointAt(location);
4145
+
4146
+ if (code === undefined) {
4147
+ return TokenKind.EOF;
4148
+ } else if (code >= 0x0020 && code <= 0x007e) {
4149
+ // Printable ASCII
4150
+ const char = String.fromCodePoint(code);
4151
+ return char === '"' ? "'\"'" : `"${char}"`;
4152
+ } // Unicode code point
4153
+
4154
+ return 'U+' + code.toString(16).toUpperCase().padStart(4, '0');
4155
+ }
4156
+ /**
4157
+ * Create a token with line and column location information.
4158
+ */
4159
+
4160
+ function createToken(lexer, kind, start, end, value) {
4161
+ const line = lexer.line;
4162
+ const col = 1 + start - lexer.lineStart;
4163
+ return new Token(kind, start, end, line, col, value);
4164
+ }
4312
4165
  /**
4313
4166
  * Gets the next token from the source starting at the given position.
4314
4167
  *
@@ -4317,586 +4170,947 @@ function printCharCode(code) {
4317
4170
  * complicated tokens.
4318
4171
  */
4319
4172
 
4173
+ function readNextToken(lexer, start) {
4174
+ const body = lexer.source.body;
4175
+ const bodyLength = body.length;
4176
+ let position = start;
4320
4177
 
4321
- function readToken(lexer, prev) {
4322
- var source = lexer.source;
4323
- var body = source.body;
4324
- var bodyLength = body.length;
4325
- var pos = prev.end;
4326
-
4327
- while (pos < bodyLength) {
4328
- var code = body.charCodeAt(pos);
4329
- var _line = lexer.line;
4330
-
4331
- var _col = 1 + pos - lexer.lineStart; // SourceCharacter
4332
-
4178
+ while (position < bodyLength) {
4179
+ const code = body.charCodeAt(position); // SourceCharacter
4333
4180
 
4334
4181
  switch (code) {
4182
+ // Ignored ::
4183
+ // - UnicodeBOM
4184
+ // - WhiteSpace
4185
+ // - LineTerminator
4186
+ // - Comment
4187
+ // - Comma
4188
+ //
4189
+ // UnicodeBOM :: "Byte Order Mark (U+FEFF)"
4190
+ //
4191
+ // WhiteSpace ::
4192
+ // - "Horizontal Tab (U+0009)"
4193
+ // - "Space (U+0020)"
4194
+ //
4195
+ // Comma :: ,
4335
4196
  case 0xfeff: // <BOM>
4336
4197
 
4337
- case 9: // \t
4198
+ case 0x0009: // \t
4338
4199
 
4339
- case 32: // <space>
4200
+ case 0x0020: // <space>
4340
4201
 
4341
- case 44:
4342
- // ,
4343
- ++pos;
4202
+ case 0x002c:
4203
+ // ,
4204
+ ++position;
4344
4205
  continue;
4206
+ // LineTerminator ::
4207
+ // - "New Line (U+000A)"
4208
+ // - "Carriage Return (U+000D)" [lookahead != "New Line (U+000A)"]
4209
+ // - "Carriage Return (U+000D)" "New Line (U+000A)"
4345
4210
 
4346
- case 10:
4347
- // \n
4348
- ++pos;
4211
+ case 0x000a:
4212
+ // \n
4213
+ ++position;
4349
4214
  ++lexer.line;
4350
- lexer.lineStart = pos;
4215
+ lexer.lineStart = position;
4351
4216
  continue;
4352
4217
 
4353
- case 13:
4354
- // \r
4355
- if (body.charCodeAt(pos + 1) === 10) {
4356
- pos += 2;
4218
+ case 0x000d:
4219
+ // \r
4220
+ if (body.charCodeAt(position + 1) === 0x000a) {
4221
+ position += 2;
4357
4222
  } else {
4358
- ++pos;
4223
+ ++position;
4359
4224
  }
4360
4225
 
4361
4226
  ++lexer.line;
4362
- lexer.lineStart = pos;
4227
+ lexer.lineStart = position;
4363
4228
  continue;
4364
-
4365
- case 33:
4366
- // !
4367
- return new Token(TokenKind.BANG, pos, pos + 1, _line, _col, prev);
4368
-
4369
- case 35:
4370
- // #
4371
- return readComment(source, pos, _line, _col, prev);
4372
-
4373
- case 36:
4374
- // $
4375
- return new Token(TokenKind.DOLLAR, pos, pos + 1, _line, _col, prev);
4376
-
4377
- case 38:
4378
- // &
4379
- return new Token(TokenKind.AMP, pos, pos + 1, _line, _col, prev);
4380
-
4381
- case 40:
4382
- // (
4383
- return new Token(TokenKind.PAREN_L, pos, pos + 1, _line, _col, prev);
4384
-
4385
- case 41:
4386
- // )
4387
- return new Token(TokenKind.PAREN_R, pos, pos + 1, _line, _col, prev);
4388
-
4389
- case 46:
4390
- // .
4391
- if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) {
4392
- return new Token(TokenKind.SPREAD, pos, pos + 3, _line, _col, prev);
4229
+ // Comment
4230
+
4231
+ case 0x0023:
4232
+ // #
4233
+ return readComment(lexer, position);
4234
+ // Token ::
4235
+ // - Punctuator
4236
+ // - Name
4237
+ // - IntValue
4238
+ // - FloatValue
4239
+ // - StringValue
4240
+ //
4241
+ // Punctuator :: one of ! $ & ( ) ... : = @ [ ] { | }
4242
+
4243
+ case 0x0021:
4244
+ // !
4245
+ return createToken(lexer, TokenKind.BANG, position, position + 1);
4246
+
4247
+ case 0x0024:
4248
+ // $
4249
+ return createToken(lexer, TokenKind.DOLLAR, position, position + 1);
4250
+
4251
+ case 0x0026:
4252
+ // &
4253
+ return createToken(lexer, TokenKind.AMP, position, position + 1);
4254
+
4255
+ case 0x0028:
4256
+ // (
4257
+ return createToken(lexer, TokenKind.PAREN_L, position, position + 1);
4258
+
4259
+ case 0x0029:
4260
+ // )
4261
+ return createToken(lexer, TokenKind.PAREN_R, position, position + 1);
4262
+
4263
+ case 0x002e:
4264
+ // .
4265
+ if (
4266
+ body.charCodeAt(position + 1) === 0x002e &&
4267
+ body.charCodeAt(position + 2) === 0x002e
4268
+ ) {
4269
+ return createToken(lexer, TokenKind.SPREAD, position, position + 3);
4393
4270
  }
4394
4271
 
4395
4272
  break;
4396
4273
 
4397
- case 58:
4398
- // :
4399
- return new Token(TokenKind.COLON, pos, pos + 1, _line, _col, prev);
4274
+ case 0x003a:
4275
+ // :
4276
+ return createToken(lexer, TokenKind.COLON, position, position + 1);
4400
4277
 
4401
- case 61:
4402
- // =
4403
- return new Token(TokenKind.EQUALS, pos, pos + 1, _line, _col, prev);
4278
+ case 0x003d:
4279
+ // =
4280
+ return createToken(lexer, TokenKind.EQUALS, position, position + 1);
4404
4281
 
4405
- case 64:
4406
- // @
4407
- return new Token(TokenKind.AT, pos, pos + 1, _line, _col, prev);
4282
+ case 0x0040:
4283
+ // @
4284
+ return createToken(lexer, TokenKind.AT, position, position + 1);
4408
4285
 
4409
- case 91:
4410
- // [
4411
- return new Token(TokenKind.BRACKET_L, pos, pos + 1, _line, _col, prev);
4286
+ case 0x005b:
4287
+ // [
4288
+ return createToken(lexer, TokenKind.BRACKET_L, position, position + 1);
4412
4289
 
4413
- case 93:
4414
- // ]
4415
- return new Token(TokenKind.BRACKET_R, pos, pos + 1, _line, _col, prev);
4290
+ case 0x005d:
4291
+ // ]
4292
+ return createToken(lexer, TokenKind.BRACKET_R, position, position + 1);
4416
4293
 
4417
- case 123:
4294
+ case 0x007b:
4418
4295
  // {
4419
- return new Token(TokenKind.BRACE_L, pos, pos + 1, _line, _col, prev);
4296
+ return createToken(lexer, TokenKind.BRACE_L, position, position + 1);
4420
4297
 
4421
- case 124:
4298
+ case 0x007c:
4422
4299
  // |
4423
- return new Token(TokenKind.PIPE, pos, pos + 1, _line, _col, prev);
4300
+ return createToken(lexer, TokenKind.PIPE, position, position + 1);
4424
4301
 
4425
- case 125:
4302
+ case 0x007d:
4426
4303
  // }
4427
- return new Token(TokenKind.BRACE_R, pos, pos + 1, _line, _col, prev);
4428
-
4429
- case 34:
4430
- // "
4431
- if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) {
4432
- return readBlockString(source, pos, _line, _col, prev, lexer);
4304
+ return createToken(lexer, TokenKind.BRACE_R, position, position + 1);
4305
+ // StringValue
4306
+
4307
+ case 0x0022:
4308
+ // "
4309
+ if (
4310
+ body.charCodeAt(position + 1) === 0x0022 &&
4311
+ body.charCodeAt(position + 2) === 0x0022
4312
+ ) {
4313
+ return readBlockString(lexer, position);
4433
4314
  }
4434
4315
 
4435
- return readString(source, pos, _line, _col, prev);
4436
-
4437
- case 45: // -
4438
-
4439
- case 48: // 0
4440
-
4441
- case 49: // 1
4442
-
4443
- case 50: // 2
4444
-
4445
- case 51: // 3
4316
+ return readString(lexer, position);
4317
+ } // IntValue | FloatValue (Digit | -)
4446
4318
 
4447
- case 52: // 4
4319
+ if (isDigit(code) || code === 0x002d) {
4320
+ return readNumber(lexer, position, code);
4321
+ } // Name
4448
4322
 
4449
- case 53: // 5
4323
+ if (isNameStart(code)) {
4324
+ return readName(lexer, position);
4325
+ }
4450
4326
 
4451
- case 54: // 6
4327
+ throw syntaxError(
4328
+ lexer.source,
4329
+ position,
4330
+ code === 0x0027
4331
+ ? 'Unexpected single quote character (\'), did you mean to use a double quote (")?'
4332
+ : isUnicodeScalarValue(code) || isSupplementaryCodePoint(body, position)
4333
+ ? `Unexpected character: ${printCodePointAt(lexer, position)}.`
4334
+ : `Invalid character: ${printCodePointAt(lexer, position)}.`,
4335
+ );
4336
+ }
4452
4337
 
4453
- case 55: // 7
4338
+ return createToken(lexer, TokenKind.EOF, bodyLength, bodyLength);
4339
+ }
4340
+ /**
4341
+ * Reads a comment token from the source file.
4342
+ *
4343
+ * ```
4344
+ * Comment :: # CommentChar* [lookahead != CommentChar]
4345
+ *
4346
+ * CommentChar :: SourceCharacter but not LineTerminator
4347
+ * ```
4348
+ */
4454
4349
 
4455
- case 56: // 8
4350
+ function readComment(lexer, start) {
4351
+ const body = lexer.source.body;
4352
+ const bodyLength = body.length;
4353
+ let position = start + 1;
4456
4354
 
4457
- case 57:
4458
- // 9
4459
- return readNumber(source, pos, code, _line, _col, prev);
4355
+ while (position < bodyLength) {
4356
+ const code = body.charCodeAt(position); // LineTerminator (\n | \r)
4460
4357
 
4461
- case 65: // A
4358
+ if (code === 0x000a || code === 0x000d) {
4359
+ break;
4360
+ } // SourceCharacter
4462
4361
 
4463
- case 66: // B
4362
+ if (isUnicodeScalarValue(code)) {
4363
+ ++position;
4364
+ } else if (isSupplementaryCodePoint(body, position)) {
4365
+ position += 2;
4366
+ } else {
4367
+ break;
4368
+ }
4369
+ }
4464
4370
 
4465
- case 67: // C
4371
+ return createToken(
4372
+ lexer,
4373
+ TokenKind.COMMENT,
4374
+ start,
4375
+ position,
4376
+ body.slice(start + 1, position),
4377
+ );
4378
+ }
4379
+ /**
4380
+ * Reads a number token from the source file, either a FloatValue or an IntValue
4381
+ * depending on whether a FractionalPart or ExponentPart is encountered.
4382
+ *
4383
+ * ```
4384
+ * IntValue :: IntegerPart [lookahead != {Digit, `.`, NameStart}]
4385
+ *
4386
+ * IntegerPart ::
4387
+ * - NegativeSign? 0
4388
+ * - NegativeSign? NonZeroDigit Digit*
4389
+ *
4390
+ * NegativeSign :: -
4391
+ *
4392
+ * NonZeroDigit :: Digit but not `0`
4393
+ *
4394
+ * FloatValue ::
4395
+ * - IntegerPart FractionalPart ExponentPart [lookahead != {Digit, `.`, NameStart}]
4396
+ * - IntegerPart FractionalPart [lookahead != {Digit, `.`, NameStart}]
4397
+ * - IntegerPart ExponentPart [lookahead != {Digit, `.`, NameStart}]
4398
+ *
4399
+ * FractionalPart :: . Digit+
4400
+ *
4401
+ * ExponentPart :: ExponentIndicator Sign? Digit+
4402
+ *
4403
+ * ExponentIndicator :: one of `e` `E`
4404
+ *
4405
+ * Sign :: one of + -
4406
+ * ```
4407
+ */
4466
4408
 
4467
- case 68: // D
4409
+ function readNumber(lexer, start, firstCode) {
4410
+ const body = lexer.source.body;
4411
+ let position = start;
4412
+ let code = firstCode;
4413
+ let isFloat = false; // NegativeSign (-)
4468
4414
 
4469
- case 69: // E
4415
+ if (code === 0x002d) {
4416
+ code = body.charCodeAt(++position);
4417
+ } // Zero (0)
4470
4418
 
4471
- case 70: // F
4419
+ if (code === 0x0030) {
4420
+ code = body.charCodeAt(++position);
4472
4421
 
4473
- case 71: // G
4422
+ if (isDigit(code)) {
4423
+ throw syntaxError(
4424
+ lexer.source,
4425
+ position,
4426
+ `Invalid number, unexpected digit after 0: ${printCodePointAt(
4427
+ lexer,
4428
+ position,
4429
+ )}.`,
4430
+ );
4431
+ }
4432
+ } else {
4433
+ position = readDigits(lexer, position, code);
4434
+ code = body.charCodeAt(position);
4435
+ } // Full stop (.)
4474
4436
 
4475
- case 72: // H
4437
+ if (code === 0x002e) {
4438
+ isFloat = true;
4439
+ code = body.charCodeAt(++position);
4440
+ position = readDigits(lexer, position, code);
4441
+ code = body.charCodeAt(position);
4442
+ } // E e
4476
4443
 
4477
- case 73: // I
4444
+ if (code === 0x0045 || code === 0x0065) {
4445
+ isFloat = true;
4446
+ code = body.charCodeAt(++position); // + -
4478
4447
 
4479
- case 74: // J
4448
+ if (code === 0x002b || code === 0x002d) {
4449
+ code = body.charCodeAt(++position);
4450
+ }
4480
4451
 
4481
- case 75: // K
4452
+ position = readDigits(lexer, position, code);
4453
+ code = body.charCodeAt(position);
4454
+ } // Numbers cannot be followed by . or NameStart
4482
4455
 
4483
- case 76: // L
4456
+ if (code === 0x002e || isNameStart(code)) {
4457
+ throw syntaxError(
4458
+ lexer.source,
4459
+ position,
4460
+ `Invalid number, expected digit but got: ${printCodePointAt(
4461
+ lexer,
4462
+ position,
4463
+ )}.`,
4464
+ );
4465
+ }
4484
4466
 
4485
- case 77: // M
4467
+ return createToken(
4468
+ lexer,
4469
+ isFloat ? TokenKind.FLOAT : TokenKind.INT,
4470
+ start,
4471
+ position,
4472
+ body.slice(start, position),
4473
+ );
4474
+ }
4475
+ /**
4476
+ * Returns the new position in the source after reading one or more digits.
4477
+ */
4486
4478
 
4487
- case 78: // N
4479
+ function readDigits(lexer, start, firstCode) {
4480
+ if (!isDigit(firstCode)) {
4481
+ throw syntaxError(
4482
+ lexer.source,
4483
+ start,
4484
+ `Invalid number, expected digit but got: ${printCodePointAt(
4485
+ lexer,
4486
+ start,
4487
+ )}.`,
4488
+ );
4489
+ }
4488
4490
 
4489
- case 79: // O
4491
+ const body = lexer.source.body;
4492
+ let position = start + 1; // +1 to skip first firstCode
4490
4493
 
4491
- case 80: // P
4494
+ while (isDigit(body.charCodeAt(position))) {
4495
+ ++position;
4496
+ }
4492
4497
 
4493
- case 81: // Q
4498
+ return position;
4499
+ }
4500
+ /**
4501
+ * Reads a single-quote string token from the source file.
4502
+ *
4503
+ * ```
4504
+ * StringValue ::
4505
+ * - `""` [lookahead != `"`]
4506
+ * - `"` StringCharacter+ `"`
4507
+ *
4508
+ * StringCharacter ::
4509
+ * - SourceCharacter but not `"` or `\` or LineTerminator
4510
+ * - `\u` EscapedUnicode
4511
+ * - `\` EscapedCharacter
4512
+ *
4513
+ * EscapedUnicode ::
4514
+ * - `{` HexDigit+ `}`
4515
+ * - HexDigit HexDigit HexDigit HexDigit
4516
+ *
4517
+ * EscapedCharacter :: one of `"` `\` `/` `b` `f` `n` `r` `t`
4518
+ * ```
4519
+ */
4494
4520
 
4495
- case 82: // R
4521
+ function readString(lexer, start) {
4522
+ const body = lexer.source.body;
4523
+ const bodyLength = body.length;
4524
+ let position = start + 1;
4525
+ let chunkStart = position;
4526
+ let value = '';
4496
4527
 
4497
- case 83: // S
4528
+ while (position < bodyLength) {
4529
+ const code = body.charCodeAt(position); // Closing Quote (")
4498
4530
 
4499
- case 84: // T
4531
+ if (code === 0x0022) {
4532
+ value += body.slice(chunkStart, position);
4533
+ return createToken(lexer, TokenKind.STRING, start, position + 1, value);
4534
+ } // Escape Sequence (\)
4500
4535
 
4501
- case 85: // U
4536
+ if (code === 0x005c) {
4537
+ value += body.slice(chunkStart, position);
4538
+ const escape =
4539
+ body.charCodeAt(position + 1) === 0x0075 // u
4540
+ ? body.charCodeAt(position + 2) === 0x007b // {
4541
+ ? readEscapedUnicodeVariableWidth(lexer, position)
4542
+ : readEscapedUnicodeFixedWidth(lexer, position)
4543
+ : readEscapedCharacter(lexer, position);
4544
+ value += escape.value;
4545
+ position += escape.size;
4546
+ chunkStart = position;
4547
+ continue;
4548
+ } // LineTerminator (\n | \r)
4502
4549
 
4503
- case 86: // V
4550
+ if (code === 0x000a || code === 0x000d) {
4551
+ break;
4552
+ } // SourceCharacter
4504
4553
 
4505
- case 87: // W
4554
+ if (isUnicodeScalarValue(code)) {
4555
+ ++position;
4556
+ } else if (isSupplementaryCodePoint(body, position)) {
4557
+ position += 2;
4558
+ } else {
4559
+ throw syntaxError(
4560
+ lexer.source,
4561
+ position,
4562
+ `Invalid character within String: ${printCodePointAt(
4563
+ lexer,
4564
+ position,
4565
+ )}.`,
4566
+ );
4567
+ }
4568
+ }
4506
4569
 
4507
- case 88: // X
4570
+ throw syntaxError(lexer.source, position, 'Unterminated string.');
4571
+ } // The string value and lexed size of an escape sequence.
4508
4572
 
4509
- case 89: // Y
4573
+ function readEscapedUnicodeVariableWidth(lexer, position) {
4574
+ const body = lexer.source.body;
4575
+ let point = 0;
4576
+ let size = 3; // Cannot be larger than 12 chars (\u{00000000}).
4510
4577
 
4511
- case 90: // Z
4578
+ while (size < 12) {
4579
+ const code = body.charCodeAt(position + size++); // Closing Brace (})
4512
4580
 
4513
- case 95: // _
4581
+ if (code === 0x007d) {
4582
+ // Must be at least 5 chars (\u{0}) and encode a Unicode scalar value.
4583
+ if (size < 5 || !isUnicodeScalarValue(point)) {
4584
+ break;
4585
+ }
4514
4586
 
4515
- case 97: // a
4587
+ return {
4588
+ value: String.fromCodePoint(point),
4589
+ size,
4590
+ };
4591
+ } // Append this hex digit to the code point.
4516
4592
 
4517
- case 98: // b
4593
+ point = (point << 4) | readHexDigit(code);
4518
4594
 
4519
- case 99: // c
4595
+ if (point < 0) {
4596
+ break;
4597
+ }
4598
+ }
4520
4599
 
4521
- case 100: // d
4600
+ throw syntaxError(
4601
+ lexer.source,
4602
+ position,
4603
+ `Invalid Unicode escape sequence: "${body.slice(
4604
+ position,
4605
+ position + size,
4606
+ )}".`,
4607
+ );
4608
+ }
4522
4609
 
4523
- case 101: // e
4610
+ function readEscapedUnicodeFixedWidth(lexer, position) {
4611
+ const body = lexer.source.body;
4612
+ const code = read16BitHexCode(body, position + 2);
4524
4613
 
4525
- case 102: // f
4614
+ if (isUnicodeScalarValue(code)) {
4615
+ return {
4616
+ value: String.fromCodePoint(code),
4617
+ size: 6,
4618
+ };
4619
+ } // GraphQL allows JSON-style surrogate pair escape sequences, but only when
4620
+ // a valid pair is formed.
4621
+
4622
+ if (isLeadingSurrogate(code)) {
4623
+ // \u
4624
+ if (
4625
+ body.charCodeAt(position + 6) === 0x005c &&
4626
+ body.charCodeAt(position + 7) === 0x0075
4627
+ ) {
4628
+ const trailingCode = read16BitHexCode(body, position + 8);
4629
+
4630
+ if (isTrailingSurrogate(trailingCode)) {
4631
+ // JavaScript defines strings as a sequence of UTF-16 code units and
4632
+ // encodes Unicode code points above U+FFFF using a surrogate pair of
4633
+ // code units. Since this is a surrogate pair escape sequence, just
4634
+ // include both codes into the JavaScript string value. Had JavaScript
4635
+ // not been internally based on UTF-16, then this surrogate pair would
4636
+ // be decoded to retrieve the supplementary code point.
4637
+ return {
4638
+ value: String.fromCodePoint(code, trailingCode),
4639
+ size: 12,
4640
+ };
4641
+ }
4642
+ }
4643
+ }
4526
4644
 
4527
- case 103: // g
4645
+ throw syntaxError(
4646
+ lexer.source,
4647
+ position,
4648
+ `Invalid Unicode escape sequence: "${body.slice(position, position + 6)}".`,
4649
+ );
4650
+ }
4651
+ /**
4652
+ * Reads four hexadecimal characters and returns the positive integer that 16bit
4653
+ * hexadecimal string represents. For example, "000f" will return 15, and "dead"
4654
+ * will return 57005.
4655
+ *
4656
+ * Returns a negative number if any char was not a valid hexadecimal digit.
4657
+ */
4528
4658
 
4529
- case 104: // h
4659
+ function read16BitHexCode(body, position) {
4660
+ // readHexDigit() returns -1 on error. ORing a negative value with any other
4661
+ // value always produces a negative value.
4662
+ return (
4663
+ (readHexDigit(body.charCodeAt(position)) << 12) |
4664
+ (readHexDigit(body.charCodeAt(position + 1)) << 8) |
4665
+ (readHexDigit(body.charCodeAt(position + 2)) << 4) |
4666
+ readHexDigit(body.charCodeAt(position + 3))
4667
+ );
4668
+ }
4669
+ /**
4670
+ * Reads a hexadecimal character and returns its positive integer value (0-15).
4671
+ *
4672
+ * '0' becomes 0, '9' becomes 9
4673
+ * 'A' becomes 10, 'F' becomes 15
4674
+ * 'a' becomes 10, 'f' becomes 15
4675
+ *
4676
+ * Returns -1 if the provided character code was not a valid hexadecimal digit.
4677
+ *
4678
+ * HexDigit :: one of
4679
+ * - `0` `1` `2` `3` `4` `5` `6` `7` `8` `9`
4680
+ * - `A` `B` `C` `D` `E` `F`
4681
+ * - `a` `b` `c` `d` `e` `f`
4682
+ */
4530
4683
 
4531
- case 105: // i
4684
+ function readHexDigit(code) {
4685
+ return code >= 0x0030 && code <= 0x0039 // 0-9
4686
+ ? code - 0x0030
4687
+ : code >= 0x0041 && code <= 0x0046 // A-F
4688
+ ? code - 0x0037
4689
+ : code >= 0x0061 && code <= 0x0066 // a-f
4690
+ ? code - 0x0057
4691
+ : -1;
4692
+ }
4693
+ /**
4694
+ * | Escaped Character | Code Point | Character Name |
4695
+ * | ----------------- | ---------- | ---------------------------- |
4696
+ * | `"` | U+0022 | double quote |
4697
+ * | `\` | U+005C | reverse solidus (back slash) |
4698
+ * | `/` | U+002F | solidus (forward slash) |
4699
+ * | `b` | U+0008 | backspace |
4700
+ * | `f` | U+000C | form feed |
4701
+ * | `n` | U+000A | line feed (new line) |
4702
+ * | `r` | U+000D | carriage return |
4703
+ * | `t` | U+0009 | horizontal tab |
4704
+ */
4532
4705
 
4533
- case 106: // j
4706
+ function readEscapedCharacter(lexer, position) {
4707
+ const body = lexer.source.body;
4708
+ const code = body.charCodeAt(position + 1);
4534
4709
 
4535
- case 107: // k
4710
+ switch (code) {
4711
+ case 0x0022:
4712
+ // "
4713
+ return {
4714
+ value: '\u0022',
4715
+ size: 2,
4716
+ };
4536
4717
 
4537
- case 108: // l
4718
+ case 0x005c:
4719
+ // \
4720
+ return {
4721
+ value: '\u005c',
4722
+ size: 2,
4723
+ };
4538
4724
 
4539
- case 109: // m
4725
+ case 0x002f:
4726
+ // /
4727
+ return {
4728
+ value: '\u002f',
4729
+ size: 2,
4730
+ };
4540
4731
 
4541
- case 110: // n
4732
+ case 0x0062:
4733
+ // b
4734
+ return {
4735
+ value: '\u0008',
4736
+ size: 2,
4737
+ };
4542
4738
 
4543
- case 111: // o
4739
+ case 0x0066:
4740
+ // f
4741
+ return {
4742
+ value: '\u000c',
4743
+ size: 2,
4744
+ };
4544
4745
 
4545
- case 112: // p
4746
+ case 0x006e:
4747
+ // n
4748
+ return {
4749
+ value: '\u000a',
4750
+ size: 2,
4751
+ };
4546
4752
 
4547
- case 113: // q
4753
+ case 0x0072:
4754
+ // r
4755
+ return {
4756
+ value: '\u000d',
4757
+ size: 2,
4758
+ };
4548
4759
 
4549
- case 114: // r
4760
+ case 0x0074:
4761
+ // t
4762
+ return {
4763
+ value: '\u0009',
4764
+ size: 2,
4765
+ };
4766
+ }
4550
4767
 
4551
- case 115: // s
4768
+ throw syntaxError(
4769
+ lexer.source,
4770
+ position,
4771
+ `Invalid character escape sequence: "${body.slice(
4772
+ position,
4773
+ position + 2,
4774
+ )}".`,
4775
+ );
4776
+ }
4777
+ /**
4778
+ * Reads a block string token from the source file.
4779
+ *
4780
+ * ```
4781
+ * StringValue ::
4782
+ * - `"""` BlockStringCharacter* `"""`
4783
+ *
4784
+ * BlockStringCharacter ::
4785
+ * - SourceCharacter but not `"""` or `\"""`
4786
+ * - `\"""`
4787
+ * ```
4788
+ */
4552
4789
 
4553
- case 116: // t
4790
+ function readBlockString(lexer, start) {
4791
+ const body = lexer.source.body;
4792
+ const bodyLength = body.length;
4793
+ let lineStart = lexer.lineStart;
4794
+ let position = start + 3;
4795
+ let chunkStart = position;
4796
+ let currentLine = '';
4797
+ const blockLines = [];
4798
+
4799
+ while (position < bodyLength) {
4800
+ const code = body.charCodeAt(position); // Closing Triple-Quote (""")
4801
+
4802
+ if (
4803
+ code === 0x0022 &&
4804
+ body.charCodeAt(position + 1) === 0x0022 &&
4805
+ body.charCodeAt(position + 2) === 0x0022
4806
+ ) {
4807
+ currentLine += body.slice(chunkStart, position);
4808
+ blockLines.push(currentLine);
4809
+ const token = createToken(
4810
+ lexer,
4811
+ TokenKind.BLOCK_STRING,
4812
+ start,
4813
+ position + 3, // Return a string of the lines joined with U+000A.
4814
+ dedentBlockStringLines(blockLines).join('\n'),
4815
+ );
4816
+ lexer.line += blockLines.length - 1;
4817
+ lexer.lineStart = lineStart;
4818
+ return token;
4819
+ } // Escaped Triple-Quote (\""")
4554
4820
 
4555
- case 117: // u
4821
+ if (
4822
+ code === 0x005c &&
4823
+ body.charCodeAt(position + 1) === 0x0022 &&
4824
+ body.charCodeAt(position + 2) === 0x0022 &&
4825
+ body.charCodeAt(position + 3) === 0x0022
4826
+ ) {
4827
+ currentLine += body.slice(chunkStart, position);
4828
+ chunkStart = position + 1; // skip only slash
4556
4829
 
4557
- case 118: // v
4830
+ position += 4;
4831
+ continue;
4832
+ } // LineTerminator
4558
4833
 
4559
- case 119: // w
4834
+ if (code === 0x000a || code === 0x000d) {
4835
+ currentLine += body.slice(chunkStart, position);
4836
+ blockLines.push(currentLine);
4560
4837
 
4561
- case 120: // x
4838
+ if (code === 0x000d && body.charCodeAt(position + 1) === 0x000a) {
4839
+ position += 2;
4840
+ } else {
4841
+ ++position;
4842
+ }
4562
4843
 
4563
- case 121: // y
4844
+ currentLine = '';
4845
+ chunkStart = position;
4846
+ lineStart = position;
4847
+ continue;
4848
+ } // SourceCharacter
4564
4849
 
4565
- case 122:
4566
- // z
4567
- return readName(source, pos, _line, _col, prev);
4850
+ if (isUnicodeScalarValue(code)) {
4851
+ ++position;
4852
+ } else if (isSupplementaryCodePoint(body, position)) {
4853
+ position += 2;
4854
+ } else {
4855
+ throw syntaxError(
4856
+ lexer.source,
4857
+ position,
4858
+ `Invalid character within String: ${printCodePointAt(
4859
+ lexer,
4860
+ position,
4861
+ )}.`,
4862
+ );
4568
4863
  }
4569
-
4570
- throw syntaxError(source, pos, unexpectedCharacterMessage(code));
4571
4864
  }
4572
4865
 
4573
- var line = lexer.line;
4574
- var col = 1 + pos - lexer.lineStart;
4575
- return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
4866
+ throw syntaxError(lexer.source, position, 'Unterminated string.');
4576
4867
  }
4577
4868
  /**
4578
- * Report a message that an unexpected character was encountered.
4869
+ * Reads an alphanumeric + underscore name from the source.
4870
+ *
4871
+ * ```
4872
+ * Name ::
4873
+ * - NameStart NameContinue* [lookahead != NameContinue]
4874
+ * ```
4579
4875
  */
4580
4876
 
4877
+ function readName(lexer, start) {
4878
+ const body = lexer.source.body;
4879
+ const bodyLength = body.length;
4880
+ let position = start + 1;
4581
4881
 
4582
- function unexpectedCharacterMessage(code) {
4583
- if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
4584
- return "Cannot contain the invalid character ".concat(printCharCode(code), ".");
4585
- }
4882
+ while (position < bodyLength) {
4883
+ const code = body.charCodeAt(position);
4586
4884
 
4587
- if (code === 39) {
4588
- // '
4589
- return 'Unexpected single quote character (\'), did you mean to use a double quote (")?';
4885
+ if (isNameContinue(code)) {
4886
+ ++position;
4887
+ } else {
4888
+ break;
4889
+ }
4590
4890
  }
4591
4891
 
4592
- return "Cannot parse the unexpected character ".concat(printCharCode(code), ".");
4892
+ return createToken(
4893
+ lexer,
4894
+ TokenKind.NAME,
4895
+ start,
4896
+ position,
4897
+ body.slice(start, position),
4898
+ );
4593
4899
  }
4594
- /**
4595
- * Reads a comment token from the source file.
4596
- *
4597
- * #[\u0009\u0020-\uFFFF]*
4598
- */
4599
-
4600
4900
 
4601
- function readComment(source, start, line, col, prev) {
4602
- var body = source.body;
4603
- var code;
4604
- var position = start;
4605
-
4606
- do {
4607
- code = body.charCodeAt(++position);
4608
- } while (!isNaN(code) && ( // SourceCharacter but not LineTerminator
4609
- code > 0x001f || code === 0x0009));
4610
-
4611
- return new Token(TokenKind.COMMENT, start, position, line, col, prev, body.slice(start + 1, position));
4612
- }
4901
+ const MAX_ARRAY_LENGTH = 10;
4902
+ const MAX_RECURSIVE_DEPTH = 2;
4613
4903
  /**
4614
- * Reads a number token from the source file, either a float
4615
- * or an int depending on whether a decimal point appears.
4616
- *
4617
- * Int: -?(0|[1-9][0-9]*)
4618
- * Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)?
4904
+ * Used to print values in error messages.
4619
4905
  */
4620
4906
 
4907
+ function inspect(value) {
4908
+ return formatValue(value, []);
4909
+ }
4621
4910
 
4622
- function readNumber(source, start, firstCode, line, col, prev) {
4623
- var body = source.body;
4624
- var code = firstCode;
4625
- var position = start;
4626
- var isFloat = false;
4911
+ function formatValue(value, seenValues) {
4912
+ switch (typeof value) {
4913
+ case 'string':
4914
+ return JSON.stringify(value);
4627
4915
 
4628
- if (code === 45) {
4629
- // -
4630
- code = body.charCodeAt(++position);
4631
- }
4916
+ case 'function':
4917
+ return value.name ? `[function ${value.name}]` : '[function]';
4632
4918
 
4633
- if (code === 48) {
4634
- // 0
4635
- code = body.charCodeAt(++position);
4919
+ case 'object':
4920
+ return formatObjectValue(value, seenValues);
4636
4921
 
4637
- if (code >= 48 && code <= 57) {
4638
- throw syntaxError(source, position, "Invalid number, unexpected digit after 0: ".concat(printCharCode(code), "."));
4639
- }
4640
- } else {
4641
- position = readDigits(source, position, code);
4642
- code = body.charCodeAt(position);
4922
+ default:
4923
+ return String(value);
4643
4924
  }
4925
+ }
4644
4926
 
4645
- if (code === 46) {
4646
- // .
4647
- isFloat = true;
4648
- code = body.charCodeAt(++position);
4649
- position = readDigits(source, position, code);
4650
- code = body.charCodeAt(position);
4927
+ function formatObjectValue(value, previouslySeenValues) {
4928
+ if (value === null) {
4929
+ return 'null';
4651
4930
  }
4652
4931
 
4653
- if (code === 69 || code === 101) {
4654
- // E e
4655
- isFloat = true;
4656
- code = body.charCodeAt(++position);
4657
-
4658
- if (code === 43 || code === 45) {
4659
- // + -
4660
- code = body.charCodeAt(++position);
4661
- }
4932
+ if (previouslySeenValues.includes(value)) {
4933
+ return '[Circular]';
4934
+ }
4662
4935
 
4663
- position = readDigits(source, position, code);
4664
- code = body.charCodeAt(position);
4665
- } // Numbers cannot be followed by . or NameStart
4936
+ const seenValues = [...previouslySeenValues, value];
4666
4937
 
4938
+ if (isJSONable(value)) {
4939
+ const jsonValue = value.toJSON(); // check for infinite recursion
4667
4940
 
4668
- if (code === 46 || isNameStart(code)) {
4669
- throw syntaxError(source, position, "Invalid number, expected digit but got: ".concat(printCharCode(code), "."));
4941
+ if (jsonValue !== value) {
4942
+ return typeof jsonValue === 'string'
4943
+ ? jsonValue
4944
+ : formatValue(jsonValue, seenValues);
4945
+ }
4946
+ } else if (Array.isArray(value)) {
4947
+ return formatArray(value, seenValues);
4670
4948
  }
4671
4949
 
4672
- return new Token(isFloat ? TokenKind.FLOAT : TokenKind.INT, start, position, line, col, prev, body.slice(start, position));
4950
+ return formatObject(value, seenValues);
4673
4951
  }
4674
- /**
4675
- * Returns the new position in the source after reading digits.
4676
- */
4677
4952
 
4953
+ function isJSONable(value) {
4954
+ return typeof value.toJSON === 'function';
4955
+ }
4678
4956
 
4679
- function readDigits(source, start, firstCode) {
4680
- var body = source.body;
4681
- var position = start;
4682
- var code = firstCode;
4683
-
4684
- if (code >= 48 && code <= 57) {
4685
- // 0 - 9
4686
- do {
4687
- code = body.charCodeAt(++position);
4688
- } while (code >= 48 && code <= 57); // 0 - 9
4957
+ function formatObject(object, seenValues) {
4958
+ const entries = Object.entries(object);
4689
4959
 
4960
+ if (entries.length === 0) {
4961
+ return '{}';
4962
+ }
4690
4963
 
4691
- return position;
4964
+ if (seenValues.length > MAX_RECURSIVE_DEPTH) {
4965
+ return '[' + getObjectTag(object) + ']';
4692
4966
  }
4693
4967
 
4694
- throw syntaxError(source, position, "Invalid number, expected digit but got: ".concat(printCharCode(code), "."));
4968
+ const properties = entries.map(
4969
+ ([key, value]) => key + ': ' + formatValue(value, seenValues),
4970
+ );
4971
+ return '{ ' + properties.join(', ') + ' }';
4695
4972
  }
4696
- /**
4697
- * Reads a string token from the source file.
4698
- *
4699
- * "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*"
4700
- */
4701
4973
 
4974
+ function formatArray(array, seenValues) {
4975
+ if (array.length === 0) {
4976
+ return '[]';
4977
+ }
4702
4978
 
4703
- function readString(source, start, line, col, prev) {
4704
- var body = source.body;
4705
- var position = start + 1;
4706
- var chunkStart = position;
4707
- var code = 0;
4708
- var value = '';
4709
-
4710
- while (position < body.length && !isNaN(code = body.charCodeAt(position)) && // not LineTerminator
4711
- code !== 0x000a && code !== 0x000d) {
4712
- // Closing Quote (")
4713
- if (code === 34) {
4714
- value += body.slice(chunkStart, position);
4715
- return new Token(TokenKind.STRING, start, position + 1, line, col, prev, value);
4716
- } // SourceCharacter
4979
+ if (seenValues.length > MAX_RECURSIVE_DEPTH) {
4980
+ return '[Array]';
4981
+ }
4717
4982
 
4983
+ const len = Math.min(MAX_ARRAY_LENGTH, array.length);
4984
+ const remaining = array.length - len;
4985
+ const items = [];
4718
4986
 
4719
- if (code < 0x0020 && code !== 0x0009) {
4720
- throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), "."));
4721
- }
4987
+ for (let i = 0; i < len; ++i) {
4988
+ items.push(formatValue(array[i], seenValues));
4989
+ }
4722
4990
 
4723
- ++position;
4991
+ if (remaining === 1) {
4992
+ items.push('... 1 more item');
4993
+ } else if (remaining > 1) {
4994
+ items.push(`... ${remaining} more items`);
4995
+ }
4724
4996
 
4725
- if (code === 92) {
4726
- // \
4727
- value += body.slice(chunkStart, position - 1);
4728
- code = body.charCodeAt(position);
4729
-
4730
- switch (code) {
4731
- case 34:
4732
- value += '"';
4733
- break;
4734
-
4735
- case 47:
4736
- value += '/';
4737
- break;
4738
-
4739
- case 92:
4740
- value += '\\';
4741
- break;
4742
-
4743
- case 98:
4744
- value += '\b';
4745
- break;
4746
-
4747
- case 102:
4748
- value += '\f';
4749
- break;
4750
-
4751
- case 110:
4752
- value += '\n';
4753
- break;
4754
-
4755
- case 114:
4756
- value += '\r';
4757
- break;
4758
-
4759
- case 116:
4760
- value += '\t';
4761
- break;
4762
-
4763
- case 117:
4764
- {
4765
- // uXXXX
4766
- var charCode = uniCharCode(body.charCodeAt(position + 1), body.charCodeAt(position + 2), body.charCodeAt(position + 3), body.charCodeAt(position + 4));
4767
-
4768
- if (charCode < 0) {
4769
- var invalidSequence = body.slice(position + 1, position + 5);
4770
- throw syntaxError(source, position, "Invalid character escape sequence: \\u".concat(invalidSequence, "."));
4771
- }
4997
+ return '[' + items.join(', ') + ']';
4998
+ }
4772
4999
 
4773
- value += String.fromCharCode(charCode);
4774
- position += 4;
4775
- break;
4776
- }
5000
+ function getObjectTag(object) {
5001
+ const tag = Object.prototype.toString
5002
+ .call(object)
5003
+ .replace(/^\[object /, '')
5004
+ .replace(/]$/, '');
4777
5005
 
4778
- default:
4779
- throw syntaxError(source, position, "Invalid character escape sequence: \\".concat(String.fromCharCode(code), "."));
4780
- }
5006
+ if (tag === 'Object' && typeof object.constructor === 'function') {
5007
+ const name = object.constructor.name;
4781
5008
 
4782
- ++position;
4783
- chunkStart = position;
5009
+ if (typeof name === 'string' && name !== '') {
5010
+ return name;
4784
5011
  }
4785
5012
  }
4786
5013
 
4787
- throw syntaxError(source, position, 'Unterminated string.');
5014
+ return tag;
4788
5015
  }
5016
+
4789
5017
  /**
4790
- * Reads a block string token from the source file.
4791
- *
4792
- * """("?"?(\\"""|\\(?!=""")|[^"\\]))*"""
5018
+ * A replacement for instanceof which includes an error warning when multi-realm
5019
+ * constructors are detected.
5020
+ * See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
5021
+ * See: https://webpack.js.org/guides/production/
4793
5022
  */
4794
5023
 
4795
-
4796
- function readBlockString(source, start, line, col, prev, lexer) {
4797
- var body = source.body;
4798
- var position = start + 3;
4799
- var chunkStart = position;
4800
- var code = 0;
4801
- var rawValue = '';
4802
-
4803
- while (position < body.length && !isNaN(code = body.charCodeAt(position))) {
4804
- // Closing Triple-Quote (""")
4805
- if (code === 34 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34) {
4806
- rawValue += body.slice(chunkStart, position);
4807
- return new Token(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, dedentBlockStringValue(rawValue));
4808
- } // SourceCharacter
4809
-
4810
-
4811
- if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
4812
- throw syntaxError(source, position, "Invalid character within String: ".concat(printCharCode(code), "."));
4813
- }
4814
-
4815
- if (code === 10) {
4816
- // new line
4817
- ++position;
4818
- ++lexer.line;
4819
- lexer.lineStart = position;
4820
- } else if (code === 13) {
4821
- // carriage return
4822
- if (body.charCodeAt(position + 1) === 10) {
4823
- position += 2;
4824
- } else {
4825
- ++position;
5024
+ const instanceOf =
5025
+ /* c8 ignore next 5 */
5026
+ // FIXME: https://github.com/graphql/graphql-js/issues/2317
5027
+ process.env.NODE_ENV === 'production'
5028
+ ? function instanceOf(value, constructor) {
5029
+ return value instanceof constructor;
4826
5030
  }
5031
+ : function instanceOf(value, constructor) {
5032
+ if (value instanceof constructor) {
5033
+ return true;
5034
+ }
4827
5035
 
4828
- ++lexer.line;
4829
- lexer.lineStart = position;
4830
- } else if ( // Escape Triple-Quote (\""")
4831
- code === 92 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34 && body.charCodeAt(position + 3) === 34) {
4832
- rawValue += body.slice(chunkStart, position) + '"""';
4833
- position += 4;
4834
- chunkStart = position;
4835
- } else {
4836
- ++position;
4837
- }
4838
- }
4839
-
4840
- throw syntaxError(source, position, 'Unterminated string.');
4841
- }
4842
- /**
4843
- * Converts four hexadecimal chars to the integer that the
4844
- * string represents. For example, uniCharCode('0','0','0','f')
4845
- * will return 15, and uniCharCode('0','0','f','f') returns 255.
4846
- *
4847
- * Returns a negative number on error, if a char was invalid.
4848
- *
4849
- * This is implemented by noting that char2hex() returns -1 on error,
4850
- * which means the result of ORing the char2hex() will also be negative.
4851
- */
5036
+ if (typeof value === 'object' && value !== null) {
5037
+ var _value$constructor;
5038
+
5039
+ // Prefer Symbol.toStringTag since it is immune to minification.
5040
+ const className = constructor.prototype[Symbol.toStringTag];
5041
+ const valueClassName = // We still need to support constructor's name to detect conflicts with older versions of this library.
5042
+ Symbol.toStringTag in value // @ts-expect-error TS bug see, https://github.com/microsoft/TypeScript/issues/38009
5043
+ ? value[Symbol.toStringTag]
5044
+ : (_value$constructor = value.constructor) === null ||
5045
+ _value$constructor === void 0
5046
+ ? void 0
5047
+ : _value$constructor.name;
5048
+
5049
+ if (className === valueClassName) {
5050
+ const stringifiedValue = inspect(value);
5051
+ throw new Error(`Cannot use ${className} "${stringifiedValue}" from another module or realm.
5052
+
5053
+ Ensure that there is only one instance of "graphql" in the node_modules
5054
+ directory. If different versions of "graphql" are the dependencies of other
5055
+ relied on modules, use "resolutions" to ensure only one version is installed.
5056
+
5057
+ https://yarnpkg.com/en/docs/selective-version-resolutions
5058
+
5059
+ Duplicate "graphql" modules cannot be used at the same time since different
5060
+ versions may have different capabilities and behavior. The data from one
5061
+ version used in the function from another could produce confusing and
5062
+ spurious results.`);
5063
+ }
5064
+ }
4852
5065
 
5066
+ return false;
5067
+ };
4853
5068
 
4854
- function uniCharCode(a, b, c, d) {
4855
- return char2hex(a) << 12 | char2hex(b) << 8 | char2hex(c) << 4 | char2hex(d);
4856
- }
4857
5069
  /**
4858
- * Converts a hex character to its integer value.
4859
- * '0' becomes 0, '9' becomes 9
4860
- * 'A' becomes 10, 'F' becomes 15
4861
- * 'a' becomes 10, 'f' becomes 15
4862
- *
4863
- * Returns -1 on error.
5070
+ * A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
5071
+ * optional, but they are useful for clients who store GraphQL documents in source files.
5072
+ * For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
5073
+ * be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
5074
+ * The `line` and `column` properties in `locationOffset` are 1-indexed.
4864
5075
  */
5076
+ class Source {
5077
+ constructor(
5078
+ body,
5079
+ name = 'GraphQL request',
5080
+ locationOffset = {
5081
+ line: 1,
5082
+ column: 1,
5083
+ },
5084
+ ) {
5085
+ typeof body === 'string' ||
5086
+ devAssert(false, `Body must be a string. Received: ${inspect(body)}.`);
5087
+ this.body = body;
5088
+ this.name = name;
5089
+ this.locationOffset = locationOffset;
5090
+ this.locationOffset.line > 0 ||
5091
+ devAssert(
5092
+ false,
5093
+ 'line in locationOffset is 1-indexed and must be positive.',
5094
+ );
5095
+ this.locationOffset.column > 0 ||
5096
+ devAssert(
5097
+ false,
5098
+ 'column in locationOffset is 1-indexed and must be positive.',
5099
+ );
5100
+ }
4865
5101
 
4866
-
4867
- function char2hex(a) {
4868
- return a >= 48 && a <= 57 ? a - 48 // 0-9
4869
- : a >= 65 && a <= 70 ? a - 55 // A-F
4870
- : a >= 97 && a <= 102 ? a - 87 // a-f
4871
- : -1;
5102
+ get [Symbol.toStringTag]() {
5103
+ return 'Source';
5104
+ }
4872
5105
  }
4873
5106
  /**
4874
- * Reads an alphanumeric + underscore name from the source.
5107
+ * Test if the given value is a Source object.
4875
5108
  *
4876
- * [_A-Za-z][_0-9A-Za-z]*
5109
+ * @internal
4877
5110
  */
4878
5111
 
4879
-
4880
- function readName(source, start, line, col, prev) {
4881
- var body = source.body;
4882
- var bodyLength = body.length;
4883
- var position = start + 1;
4884
- var code = 0;
4885
-
4886
- while (position !== bodyLength && !isNaN(code = body.charCodeAt(position)) && (code === 95 || // _
4887
- code >= 48 && code <= 57 || // 0-9
4888
- code >= 65 && code <= 90 || // A-Z
4889
- code >= 97 && code <= 122) // a-z
4890
- ) {
4891
- ++position;
4892
- }
4893
-
4894
- return new Token(TokenKind.NAME, start, position, line, col, prev, body.slice(start, position));
4895
- } // _ A-Z a-z
4896
-
4897
-
4898
- function isNameStart(code) {
4899
- return code === 95 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
5112
+ function isSource(source) {
5113
+ return instanceOf(source, Source);
4900
5114
  }
4901
5115
 
4902
5116
  /**
@@ -4908,7 +5122,7 @@ function isNameStart(code) {
4908
5122
  * Throws GraphQLError if a syntax error is encountered.
4909
5123
  */
4910
5124
  function parse$1(source, options) {
4911
- var parser = new Parser(source, options);
5125
+ const parser = new Parser(source, options);
4912
5126
  return parser.parseDocument();
4913
5127
  }
4914
5128
  /**
@@ -4923,9 +5137,9 @@ function parse$1(source, options) {
4923
5137
  * @internal
4924
5138
  */
4925
5139
 
4926
- var Parser = /*#__PURE__*/function () {
4927
- function Parser(source, options) {
4928
- var sourceObj = isSource(source) ? source : new Source(source);
5140
+ class Parser {
5141
+ constructor(source, options) {
5142
+ const sourceObj = isSource(source) ? source : new Source(source);
4929
5143
  this._lexer = new Lexer(sourceObj);
4930
5144
  this._options = options;
4931
5145
  }
@@ -4933,30 +5147,27 @@ var Parser = /*#__PURE__*/function () {
4933
5147
  * Converts a name lex token into a name parse node.
4934
5148
  */
4935
5149
 
4936
-
4937
- var _proto = Parser.prototype;
4938
-
4939
- _proto.parseName = function parseName() {
4940
- var token = this.expectToken(TokenKind.NAME);
4941
- return {
5150
+ parseName() {
5151
+ const token = this.expectToken(TokenKind.NAME);
5152
+ return this.node(token, {
4942
5153
  kind: Kind.NAME,
4943
5154
  value: token.value,
4944
- loc: this.loc(token)
4945
- };
5155
+ });
4946
5156
  } // Implements the parsing rules in the Document section.
4947
5157
 
4948
5158
  /**
4949
5159
  * Document : Definition+
4950
5160
  */
4951
- ;
4952
5161
 
4953
- _proto.parseDocument = function parseDocument() {
4954
- var start = this._lexer.token;
4955
- return {
5162
+ parseDocument() {
5163
+ return this.node(this._lexer.token, {
4956
5164
  kind: Kind.DOCUMENT,
4957
- definitions: this.many(TokenKind.SOF, this.parseDefinition, TokenKind.EOF),
4958
- loc: this.loc(start)
4959
- };
5165
+ definitions: this.many(
5166
+ TokenKind.SOF,
5167
+ this.parseDefinition,
5168
+ TokenKind.EOF,
5169
+ ),
5170
+ });
4960
5171
  }
4961
5172
  /**
4962
5173
  * Definition :
@@ -4967,40 +5178,81 @@ var Parser = /*#__PURE__*/function () {
4967
5178
  * ExecutableDefinition :
4968
5179
  * - OperationDefinition
4969
5180
  * - FragmentDefinition
5181
+ *
5182
+ * TypeSystemDefinition :
5183
+ * - SchemaDefinition
5184
+ * - TypeDefinition
5185
+ * - DirectiveDefinition
5186
+ *
5187
+ * TypeDefinition :
5188
+ * - ScalarTypeDefinition
5189
+ * - ObjectTypeDefinition
5190
+ * - InterfaceTypeDefinition
5191
+ * - UnionTypeDefinition
5192
+ * - EnumTypeDefinition
5193
+ * - InputObjectTypeDefinition
4970
5194
  */
4971
- ;
4972
5195
 
4973
- _proto.parseDefinition = function parseDefinition() {
4974
- if (this.peek(TokenKind.NAME)) {
4975
- switch (this._lexer.token.value) {
4976
- case 'query':
4977
- case 'mutation':
4978
- case 'subscription':
4979
- return this.parseOperationDefinition();
5196
+ parseDefinition() {
5197
+ if (this.peek(TokenKind.BRACE_L)) {
5198
+ return this.parseOperationDefinition();
5199
+ } // Many definitions begin with a description and require a lookahead.
4980
5200
 
4981
- case 'fragment':
4982
- return this.parseFragmentDefinition();
5201
+ const hasDescription = this.peekDescription();
5202
+ const keywordToken = hasDescription
5203
+ ? this._lexer.lookahead()
5204
+ : this._lexer.token;
4983
5205
 
5206
+ if (keywordToken.kind === TokenKind.NAME) {
5207
+ switch (keywordToken.value) {
4984
5208
  case 'schema':
5209
+ return this.parseSchemaDefinition();
5210
+
4985
5211
  case 'scalar':
5212
+ return this.parseScalarTypeDefinition();
5213
+
4986
5214
  case 'type':
5215
+ return this.parseObjectTypeDefinition();
5216
+
4987
5217
  case 'interface':
5218
+ return this.parseInterfaceTypeDefinition();
5219
+
4988
5220
  case 'union':
5221
+ return this.parseUnionTypeDefinition();
5222
+
4989
5223
  case 'enum':
5224
+ return this.parseEnumTypeDefinition();
5225
+
4990
5226
  case 'input':
5227
+ return this.parseInputObjectTypeDefinition();
5228
+
4991
5229
  case 'directive':
4992
- return this.parseTypeSystemDefinition();
5230
+ return this.parseDirectiveDefinition();
5231
+ }
5232
+
5233
+ if (hasDescription) {
5234
+ throw syntaxError(
5235
+ this._lexer.source,
5236
+ this._lexer.token.start,
5237
+ 'Unexpected description, descriptions are supported only on type definitions.',
5238
+ );
5239
+ }
5240
+
5241
+ switch (keywordToken.value) {
5242
+ case 'query':
5243
+ case 'mutation':
5244
+ case 'subscription':
5245
+ return this.parseOperationDefinition();
5246
+
5247
+ case 'fragment':
5248
+ return this.parseFragmentDefinition();
4993
5249
 
4994
5250
  case 'extend':
4995
5251
  return this.parseTypeSystemExtension();
4996
5252
  }
4997
- } else if (this.peek(TokenKind.BRACE_L)) {
4998
- return this.parseOperationDefinition();
4999
- } else if (this.peekDescription()) {
5000
- return this.parseTypeSystemDefinition();
5001
5253
  }
5002
5254
 
5003
- throw this.unexpected();
5255
+ throw this.unexpected(keywordToken);
5004
5256
  } // Implements the parsing rules in the Operations section.
5005
5257
 
5006
5258
  /**
@@ -5008,57 +5260,53 @@ var Parser = /*#__PURE__*/function () {
5008
5260
  * - SelectionSet
5009
5261
  * - OperationType Name? VariableDefinitions? Directives? SelectionSet
5010
5262
  */
5011
- ;
5012
5263
 
5013
- _proto.parseOperationDefinition = function parseOperationDefinition() {
5014
- var start = this._lexer.token;
5264
+ parseOperationDefinition() {
5265
+ const start = this._lexer.token;
5015
5266
 
5016
5267
  if (this.peek(TokenKind.BRACE_L)) {
5017
- return {
5268
+ return this.node(start, {
5018
5269
  kind: Kind.OPERATION_DEFINITION,
5019
- operation: 'query',
5270
+ operation: OperationTypeNode.QUERY,
5020
5271
  name: undefined,
5021
5272
  variableDefinitions: [],
5022
5273
  directives: [],
5023
5274
  selectionSet: this.parseSelectionSet(),
5024
- loc: this.loc(start)
5025
- };
5275
+ });
5026
5276
  }
5027
5277
 
5028
- var operation = this.parseOperationType();
5029
- var name;
5278
+ const operation = this.parseOperationType();
5279
+ let name;
5030
5280
 
5031
5281
  if (this.peek(TokenKind.NAME)) {
5032
5282
  name = this.parseName();
5033
5283
  }
5034
5284
 
5035
- return {
5285
+ return this.node(start, {
5036
5286
  kind: Kind.OPERATION_DEFINITION,
5037
- operation: operation,
5038
- name: name,
5287
+ operation,
5288
+ name,
5039
5289
  variableDefinitions: this.parseVariableDefinitions(),
5040
5290
  directives: this.parseDirectives(false),
5041
5291
  selectionSet: this.parseSelectionSet(),
5042
- loc: this.loc(start)
5043
- };
5292
+ });
5044
5293
  }
5045
5294
  /**
5046
5295
  * OperationType : one of query mutation subscription
5047
5296
  */
5048
- ;
5049
5297
 
5050
- _proto.parseOperationType = function parseOperationType() {
5051
- var operationToken = this.expectToken(TokenKind.NAME);
5298
+ parseOperationType() {
5299
+ const operationToken = this.expectToken(TokenKind.NAME);
5052
5300
 
5053
5301
  switch (operationToken.value) {
5054
5302
  case 'query':
5055
- return 'query';
5303
+ return OperationTypeNode.QUERY;
5056
5304
 
5057
5305
  case 'mutation':
5058
- return 'mutation';
5306
+ return OperationTypeNode.MUTATION;
5059
5307
 
5060
5308
  case 'subscription':
5061
- return 'subscription';
5309
+ return OperationTypeNode.SUBSCRIPTION;
5062
5310
  }
5063
5311
 
5064
5312
  throw this.unexpected(operationToken);
@@ -5066,53 +5314,56 @@ var Parser = /*#__PURE__*/function () {
5066
5314
  /**
5067
5315
  * VariableDefinitions : ( VariableDefinition+ )
5068
5316
  */
5069
- ;
5070
5317
 
5071
- _proto.parseVariableDefinitions = function parseVariableDefinitions() {
5072
- return this.optionalMany(TokenKind.PAREN_L, this.parseVariableDefinition, TokenKind.PAREN_R);
5318
+ parseVariableDefinitions() {
5319
+ return this.optionalMany(
5320
+ TokenKind.PAREN_L,
5321
+ this.parseVariableDefinition,
5322
+ TokenKind.PAREN_R,
5323
+ );
5073
5324
  }
5074
5325
  /**
5075
5326
  * VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
5076
5327
  */
5077
- ;
5078
5328
 
5079
- _proto.parseVariableDefinition = function parseVariableDefinition() {
5080
- var start = this._lexer.token;
5081
- return {
5329
+ parseVariableDefinition() {
5330
+ return this.node(this._lexer.token, {
5082
5331
  kind: Kind.VARIABLE_DEFINITION,
5083
5332
  variable: this.parseVariable(),
5084
5333
  type: (this.expectToken(TokenKind.COLON), this.parseTypeReference()),
5085
- defaultValue: this.expectOptionalToken(TokenKind.EQUALS) ? this.parseValueLiteral(true) : undefined,
5086
- directives: this.parseDirectives(true),
5087
- loc: this.loc(start)
5088
- };
5334
+ defaultValue: this.expectOptionalToken(TokenKind.EQUALS)
5335
+ ? this.parseConstValueLiteral()
5336
+ : undefined,
5337
+ directives: this.parseConstDirectives(),
5338
+ });
5089
5339
  }
5090
5340
  /**
5091
5341
  * Variable : $ Name
5092
5342
  */
5093
- ;
5094
5343
 
5095
- _proto.parseVariable = function parseVariable() {
5096
- var start = this._lexer.token;
5344
+ parseVariable() {
5345
+ const start = this._lexer.token;
5097
5346
  this.expectToken(TokenKind.DOLLAR);
5098
- return {
5347
+ return this.node(start, {
5099
5348
  kind: Kind.VARIABLE,
5100
5349
  name: this.parseName(),
5101
- loc: this.loc(start)
5102
- };
5350
+ });
5103
5351
  }
5104
5352
  /**
5353
+ * ```
5105
5354
  * SelectionSet : { Selection+ }
5355
+ * ```
5106
5356
  */
5107
- ;
5108
5357
 
5109
- _proto.parseSelectionSet = function parseSelectionSet() {
5110
- var start = this._lexer.token;
5111
- return {
5358
+ parseSelectionSet() {
5359
+ return this.node(this._lexer.token, {
5112
5360
  kind: Kind.SELECTION_SET,
5113
- selections: this.many(TokenKind.BRACE_L, this.parseSelection, TokenKind.BRACE_R),
5114
- loc: this.loc(start)
5115
- };
5361
+ selections: this.many(
5362
+ TokenKind.BRACE_L,
5363
+ this.parseSelection,
5364
+ TokenKind.BRACE_R,
5365
+ ),
5366
+ });
5116
5367
  }
5117
5368
  /**
5118
5369
  * Selection :
@@ -5120,23 +5371,23 @@ var Parser = /*#__PURE__*/function () {
5120
5371
  * - FragmentSpread
5121
5372
  * - InlineFragment
5122
5373
  */
5123
- ;
5124
5374
 
5125
- _proto.parseSelection = function parseSelection() {
5126
- return this.peek(TokenKind.SPREAD) ? this.parseFragment() : this.parseField();
5375
+ parseSelection() {
5376
+ return this.peek(TokenKind.SPREAD)
5377
+ ? this.parseFragment()
5378
+ : this.parseField();
5127
5379
  }
5128
5380
  /**
5129
5381
  * Field : Alias? Name Arguments? Directives? SelectionSet?
5130
5382
  *
5131
5383
  * Alias : Name :
5132
5384
  */
5133
- ;
5134
5385
 
5135
- _proto.parseField = function parseField() {
5136
- var start = this._lexer.token;
5137
- var nameOrAlias = this.parseName();
5138
- var alias;
5139
- var name;
5386
+ parseField() {
5387
+ const start = this._lexer.token;
5388
+ const nameOrAlias = this.parseName();
5389
+ let alias;
5390
+ let name;
5140
5391
 
5141
5392
  if (this.expectOptionalToken(TokenKind.COLON)) {
5142
5393
  alias = nameOrAlias;
@@ -5145,50 +5396,42 @@ var Parser = /*#__PURE__*/function () {
5145
5396
  name = nameOrAlias;
5146
5397
  }
5147
5398
 
5148
- return {
5399
+ return this.node(start, {
5149
5400
  kind: Kind.FIELD,
5150
- alias: alias,
5151
- name: name,
5401
+ alias,
5402
+ name,
5152
5403
  arguments: this.parseArguments(false),
5153
5404
  directives: this.parseDirectives(false),
5154
- selectionSet: this.peek(TokenKind.BRACE_L) ? this.parseSelectionSet() : undefined,
5155
- loc: this.loc(start)
5156
- };
5405
+ selectionSet: this.peek(TokenKind.BRACE_L)
5406
+ ? this.parseSelectionSet()
5407
+ : undefined,
5408
+ });
5157
5409
  }
5158
5410
  /**
5159
5411
  * Arguments[Const] : ( Argument[?Const]+ )
5160
5412
  */
5161
- ;
5162
5413
 
5163
- _proto.parseArguments = function parseArguments(isConst) {
5164
- var item = isConst ? this.parseConstArgument : this.parseArgument;
5414
+ parseArguments(isConst) {
5415
+ const item = isConst ? this.parseConstArgument : this.parseArgument;
5165
5416
  return this.optionalMany(TokenKind.PAREN_L, item, TokenKind.PAREN_R);
5166
5417
  }
5167
5418
  /**
5168
5419
  * Argument[Const] : Name : Value[?Const]
5169
5420
  */
5170
- ;
5171
5421
 
5172
- _proto.parseArgument = function parseArgument() {
5173
- var start = this._lexer.token;
5174
- var name = this.parseName();
5422
+ parseArgument(isConst = false) {
5423
+ const start = this._lexer.token;
5424
+ const name = this.parseName();
5175
5425
  this.expectToken(TokenKind.COLON);
5176
- return {
5426
+ return this.node(start, {
5177
5427
  kind: Kind.ARGUMENT,
5178
- name: name,
5179
- value: this.parseValueLiteral(false),
5180
- loc: this.loc(start)
5181
- };
5182
- };
5428
+ name,
5429
+ value: this.parseValueLiteral(isConst),
5430
+ });
5431
+ }
5183
5432
 
5184
- _proto.parseConstArgument = function parseConstArgument() {
5185
- var start = this._lexer.token;
5186
- return {
5187
- kind: Kind.ARGUMENT,
5188
- name: this.parseName(),
5189
- value: (this.expectToken(TokenKind.COLON), this.parseValueLiteral(true)),
5190
- loc: this.loc(start)
5191
- };
5433
+ parseConstArgument() {
5434
+ return this.parseArgument(true);
5192
5435
  } // Implements the parsing rules in the Fragments section.
5193
5436
 
5194
5437
  /**
@@ -5198,29 +5441,26 @@ var Parser = /*#__PURE__*/function () {
5198
5441
  *
5199
5442
  * InlineFragment : ... TypeCondition? Directives? SelectionSet
5200
5443
  */
5201
- ;
5202
5444
 
5203
- _proto.parseFragment = function parseFragment() {
5204
- var start = this._lexer.token;
5445
+ parseFragment() {
5446
+ const start = this._lexer.token;
5205
5447
  this.expectToken(TokenKind.SPREAD);
5206
- var hasTypeCondition = this.expectOptionalKeyword('on');
5448
+ const hasTypeCondition = this.expectOptionalKeyword('on');
5207
5449
 
5208
5450
  if (!hasTypeCondition && this.peek(TokenKind.NAME)) {
5209
- return {
5451
+ return this.node(start, {
5210
5452
  kind: Kind.FRAGMENT_SPREAD,
5211
5453
  name: this.parseFragmentName(),
5212
5454
  directives: this.parseDirectives(false),
5213
- loc: this.loc(start)
5214
- };
5455
+ });
5215
5456
  }
5216
5457
 
5217
- return {
5458
+ return this.node(start, {
5218
5459
  kind: Kind.INLINE_FRAGMENT,
5219
5460
  typeCondition: hasTypeCondition ? this.parseNamedType() : undefined,
5220
5461
  directives: this.parseDirectives(false),
5221
5462
  selectionSet: this.parseSelectionSet(),
5222
- loc: this.loc(start)
5223
- };
5463
+ });
5224
5464
  }
5225
5465
  /**
5226
5466
  * FragmentDefinition :
@@ -5228,43 +5468,43 @@ var Parser = /*#__PURE__*/function () {
5228
5468
  *
5229
5469
  * TypeCondition : NamedType
5230
5470
  */
5231
- ;
5232
5471
 
5233
- _proto.parseFragmentDefinition = function parseFragmentDefinition() {
5472
+ parseFragmentDefinition() {
5234
5473
  var _this$_options;
5235
5474
 
5236
- var start = this._lexer.token;
5237
- this.expectKeyword('fragment'); // Experimental support for defining variables within fragments changes
5475
+ const start = this._lexer.token;
5476
+ this.expectKeyword('fragment'); // Legacy support for defining variables within fragments changes
5238
5477
  // the grammar of FragmentDefinition:
5239
5478
  // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
5240
5479
 
5241
- if (((_this$_options = this._options) === null || _this$_options === void 0 ? void 0 : _this$_options.experimentalFragmentVariables) === true) {
5242
- return {
5480
+ if (
5481
+ ((_this$_options = this._options) === null || _this$_options === void 0
5482
+ ? void 0
5483
+ : _this$_options.allowLegacyFragmentVariables) === true
5484
+ ) {
5485
+ return this.node(start, {
5243
5486
  kind: Kind.FRAGMENT_DEFINITION,
5244
5487
  name: this.parseFragmentName(),
5245
5488
  variableDefinitions: this.parseVariableDefinitions(),
5246
5489
  typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
5247
5490
  directives: this.parseDirectives(false),
5248
5491
  selectionSet: this.parseSelectionSet(),
5249
- loc: this.loc(start)
5250
- };
5492
+ });
5251
5493
  }
5252
5494
 
5253
- return {
5495
+ return this.node(start, {
5254
5496
  kind: Kind.FRAGMENT_DEFINITION,
5255
5497
  name: this.parseFragmentName(),
5256
5498
  typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
5257
5499
  directives: this.parseDirectives(false),
5258
5500
  selectionSet: this.parseSelectionSet(),
5259
- loc: this.loc(start)
5260
- };
5501
+ });
5261
5502
  }
5262
5503
  /**
5263
5504
  * FragmentName : Name but not `on`
5264
5505
  */
5265
- ;
5266
5506
 
5267
- _proto.parseFragmentName = function parseFragmentName() {
5507
+ parseFragmentName() {
5268
5508
  if (this._lexer.token.value === 'on') {
5269
5509
  throw this.unexpected();
5270
5510
  }
@@ -5290,10 +5530,9 @@ var Parser = /*#__PURE__*/function () {
5290
5530
  *
5291
5531
  * EnumValue : Name but not `true`, `false` or `null`
5292
5532
  */
5293
- ;
5294
5533
 
5295
- _proto.parseValueLiteral = function parseValueLiteral(isConst) {
5296
- var token = this._lexer.token;
5534
+ parseValueLiteral(isConst) {
5535
+ const token = this._lexer.token;
5297
5536
 
5298
5537
  switch (token.kind) {
5299
5538
  case TokenKind.BRACKET_L:
@@ -5305,20 +5544,18 @@ var Parser = /*#__PURE__*/function () {
5305
5544
  case TokenKind.INT:
5306
5545
  this._lexer.advance();
5307
5546
 
5308
- return {
5547
+ return this.node(token, {
5309
5548
  kind: Kind.INT,
5310
5549
  value: token.value,
5311
- loc: this.loc(token)
5312
- };
5550
+ });
5313
5551
 
5314
5552
  case TokenKind.FLOAT:
5315
5553
  this._lexer.advance();
5316
5554
 
5317
- return {
5555
+ return this.node(token, {
5318
5556
  kind: Kind.FLOAT,
5319
5557
  value: token.value,
5320
- loc: this.loc(token)
5321
- };
5558
+ });
5322
5559
 
5323
5560
  case TokenKind.STRING:
5324
5561
  case TokenKind.BLOCK_STRING:
@@ -5329,124 +5566,118 @@ var Parser = /*#__PURE__*/function () {
5329
5566
 
5330
5567
  switch (token.value) {
5331
5568
  case 'true':
5332
- return {
5569
+ return this.node(token, {
5333
5570
  kind: Kind.BOOLEAN,
5334
5571
  value: true,
5335
- loc: this.loc(token)
5336
- };
5572
+ });
5337
5573
 
5338
5574
  case 'false':
5339
- return {
5575
+ return this.node(token, {
5340
5576
  kind: Kind.BOOLEAN,
5341
5577
  value: false,
5342
- loc: this.loc(token)
5343
- };
5578
+ });
5344
5579
 
5345
5580
  case 'null':
5346
- return {
5581
+ return this.node(token, {
5347
5582
  kind: Kind.NULL,
5348
- loc: this.loc(token)
5349
- };
5583
+ });
5350
5584
 
5351
5585
  default:
5352
- return {
5586
+ return this.node(token, {
5353
5587
  kind: Kind.ENUM,
5354
5588
  value: token.value,
5355
- loc: this.loc(token)
5356
- };
5589
+ });
5357
5590
  }
5358
5591
 
5359
5592
  case TokenKind.DOLLAR:
5360
- if (!isConst) {
5361
- return this.parseVariable();
5593
+ if (isConst) {
5594
+ this.expectToken(TokenKind.DOLLAR);
5595
+
5596
+ if (this._lexer.token.kind === TokenKind.NAME) {
5597
+ const varName = this._lexer.token.value;
5598
+ throw syntaxError(
5599
+ this._lexer.source,
5600
+ token.start,
5601
+ `Unexpected variable "$${varName}" in constant value.`,
5602
+ );
5603
+ } else {
5604
+ throw this.unexpected(token);
5605
+ }
5362
5606
  }
5363
5607
 
5364
- break;
5608
+ return this.parseVariable();
5609
+
5610
+ default:
5611
+ throw this.unexpected();
5365
5612
  }
5613
+ }
5366
5614
 
5367
- throw this.unexpected();
5368
- };
5615
+ parseConstValueLiteral() {
5616
+ return this.parseValueLiteral(true);
5617
+ }
5369
5618
 
5370
- _proto.parseStringLiteral = function parseStringLiteral() {
5371
- var token = this._lexer.token;
5619
+ parseStringLiteral() {
5620
+ const token = this._lexer.token;
5372
5621
 
5373
5622
  this._lexer.advance();
5374
5623
 
5375
- return {
5624
+ return this.node(token, {
5376
5625
  kind: Kind.STRING,
5377
5626
  value: token.value,
5378
5627
  block: token.kind === TokenKind.BLOCK_STRING,
5379
- loc: this.loc(token)
5380
- };
5628
+ });
5381
5629
  }
5382
5630
  /**
5383
5631
  * ListValue[Const] :
5384
5632
  * - [ ]
5385
5633
  * - [ Value[?Const]+ ]
5386
5634
  */
5387
- ;
5388
-
5389
- _proto.parseList = function parseList(isConst) {
5390
- var _this = this;
5391
5635
 
5392
- var start = this._lexer.token;
5393
-
5394
- var item = function item() {
5395
- return _this.parseValueLiteral(isConst);
5396
- };
5636
+ parseList(isConst) {
5637
+ const item = () => this.parseValueLiteral(isConst);
5397
5638
 
5398
- return {
5639
+ return this.node(this._lexer.token, {
5399
5640
  kind: Kind.LIST,
5400
5641
  values: this.any(TokenKind.BRACKET_L, item, TokenKind.BRACKET_R),
5401
- loc: this.loc(start)
5402
- };
5642
+ });
5403
5643
  }
5404
5644
  /**
5645
+ * ```
5405
5646
  * ObjectValue[Const] :
5406
5647
  * - { }
5407
5648
  * - { ObjectField[?Const]+ }
5649
+ * ```
5408
5650
  */
5409
- ;
5410
-
5411
- _proto.parseObject = function parseObject(isConst) {
5412
- var _this2 = this;
5413
5651
 
5414
- var start = this._lexer.token;
5652
+ parseObject(isConst) {
5653
+ const item = () => this.parseObjectField(isConst);
5415
5654
 
5416
- var item = function item() {
5417
- return _this2.parseObjectField(isConst);
5418
- };
5419
-
5420
- return {
5655
+ return this.node(this._lexer.token, {
5421
5656
  kind: Kind.OBJECT,
5422
5657
  fields: this.any(TokenKind.BRACE_L, item, TokenKind.BRACE_R),
5423
- loc: this.loc(start)
5424
- };
5658
+ });
5425
5659
  }
5426
5660
  /**
5427
5661
  * ObjectField[Const] : Name : Value[?Const]
5428
5662
  */
5429
- ;
5430
5663
 
5431
- _proto.parseObjectField = function parseObjectField(isConst) {
5432
- var start = this._lexer.token;
5433
- var name = this.parseName();
5664
+ parseObjectField(isConst) {
5665
+ const start = this._lexer.token;
5666
+ const name = this.parseName();
5434
5667
  this.expectToken(TokenKind.COLON);
5435
- return {
5668
+ return this.node(start, {
5436
5669
  kind: Kind.OBJECT_FIELD,
5437
- name: name,
5670
+ name,
5438
5671
  value: this.parseValueLiteral(isConst),
5439
- loc: this.loc(start)
5440
- };
5672
+ });
5441
5673
  } // Implements the parsing rules in the Directives section.
5442
5674
 
5443
5675
  /**
5444
5676
  * Directives[Const] : Directive[?Const]+
5445
5677
  */
5446
- ;
5447
5678
 
5448
- _proto.parseDirectives = function parseDirectives(isConst) {
5449
- var directives = [];
5679
+ parseDirectives(isConst) {
5680
+ const directives = [];
5450
5681
 
5451
5682
  while (this.peek(TokenKind.AT)) {
5452
5683
  directives.push(this.parseDirective(isConst));
@@ -5454,20 +5685,24 @@ var Parser = /*#__PURE__*/function () {
5454
5685
 
5455
5686
  return directives;
5456
5687
  }
5688
+
5689
+ parseConstDirectives() {
5690
+ return this.parseDirectives(true);
5691
+ }
5457
5692
  /**
5693
+ * ```
5458
5694
  * Directive[Const] : @ Name Arguments[?Const]?
5695
+ * ```
5459
5696
  */
5460
- ;
5461
5697
 
5462
- _proto.parseDirective = function parseDirective(isConst) {
5463
- var start = this._lexer.token;
5698
+ parseDirective(isConst) {
5699
+ const start = this._lexer.token;
5464
5700
  this.expectToken(TokenKind.AT);
5465
- return {
5701
+ return this.node(start, {
5466
5702
  kind: Kind.DIRECTIVE,
5467
5703
  name: this.parseName(),
5468
5704
  arguments: this.parseArguments(isConst),
5469
- loc: this.loc(start)
5470
- };
5705
+ });
5471
5706
  } // Implements the parsing rules in the Types section.
5472
5707
 
5473
5708
  /**
@@ -5476,30 +5711,27 @@ var Parser = /*#__PURE__*/function () {
5476
5711
  * - ListType
5477
5712
  * - NonNullType
5478
5713
  */
5479
- ;
5480
5714
 
5481
- _proto.parseTypeReference = function parseTypeReference() {
5482
- var start = this._lexer.token;
5483
- var type;
5715
+ parseTypeReference() {
5716
+ const start = this._lexer.token;
5717
+ let type;
5484
5718
 
5485
5719
  if (this.expectOptionalToken(TokenKind.BRACKET_L)) {
5486
- type = this.parseTypeReference();
5720
+ const innerType = this.parseTypeReference();
5487
5721
  this.expectToken(TokenKind.BRACKET_R);
5488
- type = {
5722
+ type = this.node(start, {
5489
5723
  kind: Kind.LIST_TYPE,
5490
- type: type,
5491
- loc: this.loc(start)
5492
- };
5724
+ type: innerType,
5725
+ });
5493
5726
  } else {
5494
5727
  type = this.parseNamedType();
5495
5728
  }
5496
5729
 
5497
5730
  if (this.expectOptionalToken(TokenKind.BANG)) {
5498
- return {
5731
+ return this.node(start, {
5499
5732
  kind: Kind.NON_NULL_TYPE,
5500
- type: type,
5501
- loc: this.loc(start)
5502
- };
5733
+ type,
5734
+ });
5503
5735
  }
5504
5736
 
5505
5737
  return type;
@@ -5507,404 +5739,343 @@ var Parser = /*#__PURE__*/function () {
5507
5739
  /**
5508
5740
  * NamedType : Name
5509
5741
  */
5510
- ;
5511
5742
 
5512
- _proto.parseNamedType = function parseNamedType() {
5513
- var start = this._lexer.token;
5514
- return {
5743
+ parseNamedType() {
5744
+ return this.node(this._lexer.token, {
5515
5745
  kind: Kind.NAMED_TYPE,
5516
5746
  name: this.parseName(),
5517
- loc: this.loc(start)
5518
- };
5747
+ });
5519
5748
  } // Implements the parsing rules in the Type Definition section.
5520
5749
 
5521
- /**
5522
- * TypeSystemDefinition :
5523
- * - SchemaDefinition
5524
- * - TypeDefinition
5525
- * - DirectiveDefinition
5526
- *
5527
- * TypeDefinition :
5528
- * - ScalarTypeDefinition
5529
- * - ObjectTypeDefinition
5530
- * - InterfaceTypeDefinition
5531
- * - UnionTypeDefinition
5532
- * - EnumTypeDefinition
5533
- * - InputObjectTypeDefinition
5534
- */
5535
- ;
5536
-
5537
- _proto.parseTypeSystemDefinition = function parseTypeSystemDefinition() {
5538
- // Many definitions begin with a description and require a lookahead.
5539
- var keywordToken = this.peekDescription() ? this._lexer.lookahead() : this._lexer.token;
5540
-
5541
- if (keywordToken.kind === TokenKind.NAME) {
5542
- switch (keywordToken.value) {
5543
- case 'schema':
5544
- return this.parseSchemaDefinition();
5545
-
5546
- case 'scalar':
5547
- return this.parseScalarTypeDefinition();
5548
-
5549
- case 'type':
5550
- return this.parseObjectTypeDefinition();
5551
-
5552
- case 'interface':
5553
- return this.parseInterfaceTypeDefinition();
5554
-
5555
- case 'union':
5556
- return this.parseUnionTypeDefinition();
5557
-
5558
- case 'enum':
5559
- return this.parseEnumTypeDefinition();
5560
-
5561
- case 'input':
5562
- return this.parseInputObjectTypeDefinition();
5563
-
5564
- case 'directive':
5565
- return this.parseDirectiveDefinition();
5566
- }
5567
- }
5568
-
5569
- throw this.unexpected(keywordToken);
5570
- };
5571
-
5572
- _proto.peekDescription = function peekDescription() {
5750
+ peekDescription() {
5573
5751
  return this.peek(TokenKind.STRING) || this.peek(TokenKind.BLOCK_STRING);
5574
5752
  }
5575
5753
  /**
5576
5754
  * Description : StringValue
5577
5755
  */
5578
- ;
5579
5756
 
5580
- _proto.parseDescription = function parseDescription() {
5757
+ parseDescription() {
5581
5758
  if (this.peekDescription()) {
5582
5759
  return this.parseStringLiteral();
5583
5760
  }
5584
5761
  }
5585
5762
  /**
5763
+ * ```
5586
5764
  * SchemaDefinition : Description? schema Directives[Const]? { OperationTypeDefinition+ }
5765
+ * ```
5587
5766
  */
5588
- ;
5589
5767
 
5590
- _proto.parseSchemaDefinition = function parseSchemaDefinition() {
5591
- var start = this._lexer.token;
5592
- var description = this.parseDescription();
5768
+ parseSchemaDefinition() {
5769
+ const start = this._lexer.token;
5770
+ const description = this.parseDescription();
5593
5771
  this.expectKeyword('schema');
5594
- var directives = this.parseDirectives(true);
5595
- var operationTypes = this.many(TokenKind.BRACE_L, this.parseOperationTypeDefinition, TokenKind.BRACE_R);
5596
- return {
5772
+ const directives = this.parseConstDirectives();
5773
+ const operationTypes = this.many(
5774
+ TokenKind.BRACE_L,
5775
+ this.parseOperationTypeDefinition,
5776
+ TokenKind.BRACE_R,
5777
+ );
5778
+ return this.node(start, {
5597
5779
  kind: Kind.SCHEMA_DEFINITION,
5598
- description: description,
5599
- directives: directives,
5600
- operationTypes: operationTypes,
5601
- loc: this.loc(start)
5602
- };
5780
+ description,
5781
+ directives,
5782
+ operationTypes,
5783
+ });
5603
5784
  }
5604
5785
  /**
5605
5786
  * OperationTypeDefinition : OperationType : NamedType
5606
5787
  */
5607
- ;
5608
5788
 
5609
- _proto.parseOperationTypeDefinition = function parseOperationTypeDefinition() {
5610
- var start = this._lexer.token;
5611
- var operation = this.parseOperationType();
5789
+ parseOperationTypeDefinition() {
5790
+ const start = this._lexer.token;
5791
+ const operation = this.parseOperationType();
5612
5792
  this.expectToken(TokenKind.COLON);
5613
- var type = this.parseNamedType();
5614
- return {
5793
+ const type = this.parseNamedType();
5794
+ return this.node(start, {
5615
5795
  kind: Kind.OPERATION_TYPE_DEFINITION,
5616
- operation: operation,
5617
- type: type,
5618
- loc: this.loc(start)
5619
- };
5796
+ operation,
5797
+ type,
5798
+ });
5620
5799
  }
5621
5800
  /**
5622
5801
  * ScalarTypeDefinition : Description? scalar Name Directives[Const]?
5623
5802
  */
5624
- ;
5625
5803
 
5626
- _proto.parseScalarTypeDefinition = function parseScalarTypeDefinition() {
5627
- var start = this._lexer.token;
5628
- var description = this.parseDescription();
5804
+ parseScalarTypeDefinition() {
5805
+ const start = this._lexer.token;
5806
+ const description = this.parseDescription();
5629
5807
  this.expectKeyword('scalar');
5630
- var name = this.parseName();
5631
- var directives = this.parseDirectives(true);
5632
- return {
5808
+ const name = this.parseName();
5809
+ const directives = this.parseConstDirectives();
5810
+ return this.node(start, {
5633
5811
  kind: Kind.SCALAR_TYPE_DEFINITION,
5634
- description: description,
5635
- name: name,
5636
- directives: directives,
5637
- loc: this.loc(start)
5638
- };
5812
+ description,
5813
+ name,
5814
+ directives,
5815
+ });
5639
5816
  }
5640
5817
  /**
5641
5818
  * ObjectTypeDefinition :
5642
5819
  * Description?
5643
5820
  * type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
5644
5821
  */
5645
- ;
5646
5822
 
5647
- _proto.parseObjectTypeDefinition = function parseObjectTypeDefinition() {
5648
- var start = this._lexer.token;
5649
- var description = this.parseDescription();
5823
+ parseObjectTypeDefinition() {
5824
+ const start = this._lexer.token;
5825
+ const description = this.parseDescription();
5650
5826
  this.expectKeyword('type');
5651
- var name = this.parseName();
5652
- var interfaces = this.parseImplementsInterfaces();
5653
- var directives = this.parseDirectives(true);
5654
- var fields = this.parseFieldsDefinition();
5655
- return {
5827
+ const name = this.parseName();
5828
+ const interfaces = this.parseImplementsInterfaces();
5829
+ const directives = this.parseConstDirectives();
5830
+ const fields = this.parseFieldsDefinition();
5831
+ return this.node(start, {
5656
5832
  kind: Kind.OBJECT_TYPE_DEFINITION,
5657
- description: description,
5658
- name: name,
5659
- interfaces: interfaces,
5660
- directives: directives,
5661
- fields: fields,
5662
- loc: this.loc(start)
5663
- };
5833
+ description,
5834
+ name,
5835
+ interfaces,
5836
+ directives,
5837
+ fields,
5838
+ });
5664
5839
  }
5665
5840
  /**
5666
5841
  * ImplementsInterfaces :
5667
5842
  * - implements `&`? NamedType
5668
5843
  * - ImplementsInterfaces & NamedType
5669
5844
  */
5670
- ;
5671
-
5672
- _proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
5673
- var _this$_options2;
5674
-
5675
- if (!this.expectOptionalKeyword('implements')) {
5676
- return [];
5677
- }
5678
-
5679
- if (((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true) {
5680
- var types = []; // Optional leading ampersand
5681
-
5682
- this.expectOptionalToken(TokenKind.AMP);
5683
-
5684
- do {
5685
- types.push(this.parseNamedType());
5686
- } while (this.expectOptionalToken(TokenKind.AMP) || this.peek(TokenKind.NAME));
5687
5845
 
5688
- return types;
5689
- }
5690
-
5691
- return this.delimitedMany(TokenKind.AMP, this.parseNamedType);
5846
+ parseImplementsInterfaces() {
5847
+ return this.expectOptionalKeyword('implements')
5848
+ ? this.delimitedMany(TokenKind.AMP, this.parseNamedType)
5849
+ : [];
5692
5850
  }
5693
5851
  /**
5852
+ * ```
5694
5853
  * FieldsDefinition : { FieldDefinition+ }
5854
+ * ```
5695
5855
  */
5696
- ;
5697
-
5698
- _proto.parseFieldsDefinition = function parseFieldsDefinition() {
5699
- var _this$_options3;
5700
-
5701
- // Legacy support for the SDL?
5702
- if (((_this$_options3 = this._options) === null || _this$_options3 === void 0 ? void 0 : _this$_options3.allowLegacySDLEmptyFields) === true && this.peek(TokenKind.BRACE_L) && this._lexer.lookahead().kind === TokenKind.BRACE_R) {
5703
- this._lexer.advance();
5704
-
5705
- this._lexer.advance();
5706
-
5707
- return [];
5708
- }
5709
5856
 
5710
- return this.optionalMany(TokenKind.BRACE_L, this.parseFieldDefinition, TokenKind.BRACE_R);
5857
+ parseFieldsDefinition() {
5858
+ return this.optionalMany(
5859
+ TokenKind.BRACE_L,
5860
+ this.parseFieldDefinition,
5861
+ TokenKind.BRACE_R,
5862
+ );
5711
5863
  }
5712
5864
  /**
5713
5865
  * FieldDefinition :
5714
5866
  * - Description? Name ArgumentsDefinition? : Type Directives[Const]?
5715
5867
  */
5716
- ;
5717
5868
 
5718
- _proto.parseFieldDefinition = function parseFieldDefinition() {
5719
- var start = this._lexer.token;
5720
- var description = this.parseDescription();
5721
- var name = this.parseName();
5722
- var args = this.parseArgumentDefs();
5869
+ parseFieldDefinition() {
5870
+ const start = this._lexer.token;
5871
+ const description = this.parseDescription();
5872
+ const name = this.parseName();
5873
+ const args = this.parseArgumentDefs();
5723
5874
  this.expectToken(TokenKind.COLON);
5724
- var type = this.parseTypeReference();
5725
- var directives = this.parseDirectives(true);
5726
- return {
5875
+ const type = this.parseTypeReference();
5876
+ const directives = this.parseConstDirectives();
5877
+ return this.node(start, {
5727
5878
  kind: Kind.FIELD_DEFINITION,
5728
- description: description,
5729
- name: name,
5879
+ description,
5880
+ name,
5730
5881
  arguments: args,
5731
- type: type,
5732
- directives: directives,
5733
- loc: this.loc(start)
5734
- };
5882
+ type,
5883
+ directives,
5884
+ });
5735
5885
  }
5736
5886
  /**
5737
5887
  * ArgumentsDefinition : ( InputValueDefinition+ )
5738
5888
  */
5739
- ;
5740
5889
 
5741
- _proto.parseArgumentDefs = function parseArgumentDefs() {
5742
- return this.optionalMany(TokenKind.PAREN_L, this.parseInputValueDef, TokenKind.PAREN_R);
5890
+ parseArgumentDefs() {
5891
+ return this.optionalMany(
5892
+ TokenKind.PAREN_L,
5893
+ this.parseInputValueDef,
5894
+ TokenKind.PAREN_R,
5895
+ );
5743
5896
  }
5744
5897
  /**
5745
5898
  * InputValueDefinition :
5746
5899
  * - Description? Name : Type DefaultValue? Directives[Const]?
5747
5900
  */
5748
- ;
5749
5901
 
5750
- _proto.parseInputValueDef = function parseInputValueDef() {
5751
- var start = this._lexer.token;
5752
- var description = this.parseDescription();
5753
- var name = this.parseName();
5902
+ parseInputValueDef() {
5903
+ const start = this._lexer.token;
5904
+ const description = this.parseDescription();
5905
+ const name = this.parseName();
5754
5906
  this.expectToken(TokenKind.COLON);
5755
- var type = this.parseTypeReference();
5756
- var defaultValue;
5907
+ const type = this.parseTypeReference();
5908
+ let defaultValue;
5757
5909
 
5758
5910
  if (this.expectOptionalToken(TokenKind.EQUALS)) {
5759
- defaultValue = this.parseValueLiteral(true);
5911
+ defaultValue = this.parseConstValueLiteral();
5760
5912
  }
5761
5913
 
5762
- var directives = this.parseDirectives(true);
5763
- return {
5914
+ const directives = this.parseConstDirectives();
5915
+ return this.node(start, {
5764
5916
  kind: Kind.INPUT_VALUE_DEFINITION,
5765
- description: description,
5766
- name: name,
5767
- type: type,
5768
- defaultValue: defaultValue,
5769
- directives: directives,
5770
- loc: this.loc(start)
5771
- };
5917
+ description,
5918
+ name,
5919
+ type,
5920
+ defaultValue,
5921
+ directives,
5922
+ });
5772
5923
  }
5773
5924
  /**
5774
5925
  * InterfaceTypeDefinition :
5775
5926
  * - Description? interface Name Directives[Const]? FieldsDefinition?
5776
5927
  */
5777
- ;
5778
5928
 
5779
- _proto.parseInterfaceTypeDefinition = function parseInterfaceTypeDefinition() {
5780
- var start = this._lexer.token;
5781
- var description = this.parseDescription();
5929
+ parseInterfaceTypeDefinition() {
5930
+ const start = this._lexer.token;
5931
+ const description = this.parseDescription();
5782
5932
  this.expectKeyword('interface');
5783
- var name = this.parseName();
5784
- var interfaces = this.parseImplementsInterfaces();
5785
- var directives = this.parseDirectives(true);
5786
- var fields = this.parseFieldsDefinition();
5787
- return {
5933
+ const name = this.parseName();
5934
+ const interfaces = this.parseImplementsInterfaces();
5935
+ const directives = this.parseConstDirectives();
5936
+ const fields = this.parseFieldsDefinition();
5937
+ return this.node(start, {
5788
5938
  kind: Kind.INTERFACE_TYPE_DEFINITION,
5789
- description: description,
5790
- name: name,
5791
- interfaces: interfaces,
5792
- directives: directives,
5793
- fields: fields,
5794
- loc: this.loc(start)
5795
- };
5939
+ description,
5940
+ name,
5941
+ interfaces,
5942
+ directives,
5943
+ fields,
5944
+ });
5796
5945
  }
5797
5946
  /**
5798
5947
  * UnionTypeDefinition :
5799
5948
  * - Description? union Name Directives[Const]? UnionMemberTypes?
5800
5949
  */
5801
- ;
5802
5950
 
5803
- _proto.parseUnionTypeDefinition = function parseUnionTypeDefinition() {
5804
- var start = this._lexer.token;
5805
- var description = this.parseDescription();
5951
+ parseUnionTypeDefinition() {
5952
+ const start = this._lexer.token;
5953
+ const description = this.parseDescription();
5806
5954
  this.expectKeyword('union');
5807
- var name = this.parseName();
5808
- var directives = this.parseDirectives(true);
5809
- var types = this.parseUnionMemberTypes();
5810
- return {
5955
+ const name = this.parseName();
5956
+ const directives = this.parseConstDirectives();
5957
+ const types = this.parseUnionMemberTypes();
5958
+ return this.node(start, {
5811
5959
  kind: Kind.UNION_TYPE_DEFINITION,
5812
- description: description,
5813
- name: name,
5814
- directives: directives,
5815
- types: types,
5816
- loc: this.loc(start)
5817
- };
5960
+ description,
5961
+ name,
5962
+ directives,
5963
+ types,
5964
+ });
5818
5965
  }
5819
5966
  /**
5820
5967
  * UnionMemberTypes :
5821
5968
  * - = `|`? NamedType
5822
5969
  * - UnionMemberTypes | NamedType
5823
5970
  */
5824
- ;
5825
5971
 
5826
- _proto.parseUnionMemberTypes = function parseUnionMemberTypes() {
5827
- return this.expectOptionalToken(TokenKind.EQUALS) ? this.delimitedMany(TokenKind.PIPE, this.parseNamedType) : [];
5972
+ parseUnionMemberTypes() {
5973
+ return this.expectOptionalToken(TokenKind.EQUALS)
5974
+ ? this.delimitedMany(TokenKind.PIPE, this.parseNamedType)
5975
+ : [];
5828
5976
  }
5829
5977
  /**
5830
5978
  * EnumTypeDefinition :
5831
5979
  * - Description? enum Name Directives[Const]? EnumValuesDefinition?
5832
5980
  */
5833
- ;
5834
5981
 
5835
- _proto.parseEnumTypeDefinition = function parseEnumTypeDefinition() {
5836
- var start = this._lexer.token;
5837
- var description = this.parseDescription();
5982
+ parseEnumTypeDefinition() {
5983
+ const start = this._lexer.token;
5984
+ const description = this.parseDescription();
5838
5985
  this.expectKeyword('enum');
5839
- var name = this.parseName();
5840
- var directives = this.parseDirectives(true);
5841
- var values = this.parseEnumValuesDefinition();
5842
- return {
5986
+ const name = this.parseName();
5987
+ const directives = this.parseConstDirectives();
5988
+ const values = this.parseEnumValuesDefinition();
5989
+ return this.node(start, {
5843
5990
  kind: Kind.ENUM_TYPE_DEFINITION,
5844
- description: description,
5845
- name: name,
5846
- directives: directives,
5847
- values: values,
5848
- loc: this.loc(start)
5849
- };
5991
+ description,
5992
+ name,
5993
+ directives,
5994
+ values,
5995
+ });
5850
5996
  }
5851
5997
  /**
5998
+ * ```
5852
5999
  * EnumValuesDefinition : { EnumValueDefinition+ }
6000
+ * ```
5853
6001
  */
5854
- ;
5855
6002
 
5856
- _proto.parseEnumValuesDefinition = function parseEnumValuesDefinition() {
5857
- return this.optionalMany(TokenKind.BRACE_L, this.parseEnumValueDefinition, TokenKind.BRACE_R);
6003
+ parseEnumValuesDefinition() {
6004
+ return this.optionalMany(
6005
+ TokenKind.BRACE_L,
6006
+ this.parseEnumValueDefinition,
6007
+ TokenKind.BRACE_R,
6008
+ );
5858
6009
  }
5859
6010
  /**
5860
6011
  * EnumValueDefinition : Description? EnumValue Directives[Const]?
5861
- *
5862
- * EnumValue : Name
5863
6012
  */
5864
- ;
5865
6013
 
5866
- _proto.parseEnumValueDefinition = function parseEnumValueDefinition() {
5867
- var start = this._lexer.token;
5868
- var description = this.parseDescription();
5869
- var name = this.parseName();
5870
- var directives = this.parseDirectives(true);
5871
- return {
6014
+ parseEnumValueDefinition() {
6015
+ const start = this._lexer.token;
6016
+ const description = this.parseDescription();
6017
+ const name = this.parseEnumValueName();
6018
+ const directives = this.parseConstDirectives();
6019
+ return this.node(start, {
5872
6020
  kind: Kind.ENUM_VALUE_DEFINITION,
5873
- description: description,
5874
- name: name,
5875
- directives: directives,
5876
- loc: this.loc(start)
5877
- };
6021
+ description,
6022
+ name,
6023
+ directives,
6024
+ });
6025
+ }
6026
+ /**
6027
+ * EnumValue : Name but not `true`, `false` or `null`
6028
+ */
6029
+
6030
+ parseEnumValueName() {
6031
+ if (
6032
+ this._lexer.token.value === 'true' ||
6033
+ this._lexer.token.value === 'false' ||
6034
+ this._lexer.token.value === 'null'
6035
+ ) {
6036
+ throw syntaxError(
6037
+ this._lexer.source,
6038
+ this._lexer.token.start,
6039
+ `${getTokenDesc(
6040
+ this._lexer.token,
6041
+ )} is reserved and cannot be used for an enum value.`,
6042
+ );
6043
+ }
6044
+
6045
+ return this.parseName();
5878
6046
  }
5879
6047
  /**
5880
6048
  * InputObjectTypeDefinition :
5881
6049
  * - Description? input Name Directives[Const]? InputFieldsDefinition?
5882
6050
  */
5883
- ;
5884
6051
 
5885
- _proto.parseInputObjectTypeDefinition = function parseInputObjectTypeDefinition() {
5886
- var start = this._lexer.token;
5887
- var description = this.parseDescription();
6052
+ parseInputObjectTypeDefinition() {
6053
+ const start = this._lexer.token;
6054
+ const description = this.parseDescription();
5888
6055
  this.expectKeyword('input');
5889
- var name = this.parseName();
5890
- var directives = this.parseDirectives(true);
5891
- var fields = this.parseInputFieldsDefinition();
5892
- return {
6056
+ const name = this.parseName();
6057
+ const directives = this.parseConstDirectives();
6058
+ const fields = this.parseInputFieldsDefinition();
6059
+ return this.node(start, {
5893
6060
  kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
5894
- description: description,
5895
- name: name,
5896
- directives: directives,
5897
- fields: fields,
5898
- loc: this.loc(start)
5899
- };
6061
+ description,
6062
+ name,
6063
+ directives,
6064
+ fields,
6065
+ });
5900
6066
  }
5901
6067
  /**
6068
+ * ```
5902
6069
  * InputFieldsDefinition : { InputValueDefinition+ }
6070
+ * ```
5903
6071
  */
5904
- ;
5905
6072
 
5906
- _proto.parseInputFieldsDefinition = function parseInputFieldsDefinition() {
5907
- return this.optionalMany(TokenKind.BRACE_L, this.parseInputValueDef, TokenKind.BRACE_R);
6073
+ parseInputFieldsDefinition() {
6074
+ return this.optionalMany(
6075
+ TokenKind.BRACE_L,
6076
+ this.parseInputValueDef,
6077
+ TokenKind.BRACE_R,
6078
+ );
5908
6079
  }
5909
6080
  /**
5910
6081
  * TypeSystemExtension :
@@ -5919,10 +6090,9 @@ var Parser = /*#__PURE__*/function () {
5919
6090
  * - EnumTypeExtension
5920
6091
  * - InputObjectTypeDefinition
5921
6092
  */
5922
- ;
5923
6093
 
5924
- _proto.parseTypeSystemExtension = function parseTypeSystemExtension() {
5925
- var keywordToken = this._lexer.lookahead();
6094
+ parseTypeSystemExtension() {
6095
+ const keywordToken = this._lexer.lookahead();
5926
6096
 
5927
6097
  if (keywordToken.kind === TokenKind.NAME) {
5928
6098
  switch (keywordToken.value) {
@@ -5952,53 +6122,55 @@ var Parser = /*#__PURE__*/function () {
5952
6122
  throw this.unexpected(keywordToken);
5953
6123
  }
5954
6124
  /**
6125
+ * ```
5955
6126
  * SchemaExtension :
5956
6127
  * - extend schema Directives[Const]? { OperationTypeDefinition+ }
5957
6128
  * - extend schema Directives[Const]
6129
+ * ```
5958
6130
  */
5959
- ;
5960
6131
 
5961
- _proto.parseSchemaExtension = function parseSchemaExtension() {
5962
- var start = this._lexer.token;
6132
+ parseSchemaExtension() {
6133
+ const start = this._lexer.token;
5963
6134
  this.expectKeyword('extend');
5964
6135
  this.expectKeyword('schema');
5965
- var directives = this.parseDirectives(true);
5966
- var operationTypes = this.optionalMany(TokenKind.BRACE_L, this.parseOperationTypeDefinition, TokenKind.BRACE_R);
6136
+ const directives = this.parseConstDirectives();
6137
+ const operationTypes = this.optionalMany(
6138
+ TokenKind.BRACE_L,
6139
+ this.parseOperationTypeDefinition,
6140
+ TokenKind.BRACE_R,
6141
+ );
5967
6142
 
5968
6143
  if (directives.length === 0 && operationTypes.length === 0) {
5969
6144
  throw this.unexpected();
5970
6145
  }
5971
6146
 
5972
- return {
6147
+ return this.node(start, {
5973
6148
  kind: Kind.SCHEMA_EXTENSION,
5974
- directives: directives,
5975
- operationTypes: operationTypes,
5976
- loc: this.loc(start)
5977
- };
6149
+ directives,
6150
+ operationTypes,
6151
+ });
5978
6152
  }
5979
6153
  /**
5980
6154
  * ScalarTypeExtension :
5981
6155
  * - extend scalar Name Directives[Const]
5982
6156
  */
5983
- ;
5984
6157
 
5985
- _proto.parseScalarTypeExtension = function parseScalarTypeExtension() {
5986
- var start = this._lexer.token;
6158
+ parseScalarTypeExtension() {
6159
+ const start = this._lexer.token;
5987
6160
  this.expectKeyword('extend');
5988
6161
  this.expectKeyword('scalar');
5989
- var name = this.parseName();
5990
- var directives = this.parseDirectives(true);
6162
+ const name = this.parseName();
6163
+ const directives = this.parseConstDirectives();
5991
6164
 
5992
6165
  if (directives.length === 0) {
5993
6166
  throw this.unexpected();
5994
6167
  }
5995
6168
 
5996
- return {
6169
+ return this.node(start, {
5997
6170
  kind: Kind.SCALAR_TYPE_EXTENSION,
5998
- name: name,
5999
- directives: directives,
6000
- loc: this.loc(start)
6001
- };
6171
+ name,
6172
+ directives,
6173
+ });
6002
6174
  }
6003
6175
  /**
6004
6176
  * ObjectTypeExtension :
@@ -6006,29 +6178,31 @@ var Parser = /*#__PURE__*/function () {
6006
6178
  * - extend type Name ImplementsInterfaces? Directives[Const]
6007
6179
  * - extend type Name ImplementsInterfaces
6008
6180
  */
6009
- ;
6010
6181
 
6011
- _proto.parseObjectTypeExtension = function parseObjectTypeExtension() {
6012
- var start = this._lexer.token;
6182
+ parseObjectTypeExtension() {
6183
+ const start = this._lexer.token;
6013
6184
  this.expectKeyword('extend');
6014
6185
  this.expectKeyword('type');
6015
- var name = this.parseName();
6016
- var interfaces = this.parseImplementsInterfaces();
6017
- var directives = this.parseDirectives(true);
6018
- var fields = this.parseFieldsDefinition();
6019
-
6020
- if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {
6186
+ const name = this.parseName();
6187
+ const interfaces = this.parseImplementsInterfaces();
6188
+ const directives = this.parseConstDirectives();
6189
+ const fields = this.parseFieldsDefinition();
6190
+
6191
+ if (
6192
+ interfaces.length === 0 &&
6193
+ directives.length === 0 &&
6194
+ fields.length === 0
6195
+ ) {
6021
6196
  throw this.unexpected();
6022
6197
  }
6023
6198
 
6024
- return {
6199
+ return this.node(start, {
6025
6200
  kind: Kind.OBJECT_TYPE_EXTENSION,
6026
- name: name,
6027
- interfaces: interfaces,
6028
- directives: directives,
6029
- fields: fields,
6030
- loc: this.loc(start)
6031
- };
6201
+ name,
6202
+ interfaces,
6203
+ directives,
6204
+ fields,
6205
+ });
6032
6206
  }
6033
6207
  /**
6034
6208
  * InterfaceTypeExtension :
@@ -6036,145 +6210,140 @@ var Parser = /*#__PURE__*/function () {
6036
6210
  * - extend interface Name ImplementsInterfaces? Directives[Const]
6037
6211
  * - extend interface Name ImplementsInterfaces
6038
6212
  */
6039
- ;
6040
6213
 
6041
- _proto.parseInterfaceTypeExtension = function parseInterfaceTypeExtension() {
6042
- var start = this._lexer.token;
6214
+ parseInterfaceTypeExtension() {
6215
+ const start = this._lexer.token;
6043
6216
  this.expectKeyword('extend');
6044
6217
  this.expectKeyword('interface');
6045
- var name = this.parseName();
6046
- var interfaces = this.parseImplementsInterfaces();
6047
- var directives = this.parseDirectives(true);
6048
- var fields = this.parseFieldsDefinition();
6049
-
6050
- if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {
6218
+ const name = this.parseName();
6219
+ const interfaces = this.parseImplementsInterfaces();
6220
+ const directives = this.parseConstDirectives();
6221
+ const fields = this.parseFieldsDefinition();
6222
+
6223
+ if (
6224
+ interfaces.length === 0 &&
6225
+ directives.length === 0 &&
6226
+ fields.length === 0
6227
+ ) {
6051
6228
  throw this.unexpected();
6052
6229
  }
6053
6230
 
6054
- return {
6231
+ return this.node(start, {
6055
6232
  kind: Kind.INTERFACE_TYPE_EXTENSION,
6056
- name: name,
6057
- interfaces: interfaces,
6058
- directives: directives,
6059
- fields: fields,
6060
- loc: this.loc(start)
6061
- };
6233
+ name,
6234
+ interfaces,
6235
+ directives,
6236
+ fields,
6237
+ });
6062
6238
  }
6063
6239
  /**
6064
6240
  * UnionTypeExtension :
6065
6241
  * - extend union Name Directives[Const]? UnionMemberTypes
6066
6242
  * - extend union Name Directives[Const]
6067
6243
  */
6068
- ;
6069
6244
 
6070
- _proto.parseUnionTypeExtension = function parseUnionTypeExtension() {
6071
- var start = this._lexer.token;
6245
+ parseUnionTypeExtension() {
6246
+ const start = this._lexer.token;
6072
6247
  this.expectKeyword('extend');
6073
6248
  this.expectKeyword('union');
6074
- var name = this.parseName();
6075
- var directives = this.parseDirectives(true);
6076
- var types = this.parseUnionMemberTypes();
6249
+ const name = this.parseName();
6250
+ const directives = this.parseConstDirectives();
6251
+ const types = this.parseUnionMemberTypes();
6077
6252
 
6078
6253
  if (directives.length === 0 && types.length === 0) {
6079
6254
  throw this.unexpected();
6080
6255
  }
6081
6256
 
6082
- return {
6257
+ return this.node(start, {
6083
6258
  kind: Kind.UNION_TYPE_EXTENSION,
6084
- name: name,
6085
- directives: directives,
6086
- types: types,
6087
- loc: this.loc(start)
6088
- };
6259
+ name,
6260
+ directives,
6261
+ types,
6262
+ });
6089
6263
  }
6090
6264
  /**
6091
6265
  * EnumTypeExtension :
6092
6266
  * - extend enum Name Directives[Const]? EnumValuesDefinition
6093
6267
  * - extend enum Name Directives[Const]
6094
6268
  */
6095
- ;
6096
6269
 
6097
- _proto.parseEnumTypeExtension = function parseEnumTypeExtension() {
6098
- var start = this._lexer.token;
6270
+ parseEnumTypeExtension() {
6271
+ const start = this._lexer.token;
6099
6272
  this.expectKeyword('extend');
6100
6273
  this.expectKeyword('enum');
6101
- var name = this.parseName();
6102
- var directives = this.parseDirectives(true);
6103
- var values = this.parseEnumValuesDefinition();
6274
+ const name = this.parseName();
6275
+ const directives = this.parseConstDirectives();
6276
+ const values = this.parseEnumValuesDefinition();
6104
6277
 
6105
6278
  if (directives.length === 0 && values.length === 0) {
6106
6279
  throw this.unexpected();
6107
6280
  }
6108
6281
 
6109
- return {
6282
+ return this.node(start, {
6110
6283
  kind: Kind.ENUM_TYPE_EXTENSION,
6111
- name: name,
6112
- directives: directives,
6113
- values: values,
6114
- loc: this.loc(start)
6115
- };
6284
+ name,
6285
+ directives,
6286
+ values,
6287
+ });
6116
6288
  }
6117
6289
  /**
6118
6290
  * InputObjectTypeExtension :
6119
6291
  * - extend input Name Directives[Const]? InputFieldsDefinition
6120
6292
  * - extend input Name Directives[Const]
6121
6293
  */
6122
- ;
6123
6294
 
6124
- _proto.parseInputObjectTypeExtension = function parseInputObjectTypeExtension() {
6125
- var start = this._lexer.token;
6295
+ parseInputObjectTypeExtension() {
6296
+ const start = this._lexer.token;
6126
6297
  this.expectKeyword('extend');
6127
6298
  this.expectKeyword('input');
6128
- var name = this.parseName();
6129
- var directives = this.parseDirectives(true);
6130
- var fields = this.parseInputFieldsDefinition();
6299
+ const name = this.parseName();
6300
+ const directives = this.parseConstDirectives();
6301
+ const fields = this.parseInputFieldsDefinition();
6131
6302
 
6132
6303
  if (directives.length === 0 && fields.length === 0) {
6133
6304
  throw this.unexpected();
6134
6305
  }
6135
6306
 
6136
- return {
6307
+ return this.node(start, {
6137
6308
  kind: Kind.INPUT_OBJECT_TYPE_EXTENSION,
6138
- name: name,
6139
- directives: directives,
6140
- fields: fields,
6141
- loc: this.loc(start)
6142
- };
6309
+ name,
6310
+ directives,
6311
+ fields,
6312
+ });
6143
6313
  }
6144
6314
  /**
6315
+ * ```
6145
6316
  * DirectiveDefinition :
6146
6317
  * - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
6318
+ * ```
6147
6319
  */
6148
- ;
6149
6320
 
6150
- _proto.parseDirectiveDefinition = function parseDirectiveDefinition() {
6151
- var start = this._lexer.token;
6152
- var description = this.parseDescription();
6321
+ parseDirectiveDefinition() {
6322
+ const start = this._lexer.token;
6323
+ const description = this.parseDescription();
6153
6324
  this.expectKeyword('directive');
6154
6325
  this.expectToken(TokenKind.AT);
6155
- var name = this.parseName();
6156
- var args = this.parseArgumentDefs();
6157
- var repeatable = this.expectOptionalKeyword('repeatable');
6326
+ const name = this.parseName();
6327
+ const args = this.parseArgumentDefs();
6328
+ const repeatable = this.expectOptionalKeyword('repeatable');
6158
6329
  this.expectKeyword('on');
6159
- var locations = this.parseDirectiveLocations();
6160
- return {
6330
+ const locations = this.parseDirectiveLocations();
6331
+ return this.node(start, {
6161
6332
  kind: Kind.DIRECTIVE_DEFINITION,
6162
- description: description,
6163
- name: name,
6333
+ description,
6334
+ name,
6164
6335
  arguments: args,
6165
- repeatable: repeatable,
6166
- locations: locations,
6167
- loc: this.loc(start)
6168
- };
6336
+ repeatable,
6337
+ locations,
6338
+ });
6169
6339
  }
6170
6340
  /**
6171
6341
  * DirectiveLocations :
6172
6342
  * - `|`? DirectiveLocation
6173
6343
  * - DirectiveLocations | DirectiveLocation
6174
6344
  */
6175
- ;
6176
6345
 
6177
- _proto.parseDirectiveLocations = function parseDirectiveLocations() {
6346
+ parseDirectiveLocations() {
6178
6347
  return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);
6179
6348
  }
6180
6349
  /*
@@ -6204,13 +6373,12 @@ var Parser = /*#__PURE__*/function () {
6204
6373
  * `INPUT_OBJECT`
6205
6374
  * `INPUT_FIELD_DEFINITION`
6206
6375
  */
6207
- ;
6208
6376
 
6209
- _proto.parseDirectiveLocation = function parseDirectiveLocation() {
6210
- var start = this._lexer.token;
6211
- var name = this.parseName();
6377
+ parseDirectiveLocation() {
6378
+ const start = this._lexer.token;
6379
+ const name = this.parseName();
6212
6380
 
6213
- if (DirectiveLocation[name.value] !== undefined) {
6381
+ if (Object.prototype.hasOwnProperty.call(DirectiveLocation, name.value)) {
6214
6382
  return name;
6215
6383
  }
6216
6384
 
@@ -6218,33 +6386,42 @@ var Parser = /*#__PURE__*/function () {
6218
6386
  } // Core parsing utility functions
6219
6387
 
6220
6388
  /**
6221
- * Returns a location object, used to identify the place in the source that created a given parsed object.
6389
+ * Returns a node that, if configured to do so, sets a "loc" field as a
6390
+ * location object, used to identify the place in the source that created a
6391
+ * given parsed object.
6222
6392
  */
6223
- ;
6224
6393
 
6225
- _proto.loc = function loc(startToken) {
6226
- var _this$_options4;
6394
+ node(startToken, node) {
6395
+ var _this$_options2;
6227
6396
 
6228
- if (((_this$_options4 = this._options) === null || _this$_options4 === void 0 ? void 0 : _this$_options4.noLocation) !== true) {
6229
- return new Location(startToken, this._lexer.lastToken, this._lexer.source);
6397
+ if (
6398
+ ((_this$_options2 = this._options) === null || _this$_options2 === void 0
6399
+ ? void 0
6400
+ : _this$_options2.noLocation) !== true
6401
+ ) {
6402
+ node.loc = new Location(
6403
+ startToken,
6404
+ this._lexer.lastToken,
6405
+ this._lexer.source,
6406
+ );
6230
6407
  }
6408
+
6409
+ return node;
6231
6410
  }
6232
6411
  /**
6233
6412
  * Determines if the next token is of a given kind
6234
6413
  */
6235
- ;
6236
6414
 
6237
- _proto.peek = function peek(kind) {
6415
+ peek(kind) {
6238
6416
  return this._lexer.token.kind === kind;
6239
6417
  }
6240
6418
  /**
6241
6419
  * If the next token is of the given kind, return that token after advancing the lexer.
6242
6420
  * Otherwise, do not change the parser state and throw an error.
6243
6421
  */
6244
- ;
6245
6422
 
6246
- _proto.expectToken = function expectToken(kind) {
6247
- var token = this._lexer.token;
6423
+ expectToken(kind) {
6424
+ const token = this._lexer.token;
6248
6425
 
6249
6426
  if (token.kind === kind) {
6250
6427
  this._lexer.advance();
@@ -6252,48 +6429,53 @@ var Parser = /*#__PURE__*/function () {
6252
6429
  return token;
6253
6430
  }
6254
6431
 
6255
- throw syntaxError(this._lexer.source, token.start, "Expected ".concat(getTokenKindDesc(kind), ", found ").concat(getTokenDesc(token), "."));
6432
+ throw syntaxError(
6433
+ this._lexer.source,
6434
+ token.start,
6435
+ `Expected ${getTokenKindDesc(kind)}, found ${getTokenDesc(token)}.`,
6436
+ );
6256
6437
  }
6257
6438
  /**
6258
- * If the next token is of the given kind, return that token after advancing the lexer.
6259
- * Otherwise, do not change the parser state and return undefined.
6439
+ * If the next token is of the given kind, return "true" after advancing the lexer.
6440
+ * Otherwise, do not change the parser state and return "false".
6260
6441
  */
6261
- ;
6262
6442
 
6263
- _proto.expectOptionalToken = function expectOptionalToken(kind) {
6264
- var token = this._lexer.token;
6443
+ expectOptionalToken(kind) {
6444
+ const token = this._lexer.token;
6265
6445
 
6266
6446
  if (token.kind === kind) {
6267
6447
  this._lexer.advance();
6268
6448
 
6269
- return token;
6449
+ return true;
6270
6450
  }
6271
6451
 
6272
- return undefined;
6452
+ return false;
6273
6453
  }
6274
6454
  /**
6275
6455
  * If the next token is a given keyword, advance the lexer.
6276
6456
  * Otherwise, do not change the parser state and throw an error.
6277
6457
  */
6278
- ;
6279
6458
 
6280
- _proto.expectKeyword = function expectKeyword(value) {
6281
- var token = this._lexer.token;
6459
+ expectKeyword(value) {
6460
+ const token = this._lexer.token;
6282
6461
 
6283
6462
  if (token.kind === TokenKind.NAME && token.value === value) {
6284
6463
  this._lexer.advance();
6285
6464
  } else {
6286
- throw syntaxError(this._lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(token), "."));
6465
+ throw syntaxError(
6466
+ this._lexer.source,
6467
+ token.start,
6468
+ `Expected "${value}", found ${getTokenDesc(token)}.`,
6469
+ );
6287
6470
  }
6288
6471
  }
6289
6472
  /**
6290
6473
  * If the next token is a given keyword, return "true" after advancing the lexer.
6291
6474
  * Otherwise, do not change the parser state and return "false".
6292
6475
  */
6293
- ;
6294
6476
 
6295
- _proto.expectOptionalKeyword = function expectOptionalKeyword(value) {
6296
- var token = this._lexer.token;
6477
+ expectOptionalKeyword(value) {
6478
+ const token = this._lexer.token;
6297
6479
 
6298
6480
  if (token.kind === TokenKind.NAME && token.value === value) {
6299
6481
  this._lexer.advance();
@@ -6306,22 +6488,25 @@ var Parser = /*#__PURE__*/function () {
6306
6488
  /**
6307
6489
  * Helper function for creating an error when an unexpected lexed token is encountered.
6308
6490
  */
6309
- ;
6310
6491
 
6311
- _proto.unexpected = function unexpected(atToken) {
6312
- var token = atToken !== null && atToken !== void 0 ? atToken : this._lexer.token;
6313
- return syntaxError(this._lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token), "."));
6492
+ unexpected(atToken) {
6493
+ const token =
6494
+ atToken !== null && atToken !== void 0 ? atToken : this._lexer.token;
6495
+ return syntaxError(
6496
+ this._lexer.source,
6497
+ token.start,
6498
+ `Unexpected ${getTokenDesc(token)}.`,
6499
+ );
6314
6500
  }
6315
6501
  /**
6316
6502
  * Returns a possibly empty list of parse nodes, determined by the parseFn.
6317
6503
  * This list begins with a lex token of openKind and ends with a lex token of closeKind.
6318
6504
  * Advances the parser to the next lex token after the closing token.
6319
6505
  */
6320
- ;
6321
6506
 
6322
- _proto.any = function any(openKind, parseFn, closeKind) {
6507
+ any(openKind, parseFn, closeKind) {
6323
6508
  this.expectToken(openKind);
6324
- var nodes = [];
6509
+ const nodes = [];
6325
6510
 
6326
6511
  while (!this.expectOptionalToken(closeKind)) {
6327
6512
  nodes.push(parseFn.call(this));
@@ -6335,11 +6520,10 @@ var Parser = /*#__PURE__*/function () {
6335
6520
  * that begins with a lex token of openKind and ends with a lex token of closeKind.
6336
6521
  * Advances the parser to the next lex token after the closing token.
6337
6522
  */
6338
- ;
6339
6523
 
6340
- _proto.optionalMany = function optionalMany(openKind, parseFn, closeKind) {
6524
+ optionalMany(openKind, parseFn, closeKind) {
6341
6525
  if (this.expectOptionalToken(openKind)) {
6342
- var nodes = [];
6526
+ const nodes = [];
6343
6527
 
6344
6528
  do {
6345
6529
  nodes.push(parseFn.call(this));
@@ -6355,11 +6539,10 @@ var Parser = /*#__PURE__*/function () {
6355
6539
  * This list begins with a lex token of openKind and ends with a lex token of closeKind.
6356
6540
  * Advances the parser to the next lex token after the closing token.
6357
6541
  */
6358
- ;
6359
6542
 
6360
- _proto.many = function many(openKind, parseFn, closeKind) {
6543
+ many(openKind, parseFn, closeKind) {
6361
6544
  this.expectToken(openKind);
6362
- var nodes = [];
6545
+ const nodes = [];
6363
6546
 
6364
6547
  do {
6365
6548
  nodes.push(parseFn.call(this));
@@ -6372,36 +6555,32 @@ var Parser = /*#__PURE__*/function () {
6372
6555
  * This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
6373
6556
  * Advances the parser to the next lex token after last item in the list.
6374
6557
  */
6375
- ;
6376
6558
 
6377
- _proto.delimitedMany = function delimitedMany(delimiterKind, parseFn) {
6559
+ delimitedMany(delimiterKind, parseFn) {
6378
6560
  this.expectOptionalToken(delimiterKind);
6379
- var nodes = [];
6561
+ const nodes = [];
6380
6562
 
6381
6563
  do {
6382
6564
  nodes.push(parseFn.call(this));
6383
6565
  } while (this.expectOptionalToken(delimiterKind));
6384
6566
 
6385
6567
  return nodes;
6386
- };
6387
-
6388
- return Parser;
6389
- }();
6568
+ }
6569
+ }
6390
6570
  /**
6391
6571
  * A helper function to describe a token as a string for debugging.
6392
6572
  */
6393
6573
 
6394
6574
  function getTokenDesc(token) {
6395
- var value = token.value;
6396
- return getTokenKindDesc(token.kind) + (value != null ? " \"".concat(value, "\"") : '');
6575
+ const value = token.value;
6576
+ return getTokenKindDesc(token.kind) + (value != null ? ` "${value}"` : '');
6397
6577
  }
6398
6578
  /**
6399
6579
  * A helper function to describe a token kind as a string for debugging.
6400
6580
  */
6401
6581
 
6402
-
6403
6582
  function getTokenKindDesc(kind) {
6404
- return isPunctuatorTokenKind(kind) ? "\"".concat(kind, "\"") : kind;
6583
+ return isPunctuatorTokenKind(kind) ? `"${kind}"` : kind;
6405
6584
  }
6406
6585
 
6407
6586
  /**
@@ -7782,56 +7961,71 @@ ${handlers.map((handler) => ` • ${handler.info.header}`).join('\n')}`;
7782
7961
  return `Did you mean to request "${handlers[0].info.header}" instead?`;
7783
7962
  }
7784
7963
  function onUnhandledRequest(request, handlers, strategy = 'warn') {
7785
- if (typeof strategy === 'function') {
7786
- strategy(request);
7787
- return;
7788
- }
7789
- /**
7790
- * @note Ignore exceptions during GraphQL request parsing because at this point
7791
- * we cannot assume the unhandled request is a valid GraphQL request.
7792
- * If the GraphQL parsing fails, just don't treat it as a GraphQL request.
7793
- */
7794
7964
  const parsedGraphQLQuery = tryCatch(() => parseGraphQLRequest(request));
7795
- const handlerGroups = groupHandlersByType(handlers);
7796
- const relevantHandlers = parsedGraphQLQuery
7797
- ? handlerGroups.graphql
7798
- : handlerGroups.rest;
7799
- const suggestedHandlers = getSuggestedHandler(request, relevantHandlers, parsedGraphQLQuery
7800
- ? getGraphQLHandlerScore(parsedGraphQLQuery)
7801
- : getRestHandlerScore());
7802
- const handlerSuggestion = suggestedHandlers.length > 0
7803
- ? getSuggestedHandlersMessage(suggestedHandlers)
7804
- : '';
7805
- const publicUrl = getPublicUrlFromRequest(request);
7806
- const requestHeader = parsedGraphQLQuery
7807
- ? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})`
7808
- : `${request.method} ${publicUrl}`;
7809
- const messageTemplate = [
7810
- `captured a request without a matching request handler:`,
7811
- ` \u2022 ${requestHeader}`,
7812
- handlerSuggestion,
7813
- `\
7965
+ function generateHandlerSuggestion() {
7966
+ /**
7967
+ * @note Ignore exceptions during GraphQL request parsing because at this point
7968
+ * we cannot assume the unhandled request is a valid GraphQL request.
7969
+ * If the GraphQL parsing fails, just don't treat it as a GraphQL request.
7970
+ */
7971
+ const handlerGroups = groupHandlersByType(handlers);
7972
+ const relevantHandlers = parsedGraphQLQuery
7973
+ ? handlerGroups.graphql
7974
+ : handlerGroups.rest;
7975
+ const suggestedHandlers = getSuggestedHandler(request, relevantHandlers, parsedGraphQLQuery
7976
+ ? getGraphQLHandlerScore(parsedGraphQLQuery)
7977
+ : getRestHandlerScore());
7978
+ return suggestedHandlers.length > 0
7979
+ ? getSuggestedHandlersMessage(suggestedHandlers)
7980
+ : '';
7981
+ }
7982
+ function generateUnhandledRequestMessage() {
7983
+ const publicUrl = getPublicUrlFromRequest(request);
7984
+ const requestHeader = parsedGraphQLQuery
7985
+ ? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})`
7986
+ : `${request.method} ${publicUrl}`;
7987
+ const handlerSuggestion = generateHandlerSuggestion();
7988
+ const messageTemplate = [
7989
+ `captured a request without a matching request handler:`,
7990
+ ` \u2022 ${requestHeader}`,
7991
+ handlerSuggestion,
7992
+ `\
7814
7993
  If you still wish to intercept this unhandled request, please create a request handler for it.
7815
7994
  Read more: https://mswjs.io/docs/getting-started/mocks\
7816
7995
  `,
7817
- ].filter(Boolean);
7818
- const message = messageTemplate.join('\n\n');
7819
- switch (strategy) {
7820
- case 'error': {
7821
- // Print a developer-friendly error.
7822
- devUtils.error('Error: %s', message);
7823
- // Throw an exception to halt request processing and not perform the original request.
7824
- throw new Error(devUtils.formatMessage('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'));
7825
- }
7826
- case 'warn': {
7827
- devUtils.warn('Warning: %s', message);
7828
- break;
7996
+ ].filter(Boolean);
7997
+ return messageTemplate.join('\n\n');
7998
+ }
7999
+ function applyStrategy(strategy) {
8000
+ // Generate handler suggestions only when applying the strategy.
8001
+ // This saves bandwidth for scenarios when developers opt-out
8002
+ // from the default unhandled request handling strategy.
8003
+ const message = generateUnhandledRequestMessage();
8004
+ switch (strategy) {
8005
+ case 'error': {
8006
+ // Print a developer-friendly error.
8007
+ devUtils.error('Error: %s', message);
8008
+ // Throw an exception to halt request processing and not perform the original request.
8009
+ throw new Error(devUtils.formatMessage('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'));
8010
+ }
8011
+ case 'warn': {
8012
+ devUtils.warn('Warning: %s', message);
8013
+ break;
8014
+ }
8015
+ case 'bypass':
8016
+ break;
8017
+ default:
8018
+ throw new Error(devUtils.formatMessage('Failed to react to an unhandled request: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.', strategy));
7829
8019
  }
7830
- case 'bypass':
7831
- break;
7832
- default:
7833
- throw new Error(devUtils.formatMessage('Failed to react to an unhandled request: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.', strategy));
7834
8020
  }
8021
+ if (typeof strategy === 'function') {
8022
+ strategy(request, {
8023
+ warning: applyStrategy.bind(null, 'warn'),
8024
+ error: applyStrategy.bind(null, 'error'),
8025
+ });
8026
+ return;
8027
+ }
8028
+ applyStrategy(strategy);
7835
8029
  }
7836
8030
 
7837
8031
  function readResponseCookies(request, response) {
@@ -7844,7 +8038,7 @@ function handleRequest(request, handlers, options, emitter, handleRequestOptions
7844
8038
  return __awaiter(this, void 0, void 0, function* () {
7845
8039
  emitter.emit('request:start', request);
7846
8040
  // Perform bypassed requests (i.e. issued via "ctx.fetch") as-is.
7847
- if (request.headers.get('x-msw-bypass')) {
8041
+ if (request.headers.get('x-msw-bypass') === 'true') {
7848
8042
  emitter.emit('request:end', request);
7849
8043
  (_a = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onBypassResponse) === null || _a === void 0 ? void 0 : _a.call(handleRequestOptions, request);
7850
8044
  return;